示例#1
0
        public IEntity CreateEntity(BaseSystem system)
        {
            Entity entity = new Entity();

            Entities.Add(entity);
            InitEntity(entity, system);
            return(entity);
        }
示例#2
0
        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));
     }
 }
示例#4
0
        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);
        }
示例#5
0
 public int EntityCount(BaseSystem system)
 {
     return(systems.GetEntityCount(system));
 }
示例#6
0
 public void InitEntity(IEntity entity, BaseSystem system)
 {
     Components.InitEntity(entity as Entity, system);
 }
示例#7
0
 public IWorld AddSystem(BaseSystem system)
 {
     system.Finder = this.EntityFinder;
     Systems.Add(system, Entities.EntityFinder.Find(system.KeyComponents));
     return(this);
 }
示例#8
0
        /**** ***/

        public bool BelongsTo(BaseSystem sys)
        {
            return(this.ContainsAll(sys.KeyComponents));
        }
 public SystemWrapper(BaseSystem system)
 {
     System   = system;
     entities = new HashSet <Entity>();
 }