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; } }
public EntitySystem(params Type[] types) { for (int i = 0; i < types.Length; ++i) { int comTypeId = ComponentTypeManager.GetTypeId(types[i]); componentBits[comTypeId] = true; } }
public bool HasComponent(int entityId, Type type) { int comTypeId = ComponentTypeManager.GetTypeId(type); BitSet bits = componentBitsOfEntity[entityId]; bool has = bits[comTypeId]; return(has); }
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); } } }
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()); } }
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); }