===== IEntityRepository ===== This service maintains the collection of currently registered [[IEntity|Entities]] and provides efficient lookup access based on their Components and static data IDs. Entities are indexed by the [[IComponent|Component]] types they contain when they are registered. This allows systems to efficiently retrieve or iterate through Entities containing a specific Component without scanning the complete Entity collection. === Methods === ^Method | [[IEntity]][] **GetAllEntities**() | ^Description | Returns all currently registered [[IEntity|Entities]]. | ^Method | int **GetEntityCount**() where T : [[IComponent]] | ^Description | Returns the number of currently registered [[IEntity|Entities]] containing a Component of type T. Returns zero if no Entities with that Component type are registered. | ^Method | bool **TryGetEntityAt**(int index, out [[IEntity]]? entity) where T : [[IComponent]] | ^Description | Attempts to retrieve the [[IEntity]] at specified index from the collection of Entities containing a Component of type T. Returns true and outputs the Entity if the index is valid. Returns false and outputs null if the index is negative, no Entities with that Component type are registered, or the index is outside the collection bounds. | ^Method | [[IEntity]][] **GetEntitiesWithComponent**() where T : [[IComponent]] | ^Description | Returns all currently registered [[IEntity|Entities]] containing a Component of type T. Returns an empty array if no matching Entities are registered. | ^Method | [[IEntity]][] **GetEntitiesWithComponent**(Type componentType) | ^Description | Returns all currently registered [[IEntity|Entities]] containing a Component of specified Type. Returns an empty array if no matching Entities are registered. | ^Method | [[IEntity]][] **GetEntitiesWithStaticDataID**(string staticDataID) | ^Description | Returns all currently registered [[IEntity|Entities]] whose static data ID matches specified staticDataID. Returns an empty array if no matching Entities are registered. | ^Method | void **RegisterEntity**([[IEntity]] entity) | ^Description | Registers specified [[IEntity]] with the repository. The Entity is added to the global Entity collection and indexed by its static data ID and every [[IComponent|Component]] type it contains. | ^Method | void **UnregisterEntity**([[IEntity]] entity) | ^Description | Unregisters specified [[IEntity]] from the repository. The Entity is removed from the global Entity collection and from the indexes associated with its static data ID and Component types. |