// TODO: Add ability to add and remove tags that are active // this should cause the set of processors to change public void RegisterComponent(RobotArmsComponent component) { components.Add(component); var entity = component.gameObject; foreach (var p in processors.Where(p => p.RequiredTypes.Contains(component.GetType()) && p.IsInterestedIn(entity))) { EntityAndComponents current = entitiesForProcessors[p].FirstOrDefault(e => e.Entity == entity); if (current == null) { current = new EntityAndComponents { Entity = entity }; entitiesForProcessors[p].Add(current); } var componentTypes = p.GetType().BaseType.GetGenericArguments(); current.Components = new Component[componentTypes.Length]; for (var i = 0; i < componentTypes.Length; ++i) { current.Components[i] = entity.GetComponent(componentTypes[i]); } if (!entitiesForProcessorsToInitialize[p].Any(e => e.Entity == entity)) { entitiesForProcessorsToInitialize[p].Add(current); } } }
public void UnregisterComponent(RobotArmsComponent component) { components.Remove(component); entitiesWithComponentsThatWereRemoved.Enqueue(component.gameObject); }
public static void DestroyComponent(RobotArmsComponent component) { Coordinator.RunAtEndOfFrame(() => GameObject.Destroy(component)); }