Game.Tutorials.TutorialUITriggerSystem
Assembly: Assembly-CSharp
Namespace: Game.Tutorials
Type: class
Base: TutorialTriggerSystemBase, ITutorialUITriggerSystem
Summary:
System that drives UI-related tutorial triggers. It monitors active tutorial UI trigger entities (UITriggerData + TriggerActive and not TriggerCompleted), checks their configured UI tags against a runtime set of activated trigger strings, and marks triggers as completed, pre-completed, or transitions to another tutorial phase. The system depends on the PrefabSystem to read TutorialUITriggerPrefab data and creates unlock events via an EntityArchetype. Uses a command buffer from the barrier system to modify entities safely during update.
Fields
-
private PrefabSystem m_PrefabSystem
Used to access tutorial-related prefabs (TutorialUITriggerPrefab) and to translate prefab references to entities. Initialized in OnCreate via World.GetOrCreateSystemManaged(). -
private EntityArchetype m_UnlockEventArchetype
Archetype created in OnCreate with componentsEvent
andUnlock
. Used when calling TutorialSystem.ManualUnlock to emit unlock events for completed triggers. -
private readonly HashSet<string> m_ActivatedTriggers = new HashSet<string>()
Runtime set of string trigger IDs that have been activated by external code. The system checks UI trigger prefab tags against this set to decide whether to complete a UI trigger. Thread-affine to the main thread; mutated via ActivateTrigger / DisactivateTrigger.
Properties
- (none)
This system does not expose public properties. Its API is provided via the ActivateTrigger / DisactivateTrigger methods.
Constructors
public TutorialUITriggerSystem()
Default constructor. Marked with [Preserve] (via attribute on the class methods) — the system relies on the ECS lifecycle methods (OnCreate/OnUpdate) to perform initialization.
Methods
-
public void ActivateTrigger(string trigger)
Add a trigger ID to the internal activated set. Call this from game code to notify the tutorial system that a specific UI-related event/tag has occurred (e.g., "build_button_clicked"). -
public void DisactivateTrigger(string trigger)
Remove a trigger ID from the internal activated set. Useful to avoid re-processing the same activation or to reset state. -
[Preserve] protected override void OnCreate()
Initializes subsystem references and ECS query/archetype: - Retrieves PrefabSystem via World.GetOrCreateSystemManaged
(). - Sets up the m_ActiveTriggerQuery to select entities with
UITriggerData
andTriggerActive
and excludeTriggerCompleted
. -
Creates the
m_UnlockEventArchetype
forEvent
+Unlock
components. Called once when the system is created. -
[Preserve] protected override void OnUpdate()
Main runtime logic: - If there are no activated triggers or no active trigger entities, returns early.
- Iterates all matching entities (m_ActiveTriggerQuery) and reads the TutorialUITriggerPrefab data for each.
- For each UITriggerInfo in the prefab, splits
m_UITagProvider.uiTag
by '|' to support multiple tag alternatives. - If any tag is found in
m_ActivatedTriggers
:- If
m_GoToPhase
is set, adds aTutorialNextPhase
component (pointing to the phase entity) and marks the trigger asTriggerPreCompleted
. - Else if
m_CompleteManually
is true, marksTriggerPreCompleted
. - Else marks
TriggerCompleted
. - Calls
TutorialSystem.ManualUnlock
to emit unlock event(s) using the archetype and command buffer. - Removes the processed tag from
m_ActivatedTriggers
and stops processing further UITriggerInfo for that entity.
- If
- Disposes the temporary NativeArray of entities at the end. This method uses the barrier system's command buffer to safely add components to entities during the frame.
Usage Example
// Activating a UI trigger from game logic (e.g., when a specific UI element is used)
var tutorialSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<TutorialUITriggerSystem>();
tutorialSystem?.ActivateTrigger("build_button_clicked");
// The system's OnUpdate will detect the activated tag, consult the prefab's UITriggerInfo
// (splitting uiTag by '|'), and will add TriggerCompleted / TriggerPreCompleted or
// TutorialNextPhase as configured, then emit unlock events via TutorialSystem.ManualUnlock.