public void DestroyEntity(SimulationEntity entity) { if (!initialized) { throw new InvalidOperationException("Can't remove entities from simulations that haven't been initialized"); } if (entity.Destroyed) { throw new InvalidOperationException("Can't remove a destroyed entity"); } if (simulationListener != null) { simulationListener.EntityRemoved(entity); } for (int i = 0; i < entity.components.Count; i++) { for (int j = 0; j < componentManagers.Count; j++) { componentManagers[j].ComponentRemoved(entity.components[i]); } } entity.Destroy(); entities.Remove(entity); }
public SimulationEntity AddEntity(EntityTemplate template) { if (!initialized) { throw new InvalidOperationException("Can't add entities to simulations that haven't been initialized"); } SimulationEntity entity = new SimulationEntity(); entities.Add(entity); entity.Init(this, nextEntityId++, template); for (int i = 0; i < entity.components.Count; i++) { for (int j = 0; j < componentManagers.Count; j++) { componentManagers[j].ComponentAdded(entity.components[i]); } } if (simulationListener != null) { simulationListener.EntityAdded(entity); } return(entity); }
internal void Destroy() { OnDestroy(); this.entity = null; }
public void InitDependencies(SimulationEntity entity) { this.entity = entity; OnInitDependencies(); }