BGMetaEntity API

BGMetaEntity.cs -is a database table, containing 1-n fields and 0-n rows. The API list is not full.

Main API

Method/Property Returns Description
this[int entityIndex] BGEntity Get table row by it's index
//get first row
var entity = meta[0];
this[BGId entityId] BGEntity Get table row by it's id
//get row by it's id
var entity = meta[new BGId("HThOdRCxlEGU1aefSG+Nbw")];
this[string entityName] BGEntity Get the first table row, whose name is equal to entityName
//get the first row by it's name
var entity = meta["BigSword"];
ForEachEntity(Action<BGEntity> action, Predicate<BGEntity> filter=null, Comparison<BGEntity> sort=null) void Search and iterate entities by filter. For each found entity action will be called. Sort delegate allows to sort entities
//print entities names, whose name starts with "My"
meta.ForEachEntity(entity => Debug.Log(entity.Name), entity => entity.Name.StartsWith("My"));
FindEntity(Predicate<BGEntity> filter) BGEntity Find the first entity by filter
//find first entity, which name starts with "My"
BGEntity result = meta.FindEntity(entity => entity.Name.StartsWith("My"));
FindEntities(Predicate<BGEntity> filter, List<BGEntity> result=null, Comparison<BGEntity> sort=null) List<BGEntity> Search entities by filter. Pass in 'result' list to get rid of Garbage Collection. 'sort' allows to sort entities
//find all entities, whose name starts with "My"
List<BGEntity> result = meta.FindEntities(entity => entity.Name.StartsWith("My"));
CountEntities int The number of rows
//print the number of rows
NewEntity BGEntity Create new row
//create new entity
var newEntity = meta.NewEntity();

Additional API

Method/Property Returns Description
Id BGId table id
//get table id
var id = meta.Id;
Name string table name
//get table name
var name = meta.Name;
DeleteEntities void Delete several rows
//delete all entities, which names start with 'My'
meta.DeleteEntities(meta.FindEntities(entity => entity.Name.StartsWith("My")));
ForEachField(Action<BGField> action) void Execute action for each field
//print all field names
meta.ForEachField(field => Debug.Log(field.Name));
ForEachField(Action<BGField> action, Predicate<BGField> filter = null) void Execute action for each field, complying to the filter
//print all field names, whose value type is int
meta.ForEachField(field => Debug.Log(field.Name), field => field.ValueType==typeof(int));