/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Initialized" /> to /// <see cref="ComponentLifeStage.Running" />, calling <see cref="Startup" />. /// </summary> internal void LifeStartup() { DebugTools.Assert(LifeStage == ComponentLifeStage.Initialized); LifeStage = ComponentLifeStage.Starting; Startup(); DebugTools.Assert(LifeStage == ComponentLifeStage.Running, $"Component {this.GetType().Name} did not call base {nameof(Startup)} in derived method."); }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Added" /> to <see cref="ComponentLifeStage.Initialized" />, /// calling <see cref="Initialize" />. /// </summary> internal void LifeInitialize() { DebugTools.Assert(LifeStage == ComponentLifeStage.Added); LifeStage = ComponentLifeStage.Initializing; Initialize(); DebugTools.Assert(LifeStage == ComponentLifeStage.Initialized, $"Component {this.GetType().Name} did not call base {nameof(Initialize)} in derived method."); }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.PreAdd" /> to <see cref="ComponentLifeStage.Added" />, /// calling <see cref="OnAdd" />. /// </summary> internal void LifeAddToEntity() { DebugTools.Assert(LifeStage == ComponentLifeStage.PreAdd); LifeStage = ComponentLifeStage.Adding; OnAdd(); DebugTools.Assert(LifeStage == ComponentLifeStage.Added, $"Component {this.GetType().Name} did not call base {nameof(OnAdd)} in derived method."); }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Running" /> to <see cref="ComponentLifeStage.Stopped" />, /// calling <see cref="Shutdown" />. /// </summary> /// <remarks> /// Components are allowed to remove themselves in their own Startup function. /// </remarks> internal void LifeShutdown() { // Starting allows a component to remove itself in it's own Startup function. DebugTools.Assert(LifeStage == ComponentLifeStage.Starting || LifeStage == ComponentLifeStage.Running); LifeStage = ComponentLifeStage.Stopping; Shutdown(); DebugTools.Assert(LifeStage == ComponentLifeStage.Stopped, $"Component {this.GetType().Name} did not call base {nameof(Shutdown)} in derived method."); }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Stopped" /> to <see cref="ComponentLifeStage.Deleted" />, /// calling <see cref="OnRemove" />. /// </summary> internal void LifeRemoveFromEntity() { // can be called at any time after PreAdd, including inside other life stage events. DebugTools.Assert(LifeStage != ComponentLifeStage.PreAdd); LifeStage = ComponentLifeStage.Removing; OnRemove(); DebugTools.Assert(LifeStage == ComponentLifeStage.Deleted, $"Component {this.GetType().Name} did not call base {nameof(OnRemove)} in derived method."); }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Initialized" /> to /// <see cref="ComponentLifeStage.Running" />, calling <see cref="Startup" />. /// </summary> internal void LifeStartup(IEntityManager entManager) { DebugTools.Assert(LifeStage == ComponentLifeStage.Initialized); LifeStage = ComponentLifeStage.Starting; entManager.EventBus.RaiseComponentEvent(this, CompStartupInstance); Startup(); #if DEBUG if (LifeStage != ComponentLifeStage.Running) { DebugTools.Assert($"Component {this.GetType().Name} did not call base {nameof(Startup)} in derived method."); } #endif }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.PreAdd" /> to <see cref="ComponentLifeStage.Added" />, /// calling <see cref="OnAdd" />. /// </summary> internal void LifeAddToEntity(IEntityManager entManager) { DebugTools.Assert(LifeStage == ComponentLifeStage.PreAdd); LifeStage = ComponentLifeStage.Adding; CreationTick = entManager.CurrentTick; entManager.EventBus.RaiseComponentEvent(this, CompAddInstance); OnAdd(); #if DEBUG if (LifeStage != ComponentLifeStage.Added) { DebugTools.Assert($"Component {this.GetType().Name} did not call base {nameof(OnAdd)} in derived method."); } #endif }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Running" /> to <see cref="ComponentLifeStage.Stopped" />, /// calling <see cref="Shutdown" />. /// </summary> /// <remarks> /// Components are allowed to remove themselves in their own Startup function. /// </remarks> internal void LifeShutdown(IEntityManager entManager) { // Starting allows a component to remove itself in it's own Startup function. DebugTools.Assert(LifeStage == ComponentLifeStage.Starting || LifeStage == ComponentLifeStage.Running); LifeStage = ComponentLifeStage.Stopping; entManager.EventBus.RaiseComponentEvent(this, CompShutdownInstance); Shutdown(); #if DEBUG if (LifeStage != ComponentLifeStage.Stopped) { DebugTools.Assert($"Component {this.GetType().Name} did not call base {nameof(Shutdown)} in derived method."); } #endif }
/// <summary> /// Increases the life stage from <see cref="ComponentLifeStage.Stopped" /> to <see cref="ComponentLifeStage.Deleted" />, /// calling <see cref="OnRemove" />. /// </summary> internal void LifeRemoveFromEntity(IEntityManager entManager) { // can be called at any time after PreAdd, including inside other life stage events. DebugTools.Assert(LifeStage != ComponentLifeStage.PreAdd); LifeStage = ComponentLifeStage.Removing; entManager.EventBus.RaiseComponentEvent(this, CompRemoveInstance); OnRemove(); #if DEBUG if (LifeStage != ComponentLifeStage.Deleted) { DebugTools.Assert($"Component {this.GetType().Name} did not call base {nameof(OnRemove)} in derived method."); } #endif }