Example #1
0
        public void OnEntityRemovingFromGroup(IEntity entity)
        {
            if (!CachedEntities.Contains(entity.Id))
            {
                return;
            }

            _onEntityRemoving.OnNext(entity);
            CachedEntities.Remove(entity.Id);
            _onEntityRemoved.OnNext(entity);
        }
Example #2
0
        public IEntity CreateEntity(IBlueprint blueprint = null, int?id = null)
        {
            if (id.HasValue && EntityLookup.Contains(id.Value))
            {
                throw new InvalidOperationException("id already exists");
            }

            var entity = EntityFactory.Create(id);

            EntityLookup.Add(entity);
            _onEntityAdded.OnNext(new CollectionEntityEvent(entity));
            SubscribeToEntity(entity);

            blueprint?.Apply(entity);

            return(entity);
        }
Example #3
0
        public void OnEntityComponentRemoved(ComponentsChangedEvent args)
        {
            if (CachedEntities.Contains(args.Entity.Id))
            {
                if (args.Entity.HasAllComponents(Token.LookupGroup.RequiredComponents))
                {
                    return;
                }

                CachedEntities.Remove(args.Entity.Id);
                _onEntityRemoved.OnNext(args.Entity);
                return;
            }

            if (!Token.LookupGroup.Matches(args.Entity))
            {
                return;
            }

            CachedEntities.Add(args.Entity);
            _onEntityAdded.OnNext(args.Entity);
        }
 public bool ContainsEntity(int id)
 {
     return(EntityLookup.Contains(id));
 }