예제 #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
파일: EntitySystem.cs 프로젝트: end1220/ECS
 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
파일: EntitySystem.cs 프로젝트: end1220/ECS
        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);
        }