Game.Tutorials.TutorialInfoviewDeactivationSystem
Assembly: Game
Namespace: Game.Tutorials
Type: class
Base: TutorialDeactivationSystemBase
Summary:
TutorialInfoviewDeactivationSystem is an ECS system used by the game's tutorial framework to ensure tutorial entities are deactivated when their associated infoview is no longer the currently active infoview. It keeps two queries (pending and active tutorials), and schedules a Burst-compiled IJobChunk (CheckDeactivationJob) that iterates matching entities and removes the TutorialActivated component for any tutorial whose InfoviewActivationData.m_Infoview does not match the currently active infoview. The system uses ToolSystem to discover the active infoview prefab and PrefabSystem to map that prefab to an Entity. It schedules the job in parallel and writes component removals through an EntityCommandBuffer obtained from the barrier system.
Fields
-
private PrefabSystem m_PrefabSystem
This stores a reference to the game's PrefabSystem (managed system). Used by GetActiveInfoview() to convert a ToolSystem active infoview prefab to an Entity. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem (managed system). The system reads m_ToolSystem.activeInfoview to determine which infoview is currently active. -
private EntityQuery m_PendingTutorialQuery
EntityQuery that matches tutorials that are pending activation (contains TutorialData, InfoviewActivationData, TutorialActivated and excludes TutorialActive, TutorialCompleted and ForceActivation). Used to check deactivation for pending tutorials. -
private EntityQuery m_ActiveTutorialQuery
EntityQuery that matches currently active tutorials (contains TutorialData, InfoviewActivationData, TutorialActivated, TutorialActive and excludes TutorialCompleted and ForceActivation). This query is only processed when base.phaseCanDeactivate is true. -
private TypeHandle __TypeHandle
Internal helper struct holding ComponentTypeHandle/EntityTypeHandle instances; populated in OnCreateForCompiler via __AssignHandles so the job can read InfoviewActivationData and Entity values efficiently. -
(Nested)
CheckDeactivationJob
(private, Burst-compiled)
IJobChunk implementation used to iterate chunks of matching entities. Reads InfoviewActivationData and Entity values, compares each entity's m_Infoview to the active infoview, and uses an EntityCommandBuffer.ParallelWriter to RemoveComponentfor mismatches.
Properties
- This type exposes no public properties.
Constructors
public TutorialInfoviewDeactivationSystem()
Default constructor. The system relies on ECS lifecycle methods (OnCreate/OnUpdate). The constructor itself performs no custom initialization beyond default.
Methods
protected override void OnCreate()
Initializes system references and queries:- Calls base.OnCreate().
- Acquires managed systems: ToolSystem and PrefabSystem from the World.
-
Builds two EntityQuery instances: m_PendingTutorialQuery and m_ActiveTutorialQuery with the required include/exclude components used by the system.
-
protected override void OnUpdate()
Main update loop: - If m_PendingTutorialQuery is not empty, calls CheckDeactivation(m_PendingTutorialQuery).
- If m_ActiveTutorialQuery is not empty and base.phaseCanDeactivate is true, calls CheckDeactivation(m_ActiveTutorialQuery).
-
Uses the system's Job/Dependency handling to schedule the check job and to notify the barrier system of the job handle.
-
private void CheckDeactivation(EntityQuery query)
Prepares and schedules the CheckDeactivationJob for the provided query: - Fills jobData fields:
- ComponentTypeHandle
and EntityTypeHandle via InternalCompilerInterface.GetComponentTypeHandle/GetEntityTypeHandle using the precomputed __TypeHandle entries and the CheckedStateRef. - m_Infoview set to the result of GetActiveInfoview().
- m_Buffer created via m_BarrierSystem.CreateCommandBuffer().AsParallelWriter().
- ComponentTypeHandle
-
Schedules the job with ScheduleParallel and attaches the resulting dependency to the barrier system using m_BarrierSystem.AddJobHandleForProducer.
-
private Entity GetActiveInfoview()
Returns the entity representing the currently active infoview: - If m_ToolSystem.activeInfoview is null, returns Entity.Null.
-
Otherwise, calls m_PrefabSystem.GetEntity(m_ToolSystem.activeInfoview) to map the prefab to an Entity.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper used at system creation for code-generation convenience. In this decompiled form it no-ops except for creating and disposing an EntityQueryBuilder in a temporary allocator. -
protected override void OnCreateForCompiler()
Called by generated boilerplate to prepare type handles and queries for the job system: - Calls __AssignQueries(ref base.CheckedStateRef).
-
Calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to populate ComponentTypeHandle/EntityTypeHandle used by jobs.
-
(Nested) CheckDeactivationJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : void
Job body details: - Gets NativeArray
and NativeArray for the chunk. - Iterates each element; if nativeArray[i].m_Infoview != m_Infoview (the currently active infoview), enqueues a RemoveComponent
on that entity using m_Buffer.RemoveComponent with the chunk's unfilteredChunkIndex.
Usage Example
// The system itself already wires the required systems and queries during OnCreate.
// Example showing the main flow that happens in OnCreate and OnUpdate:
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire managed system references (this is what the real system does)
m_ToolSystem = World.GetOrCreateSystemManaged<ToolSystem>();
m_PrefabSystem = World.GetOrCreateSystemManaged<PrefabSystem>();
// Setup queries analogous to the real implementation
m_PendingTutorialQuery = GetEntityQuery(
ComponentType.ReadOnly<TutorialData>(),
ComponentType.ReadOnly<InfoviewActivationData>(),
ComponentType.ReadOnly<TutorialActivated>(),
ComponentType.Exclude<TutorialActive>(),
ComponentType.Exclude<TutorialCompleted>(),
ComponentType.Exclude<ForceActivation>());
m_ActiveTutorialQuery = GetEntityQuery(
ComponentType.ReadOnly<TutorialData>(),
ComponentType.ReadOnly<InfoviewActivationData>(),
ComponentType.ReadOnly<TutorialActivated>(),
ComponentType.ReadOnly<TutorialActive>(),
ComponentType.Exclude<TutorialCompleted>(),
ComponentType.Exclude<ForceActivation>());
}
// Example of what the CheckDeactivationJob does (pseudo-logic):
// For each matching entity:
// if (entity.InfoviewActivationData.m_Infoview != currentActiveInfoview)
// commandBuffer.RemoveComponent<TutorialActivated>(entity);
Notes and implementation details: - The core per-entity work is run inside a Burst-compiled IJobChunk (CheckDeactivationJob) and scheduled in parallel for performance. - The system uses an end-frame barrier (m_BarrierSystem) to obtain an EntityCommandBuffer.ParallelWriter so structural changes (component removals) are deferred and safe to perform from a job. - ComponentTypeHandle and EntityTypeHandle are obtained via InternalCompilerInterface with reference to base.CheckedStateRef — this is a pattern used in generated/compiled ECS systems to ensure safe access across job schedules. - The system intentionally excludes tutorials marked with ForceActivation or TutorialCompleted from deactivation checks.