/// <summary> /// Internal method to add an entity to the entity manager and register it with all /// associated systems. This executes the add immediately. /// </summary> /// <param name="toAdd">The entity to add.</param> private void InternalAddEntity(RuntimeEntity toAdd) { toAdd.GameEngine = this; // notify listeners that we both added and created the entity Log <GameEngine> .Info("Submitting internal EntityAddedEvent for " + toAdd); EventNotifier.Submit(EntityAddedEvent.Create(toAdd)); EventNotifier.Submit(ShowEntityEvent.Create(toAdd)); // add it to the entity index _entityIndex.AddEntity(toAdd); // register listeners toAdd.ModificationNotifier.Listener += OnEntityModified; toAdd.DataStateChangeNotifier.Listener += OnEntityDataStateChanged; // notify ourselves of data state changes so that it the entity is pushed to systems toAdd.DataStateChangeNotifier.Notify(); // ensure it contains metadata for our keys toAdd.Metadata.UnorderedListMetadata[_entityUnorderedListMetadataKey] = new UnorderedListMetadata(); // add it our list of entities _entities.Add(toAdd, GetEntitiesListFromMetadata(toAdd)); }