Game.Tutorials.TutorialInputTriggerSystem
Assembly: Assembly-CSharp
Namespace: Game.Tutorials
Type: public class
Base: TutorialTriggerSystemBase
Summary:
Handles tutorial triggers that are completed by player input. The system queries active input-based tutorial triggers, checks whether any of the configured input actions were performed this frame, and when performed it marks the trigger as completed and emits an Unlock event entity using an archetype. It uses the game's PrefabSystem to read the TutorialInputTriggerPrefab attached to trigger entities and the InputManager to test actions.
Fields
-
private EntityArchetype m_UnlockEventArchetype
Archetype used to create unlock event entities (components: Event, Unlock). Initialized in OnCreate and used when a trigger completes to spawn an unlock event via the command buffer. -
private PrefabSystem m_PrefabSystem
Cached reference to the PrefabSystem obtained from the World. Used to fetch the TutorialInputTriggerPrefab for each trigger entity so the system knows which input actions to check.
Properties
- None
Constructors
public TutorialInputTriggerSystem()
Default parameterless constructor. The system relies on the ECS lifecycle methods (OnCreate / OnUpdate) for initialization and work; no custom construction logic beyond the default is required.
Methods
-
protected override void OnCreate()
Initializes the system. Calls base.OnCreate(), sets up an entity query (active input triggers: InputTriggerData + TriggerActive, excluding TriggerCompleted), creates the unlock event archetype, caches the PrefabSystem, and calls RequireForUpdate with the active trigger query so the system only runs when triggers are present. -
protected override void OnUpdate()
Main update loop. Converts the active trigger query to temporary arrays of InputTriggerData and Entity (Allocator.TempJob), creates an EntityCommandBuffer from the barrier system, iterates over active triggers and for each: - Fetches the TutorialInputTriggerPrefab via PrefabSystem.
- Calls Performed(prefab) to check if any configured input action was performed this frame.
-
If performed: adds TriggerCompleted to the entity using the command buffer and calls TutorialSystem.ManualUnlock to emit the unlock event (using the m_UnlockEventArchetype, EntityManager and command buffer). Finally disposes the temporary arrays. Note: uses Allocator.TempJob for temporary arrays — they must be disposed within the same frame (which the method does).
-
private bool Performed(TutorialInputTriggerPrefab prefab)
Checks whether any of the input actions configured on the TutorialInputTriggerPrefab were performed this frame. For each action entry in prefab.m_Actions, it calls InputManager.instance.TryFindAction(map, action, out var action) and if found checks action.WasPerformedThisFrame(). Returns true on the first match; returns false if no configured action was performed.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Example of what this system does: set up queries and dependencies.
m_ActiveTriggerQuery = GetEntityQuery(
ComponentType.ReadOnly<InputTriggerData>(),
ComponentType.ReadOnly<TriggerActive>(),
ComponentType.Exclude<TriggerCompleted>());
m_UnlockEventArchetype = EntityManager.CreateArchetype(
ComponentType.ReadWrite<Event>(),
ComponentType.ReadWrite<Unlock>());
m_PrefabSystem = World.GetOrCreateSystemManaged<PrefabSystem>();
RequireForUpdate(m_ActiveTriggerQuery);
}
Notes and tips: - The system allocates NativeArray with Allocator.TempJob and disposes them synchronously in OnUpdate; ensure no early returns that skip disposal. - Performed(...) relies on the global InputManager.instance and action.WasPerformedThisFrame(), so behavior depends on the input/action configuration and the input subsystem state. - The system uses EntityCommandBuffer from the barrier system to mutate entities safely during the system's update. - When modding, ensure the TutorialInputTriggerPrefab's m_Actions entries match the actual input maps/actions used by the game so triggers fire as expected.