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 EntitySystem(params Type[] types) { for (int i = 0, j = types.Length; i < j; i++) { Type type = types[i]; ComponentType ct = ComponentTypeManager.GetTypeFor(type); typeFlags |= ct.GetBit(); } }
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()); }