Пример #1
0
        public void RemoveComponent(int entityId, Type type)
        {
            Entity ent = FindEntity(entityId);

            if (ent == null)
            {
                return;
            }

            int comTypeId = ComponentTypeManager.GetTypeId(type);

            ComponentArray entComArray = componentsArrayOfEntity[entityId];
            Component      com         = entComArray[comTypeId];

            if (com != null)
            {
                entComArray[comTypeId] = null;

                /*ComponentArray typeComArray = typeConponnetsArray[comTypeId];
                 * typeComArray.Remove(com);*/

                systemManager.OnRemoveComponent(ent, com);

                BitSet bits = componentBitsOfEntity[entityId];
                bits[comTypeId] = false;
            }
        }
Пример #2
0
 public EntitySystem(params Type[] types)
 {
     for (int i = 0; i < types.Length; ++i)
     {
         int comTypeId = ComponentTypeManager.GetTypeId(types[i]);
         componentBits[comTypeId] = true;
     }
 }
Пример #3
0
        public bool HasComponent(int entityId, Type type)
        {
            int    comTypeId = ComponentTypeManager.GetTypeId(type);
            BitSet bits      = componentBitsOfEntity[entityId];
            bool   has       = bits[comTypeId];

            return(has);
        }
Пример #4
0
        public void OnRemoveComponent(Entity entity, Component component)
        {
            BitSet bits = entityManager.GetEntityComponentBitSet(entity.Id);

            if (bits.Contains(componentBits))
            {
                int comTypeId = ComponentTypeManager.GetTypeId(component.GetType());
                if (componentBits[comTypeId])
                {
                    entityArray.Remove(entity);
                }
            }
        }
Пример #5
0
        public void AddComponent(int entityId, Component component)
        {
            Entity ent = FindEntity(entityId);

            if (ent == null)
            {
                return;
            }

            int comTypeId = ComponentTypeManager.GetTypeId(component.GetType());

            ComponentArray entComArray = null;

            if (entityId < componentsArrayOfEntity.Count)
            {
                entComArray = componentsArrayOfEntity[entityId];
            }
            else
            {
                entComArray = new ComponentArray();
                componentsArrayOfEntity[entityId] = entComArray;
            }

            Component com = entComArray[comTypeId];

            if (com == null)
            {
                com = component;
                entComArray[comTypeId] = com;

                /*ComponentArray typeComArray = null;
                 * if (comTypeId < typeConponnetsArray.Count)
                 *      typeComArray = typeConponnetsArray[comTypeId];
                 * else
                 * {
                 *      typeComArray = new ComponentArray();
                 *      typeConponnetsArray[comTypeId] = typeComArray;
                 * }
                 * typeComArray.Add(com);*/

                BitSet bits = componentBitsOfEntity[entityId];
                bits[comTypeId] = true;

                systemManager.OnAddComponent(ent, com);
            }
            else
            {
                //throw new Exception("EntityManager.AddComponent: repeated component " + component.GetType());
            }
        }
Пример #6
0
        public Component GetComponent(int entityId, Type type)
        {
            Entity ent = FindEntity(entityId);

            if (ent == null)
            {
                return(null);
            }

            int comTypeId = ComponentTypeManager.GetTypeId(type);

            ComponentArray entComArray = componentsArrayOfEntity[entityId];
            Component      com         = entComArray[comTypeId];

            return(com);
        }