コード例 #1
0
ファイル: Group.cs プロジェクト: tatelax/LazyECS
        public void ComponentRemovedFromEntity(Entity.Entity entity, Type component)
        {
            if (GroupType == GroupType.All && Filters.Contains(component))
            {
                Entities.Remove(entity);

                if (EventType == EventType.Removed || EventType == EventType.All)
                {
                    OnEntityUpdateEvent?.Invoke(EventType.Removed, entity, component);
                }

                return;
            }

            if (entity.Components.Any(cmp => Filters.Contains(cmp.Key)))
            {
                return;
            }

            Entities.Remove(entity);

            if (EventType == EventType.Removed || EventType == EventType.All)
            {
                OnEntityUpdateEvent?.Invoke(EventType.Removed, entity, component);
            }
        }
コード例 #2
0
ファイル: Group.cs プロジェクト: tatelax/LazyECS
        public void ComponentAddedToEntity(Entity.Entity entity, Type component)
        {
            if (Entities.Contains(entity))
            {
                return;
            }

            if (GroupType == GroupType.Any && Filters.Contains(component))
            {
                Entities.Add(entity);

                if (EventType == EventType.Added || EventType == EventType.All)
                {
                    OnEntityUpdateEvent?.Invoke(EventType.Added, entity, component);
                }

                return;
            }

            int matches = entity.Components.Sum(cmp => Filters.Count(filter => cmp.Key == filter));

            if (matches != Filters.Count)
            {
                return;
            }

            Entities.Add(entity);

            if (EventType == EventType.Added || EventType == EventType.All)
            {
                OnEntityUpdateEvent?.Invoke(EventType.Added, entity, component);
            }
        }
コード例 #3
0
ファイル: Group.cs プロジェクト: tatelax/LazyECS
 public void EntityDestroyed(Entity.Entity entity)
 {
     if (Entities.Contains(entity))
     {
         Entities.Remove(entity);
     }
 }
コード例 #4
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual void OnEntityCreated(Entity.Entity entity, bool entityCreatedFromNetworkMessage)
        {
            if (SimulationController.Instance.LogLevel == LogLevel.Verbose)
            {
                Debug.Log("<color=#00ff00>[LazyECS] Creating entity with id " + entity.id + " in world " + GetType().Name + "</color>");
            }

            OnEntityCreatedEvent?.Invoke(entity, entityCreatedFromNetworkMessage);
        }
コード例 #5
0
ファイル: Group.cs プロジェクト: tatelax/LazyECS
 public void EntitySet(Entity.Entity entity, Type component)
 {
     if (Entities.Contains(entity) && Filters.Contains(component))
     {
         if (EventType == EventType.Set || EventType == EventType.All)
         {
             OnEntityUpdateEvent?.Invoke(EventType.Set, entity, component);
         }
     }
 }
コード例 #6
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual Entity.Entity CreateEntity(int id = -1, bool entityCreatedFromNetworkMessage = false)
        {
            Entity.Entity newEntity = id != -1 ? new Entity.Entity(id) : new Entity.Entity(Entities.Count);

            newEntity.OnComponentAdded   += OnComponentAddedToEntity;
            newEntity.OnComponentRemoved += OnComponentRemovedFromEntity;
            newEntity.OnComponentSet     += OnComponentSetOnEntity;
            Entities.Add(newEntity.id, newEntity);
            OnEntityCreated(newEntity, entityCreatedFromNetworkMessage);

            return(newEntity);
        }
コード例 #7
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual bool DestroyEntity(Entity.Entity entity, bool entityDestroyedFromNetworkMessage = false)
        {
            if (Entities.ContainsKey(entity.id))
            {
                Entities.Remove(entity.id);
                OnEntityDestroyed(entity, entityDestroyedFromNetworkMessage);
                return(true);
            }

            Debug.LogWarning("Attempted to destroy entity but it doesn't exist!");
            return(false);
        }
コード例 #8
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual void OnComponentSetOnEntity(Entity.Entity entity, IComponent component, bool setFromNetworkMessage = false)
        {
            if (SimulationController.Instance.LogLevel == LogLevel.Verbose)
            {
                Debug.Log("<color=#00ff00>[LazyECS] " + $"{component.GetType()} was <b>SET</b> on entity {entity.id} in world {GetType().Name} </color>");
            }

            for (int i = 0; i < Groups.Count; i++)
            {
                Groups[i].EntitySet(entity, component.GetType());
            }

            OnComponentSetOnEntityEvent?.Invoke(entity, component, setFromNetworkMessage);
        }
コード例 #9
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual void OnComponentRemovedFromEntity(Entity.Entity entity, IComponent component)
        {
            if (SimulationController.Instance.LogLevel == LogLevel.Verbose)
            {
                Debug.Log("<color=#00ff00>[LazyECS] " + $"{component.GetType()} was <b>REMOVED</b> from entity {entity.id} in world {GetType().Name} </color>");
            }

            for (int i = 0; i < Groups.Count; i++)
            {
                Groups[i].ComponentRemovedFromEntity(entity, component.GetType());
            }

            OnComponentRemovedFromEntityEvent?.Invoke(entity, component);
        }
コード例 #10
0
ファイル: World.cs プロジェクト: tatelax/LazyECS
        public virtual void OnEntityDestroyed(Entity.Entity entity, bool entityDestroyedFromNetworkMessage = false)
        {
            if (SimulationController.Instance.LogLevel == LogLevel.Verbose)
            {
                Debug.Log("<color=#00ff00>[LazyECS] " + $"{entity.id} was <b>DESTROYED</b> in world {GetType().Name} </color>");
            }

            for (int i = 0; i < Groups.Count; i++)
            {
                Groups[i].EntityDestroyed(entity);
            }

            OnEntityDestroyedEvent?.Invoke(entity, entityDestroyedFromNetworkMessage);
        }