/// <summary> /// Finds all entities in a registry that have a component of the specified type attached to them. /// </summary> public static IEnumerable <IEntityRecord> FindAllWithComponent <TComponent>(IEntityRecordCollection registry) where TComponent : class, IComponent { return(registry != null? registry.Where(entity => entity.HasComponent <TComponent>()) : null); }
/// <summary> /// Creates a new entity with the specified name and registers it to the registry. /// </summary> public EntityRecord(string name, IEntityRecordCollection registry) : this() { Name = name; Registry = registry; _mediator = new Mediator(); _children = new List <IEntityRecord>(); }
/// <summary> /// Creates and registers an entity in the specified registry. /// </summary> public static IEntityRecord Create(string name, IEntityRecordCollection registry) { IEntityRecord record = new EntityRecord(name, registry); /// Ensure that the entity gets registered. record.Synchronize(); return(record); }
/// <summary> /// Creates and registers a new entity in the specified registry. The specified components will also be attached to it. /// </summary> public static IEntityRecord Create(string name, IEntityRecordCollection registry, params IComponent[] components) { IEntityRecord record = Create(name, registry); foreach (IComponent component in components) { record.Add(component); } return(record); }
/// <summary> /// Attempts to find the entity that matches the specified name in a registry. Returns `null` if none was found. /// </summary> public static IEntityRecord Find(string name, IEntityRecordCollection registry) { IEntityRecord record = new EntityRecord(name, registry); if (!registry.Contains(record)) { record = null; } return(record); }
/// <summary> /// Broadcasts a message to every single component that is currently attached to an entity in the specified registry. /// </summary> public static void Broadcast <TData>(IEntityRecordCollection registry, string message, TData data) { if (registry == null) { return; } foreach (IEntityRecord record in registry) { record.Notify(message, data); } }
public static IEntityRecord CreateChild(this IEntityRecord parent, string name, IEntityRecordCollection registry, params IComponent[] components) { IEntityRecord record = Entity.Create(name, registry, components); record.Parent = record; return(record); }
public static IEntityRecord CreateChild(this IEntityRecord parent, string name, IEntityRecordCollection registry) { IEntityRecord record = Entity.Create(name, registry); record.Parent = record; return(record); }
/// <summary> /// Creates a new entity with the specified name and registers it to the registry. /// </summary> public EntityRecord(string name, IEntityRecordCollection registry) : this() { Name = name; Registry = registry; }