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); } }
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); } }
public void EntityDestroyed(Entity.Entity entity) { if (Entities.Contains(entity)) { Entities.Remove(entity); } }
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); }
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); } } }
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); }
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); }
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); }
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); }
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); }