Skip to content

Game.Tutorials.TutorialUpgradeTriggerSystem

Assembly: Assembly-CSharp
Namespace: Game.Tutorials

Type: class

Base: TutorialTriggerSystemBase

Summary:
Handles tutorial triggers that depend on service upgrades. This ECS system watches for existing service upgrades and newly created upgrades, and marks active tutorial triggers as pre-completed or completed as appropriate. When triggers change or relevant upgrade events occur, it uses an EntityCommandBuffer (via the barrier system) and TutorialSystem.ManualUnlock to produce Unlock events and advance/complete the associated tutorial triggers.


Fields

  • private EntityQuery m_CreatedUpgradeQuery
    Query matching entities that represent newly created service upgrades. Matches Created + Game.Buildings.ServiceUpgrade while excluding Temp, Deleted and Native markers. Used to detect when an upgrade has just been created so active triggers can be marked completed.

  • private EntityQuery m_UpgradeQuery
    Query matching any existing service upgrade entities (Game.Buildings.ServiceUpgrade) excluding Temp/Deleted/Native. Used to detect presence of upgrades so active triggers can be pre-completed.

  • private EntityArchetype m_UnlockEventArchetype
    Archetype created for producing unlock events. It contains Event and Unlock components and is used when calling TutorialSystem.ManualUnlock to spawn the event entities via the command buffer.

Properties

  • (none declared on this type)
    This system relies on and manipulates queries/fields defined here and uses inherited members from TutorialTriggerSystemBase (for example m_ActiveTriggerQuery and m_BarrierSystem) to find active triggers and create command buffers.

Constructors

  • public TutorialUpgradeTriggerSystem()
    Default constructor. Marked with [Preserve] attribute in source. Initialization logic is performed in OnCreate rather than the constructor.

Methods

  • protected override OnCreate() : System.Void
    Initializes the system: calls base.OnCreate(), sets up three EntityQueries (m_CreatedUpgradeQuery, m_UpgradeQuery, and m_ActiveTriggerQuery from the base), creates the m_UnlockEventArchetype (Event + Unlock), and calls RequireForUpdate on the active-trigger query so the system only runs when there are active triggers to process.

  • protected override OnUpdate() : System.Void
    Main update logic:

  • Calls base.OnUpdate().
  • If triggers have changed (base.triggersChanged) and there are any upgrades (m_UpgradeQuery not empty), it gets the active triggers as an entity array and for each active trigger it:
    • Adds TriggerPreCompleted via an EntityCommandBuffer.
    • Calls TutorialSystem.ManualUnlock to produce the unlock event using m_UnlockEventArchetype.
  • If any newly created upgrades are present (m_CreatedUpgradeQuery not empty), it gets the active triggers and for each active trigger:
    • Adds TriggerCompleted via the command buffer.
    • Calls TutorialSystem.ManualUnlock to produce the unlock event.
  • Uses Allocator.TempJob for temporary NativeArray allocations and disposes them after use.
  • Uses barrier system (m_BarrierSystem.CreateCommandBuffer()) to enqueue component additions and event creation safely for playback.

Usage Example

// Example: create a simple active upgrade-trigger entity so the system can act on it.
// When a service upgrade exists or is created, TutorialUpgradeTriggerSystem will
// mark the trigger pre-completed or completed and invoke TutorialSystem.ManualUnlock.

var em = World.DefaultGameObjectInjectionWorld.EntityManager;

// create an active tutorial trigger that listens for upgrades
Entity trigger = em.CreateEntity(typeof(UpgradeTriggerData), typeof(TriggerActive));

// Later, when a ServiceUpgrade is present or created in the world,
// TutorialUpgradeTriggerSystem will add TriggerPreCompleted or TriggerCompleted
// and call TutorialSystem.ManualUnlock to spawn unlock events.