public void AddComponent <T>(Entity e, Component component) where T : Component { ComponentType type = ComponentTypeManager.GetTypeFor <T>(); if (type.GetId() >= componentsByType.GetCapacity()) { componentsByType.Set(type.GetId(), null); } Bag <Component> components = componentsByType.Get(type.GetId()); if (components == null) { components = new Bag <Component>(); componentsByType.Set(type.GetId(), components); } components.Set(e.GetId(), component); e.AddTypeBit(type.GetBit()); if (AddedComponentEvent != null) { AddedComponentEvent(e, component); } }
public Component GetComponent(Entity e, ComponentType type) { int entityId = e.GetId(); Bag <Component> bag = componentsByType.Get(type.GetId()); if (bag != null && entityId < bag.GetCapacity()) { return(bag.Get(entityId)); } return(null); }
public void RemoveComponent(Entity e, ComponentType type) { int entityId = e.GetId(); Bag <Component> components = componentsByType.Get(type.GetId()); if (RemovedComponentEvent != null) { RemovedComponentEvent(e, components.Get(entityId)); } components.Set(entityId, null); e.RemoveTypeBit(type.GetBit()); }