Game.Tutorials.TutorialTriggerSystemBase
Assembly: Game
Namespace: Game.Tutorials
Type: abstract class
Base: Game.Common.GameSystemBase
Summary:
Base ECS system for handling tutorial trigger evaluation. This abstract system wires up common tutorial services (ModificationBarrier5 and TutorialSystem), tracks the currently active tutorial phase entity, and exposes a triggersChanged flag that derived systems can use to react when the active tutorial phase changes. It also provides an EntityQuery slot for derived systems to populate for searching triggers relevant to the current phase.
Fields
-
protected ModificationBarrier5 m_BarrierSystem
Reference to the game's modification barrier system (ModificationBarrier5). Use this to schedule structural/entity modifications from jobs or systems that must synchronize with entity changes. -
protected Unity.Entities.EntityQuery m_ActiveTriggerQuery
EntityQuery intended to be initialized by derived classes to locate active tutorial trigger entities/components. -
private TutorialSystem m_TutorialSystem
Cached reference to the TutorialSystem (used to read the currently active tutorial phase). -
private Unity.Entities.Entity m_LastPhase
Stores the last known active tutorial phase entity. Used to detect changes between frames.
Properties
protected bool triggersChanged { get; private set; }
Set to true during OnUpdate() when the active tutorial phase entity changes since the last update. Derived systems should check this property to know when to (re)evaluate triggers or refresh queries.
Constructors
protected TutorialTriggerSystemBase()
Default protected constructor. Meant to be called by derived classes.
Methods
protected virtual void OnCreate()
Initializes required systems. The base implementation acquires:- ModificationBarrier5 via World.GetOrCreateSystemManaged
() -
TutorialSystem via World.GetOrCreateSystemManaged
() Derived classes should call base.OnCreate() and then configure m_ActiveTriggerQuery as needed. -
protected override void OnGameLoaded(Context serializationContext)
Called when a game save is loaded. The base implementation resets m_LastPhase to Entity.Null so the next update will detect the active phase and set triggersChanged accordingly. -
protected override void OnUpdate()
Main update loop: reads the active tutorial phase from m_TutorialSystem.activeTutorialPhase and compares it to m_LastPhase. If changed, updates m_LastPhase and sets triggersChanged = true; otherwise sets triggersChanged = false. Derived systems should use this flag to refresh trigger state only when necessary. -
protected override void OnStopRunning()
Called when the system stops running (e.g., during shutdown or domain reload). The base implementation clears m_LastPhase to Entity.Null.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Base implementation caches these systems:
// m_BarrierSystem = World.GetOrCreateSystemManaged<ModificationBarrier5>();
// m_TutorialSystem = World.GetOrCreateSystemManaged<TutorialSystem>();
// Example: create a query for trigger components your derived system cares about
m_ActiveTriggerQuery = GetEntityQuery(
ComponentType.ReadOnly(typeof(MyTutorialTriggerComponent)),
ComponentType.ReadOnly(typeof(SomeOtherComponent))
);
}
[Preserve]
protected override void OnUpdate()
{
base.OnUpdate(); // sets triggersChanged based on active tutorial phase
if (triggersChanged)
{
// Re-evaluate triggers for the new phase
// e.g., iterate over m_ActiveTriggerQuery or schedule jobs that use m_BarrierSystem
}
// Normal update logic...
}