public IEntity CreateEntity(BaseSystem system) { Entity entity = new Entity(); Entities.Add(entity); InitEntity(entity, system); return(entity); }
public int GetEntityCount(BaseSystem system) { SystemWrapper wrapper; wrappers.TryGetValue(system.GetType(), out wrapper); if (wrapper != null) { return(wrapper.EntityCount); } return(0); }
public void InitEntity(Entity entity, BaseSystem system) { if (entity == null || system == null) { return; } if (entity.ComponentCount == 0) { system.KeyComponents.ForEach(type => AddComponent(entity, Activator.CreateInstance(type) as IComponent)); } else { system.KeyComponents.Where(c => !entity.Contains(c)).ForEach(type => AddComponent(entity, Activator.CreateInstance(type) as IComponent)); } }
public bool Add(BaseSystem system, IEnumerable <IEntity> existingEntities) { if (wrappers.ContainsKey(system.GetType())) { return(false); } SystemWrapper wrapper = new SystemWrapper(system); wrappers.Add(system.GetType(), wrapper); foreach (Entity enitity in existingEntities) { wrapper.AddEntity(enitity); } return(true); }
public int EntityCount(BaseSystem system) { return(systems.GetEntityCount(system)); }
public void InitEntity(IEntity entity, BaseSystem system) { Components.InitEntity(entity as Entity, system); }
public IWorld AddSystem(BaseSystem system) { system.Finder = this.EntityFinder; Systems.Add(system, Entities.EntityFinder.Find(system.KeyComponents)); return(this); }
/**** ***/ public bool BelongsTo(BaseSystem sys) { return(this.ContainsAll(sys.KeyComponents)); }
public SystemWrapper(BaseSystem system) { System = system; entities = new HashSet <Entity>(); }