Entitas.Context.GetGroup C# (CSharp) Method

GetGroup() public method

public GetGroup ( IMatcher matcher ) : Group
matcher IMatcher
return Group
        public virtual Group GetGroup(IMatcher matcher)
        {
            Group group;
            if(!_groups.TryGetValue(matcher, out group)) {
                group = new Group(matcher);
                var entities = GetEntities();
                for (int i = 0; i < entities.Length; i++) {
                    group.HandleEntitySilently(entities[i]);
                }
                _groups.Add(matcher, group);

                for (int i = 0; i < matcher.indices.Length; i++) {
                    var index = matcher.indices[i];
                    if(_groupsForIndex[index] == null) {
                        _groupsForIndex[index] = new List<Group>();
                    }
                    _groupsForIndex[index].Add(group);
                }

                if(OnGroupCreated != null) {
                    OnGroupCreated(this, group);
                }
            }

            return group;
        }

Usage Example

Exemplo n.º 1
0
        static void groupExample(Context context) {
            context.GetGroup(Matcher.Position).GetEntities();

            // ----------------------------

            context.GetGroup(Matcher.Position).OnEntityAdded += (group, entity, index, component) => {
                // Do something
            };
        }
All Usage Examples Of Entitas.Context::GetGroup