Game.Tutorials.TutorialObjectSelectionDeactivationSystem
Assembly: Game (assembly containing game systems; typically Assembly-CSharp in the game build)
Namespace: Game.Tutorials
Type: class
Base: TutorialDeactivationSystemBase
Summary:
System that deactivates object-selection-based tutorials when the player's current selection or active tool no longer matches the tutorial's required selection. It queries for pending and active tutorial entities that are triggered by object selection, compares the current selected prefab/tool to each tutorial's activation buffer, and removes the TutorialActivated component (via an EntityCommandBuffer) for tutorials that should be deactivated. Uses a parallel IJobChunk (CheckTutorialsJob) for efficient processing and coordinates with a barrier system for safe structural changes.
Fields
-
private PrefabSystem m_PrefabSystem
Reference to the game's PrefabSystem used to resolve prefab references to entities. -
private ObjectToolSystem m_ObjectToolSystem
Reference to the object placement tool system used to determine currently selected object prefabs when using the object tool. -
private NetToolSystem m_NetToolSystem
Reference to the network (road) tool system used to determine currently selected net prefabs. -
private ToolSystem m_ToolSystem
Reference to the general ToolSystem used to inspect selected entities or current active tool. -
private EntityQuery m_PendingTutorialQuery
EntityQuery that matches tutorial entities that are pending activation/monitoring (contains TutorialActivated but not TutorialActive, not completed, not forced). -
private EntityQuery m_ActiveTutorialQuery
EntityQuery for already-active tutorials (contains TutorialActive and TutorialActivated, not completed or forced). -
private TypeHandle __TypeHandle
Local container for the BufferTypeHandle and EntityTypeHandle used by jobs; populated in OnCreateForCompiler to cache the required handles. -
private struct TypeHandle
(nested)
Holds buffer/entity type handles used by the job; has an __AssignHandles method that fetches/assigns handles from the SystemState. -
private struct CheckTutorialsJob
(nested)
IJobChunk implementation that performs the per-chunk check of tutorials and issues RemoveComponentvia a parallel EntityCommandBuffer when a tutorial should be deactivated.
Properties
- This type exposes no public properties.
Constructors
public TutorialObjectSelectionDeactivationSystem()
Default constructor. Marked with [Preserve] attribute in source. No special runtime initialization beyond the base constructor; system initialization happens in OnCreate.
Methods
-
protected override void OnCreate()
Creates entity queries for pending and active tutorials and obtains references to required systems (PrefabSystem, ToolSystem, NetToolSystem, ObjectToolSystem). This prepares the system for use in OnUpdate. -
protected override void OnUpdate()
Main system update. If either pending or active tutorial queries are non-empty, it retrieves the current selection (prefab entity and whether it is a tool selection) via GetSelection. It then calls CheckDeactivate on the pending query, and also on the active query if the base phase allows deactivation (base.phaseCanDeactivate). Scheduling for deactivation is done via a parallel IJobChunk. -
private Entity GetSelection(out bool tool)
Inspects the current ToolSystem selection and active tool stacks to determine the currently selected prefab entity and whether the selection comes from a tool. Returns Entity.Null if no meaningful selection exists. Sets tool = true when the selection originates from a tool prefab; otherwise false. -
private void CheckDeactivate(EntityQuery query, Entity selection, bool tool)
Prepares and schedules the CheckTutorialsJob for the provided query. It fills the job's cached type handles (using InternalCompilerInterface.GetBufferTypeHandle/GetEntityTypeHandle with the stored __TypeHandle), sets the selection and tool flags, and attaches a parallel EntityCommandBuffer from the barrier system. Schedules the job with ScheduleParallel and registers its handle with the barrier to ensure safe structural changes. -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and assigns type handles via __TypeHandle.__AssignHandles(ref base.CheckedStateRef). Used by generated/compiled code paths. -
private void __AssignQueries(ref SystemState state)
Small helper used by OnCreateForCompiler; in this implementation it creates and disposes a temporary EntityQueryBuilder (no-op here, but present to satisfy generated code path patterns). -
(Nested job)
CheckTutorialsJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Iterates entities in the chunk, reads the DynamicBufferper entity and the entity array, then for each entity determines whether the tutorial should be deactivated (using ShouldDeactivate). If so, enqueues a RemoveComponent on that entity via the provided parallel EntityCommandBuffer. -
(Nested job)
CheckTutorialsJob.ShouldDeactivate(DynamicBuffer<ObjectSelectionActivationData> selections)
Returns true if none of the ObjectSelectionActivationData entries in the buffer match the currently selected prefab (m_Selection) while also respecting the m_AllowTool flag relative to the current m_Tool flag. If any buffer entry matches the selection and tool rules, the tutorial should remain activated (returns false).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Create queries for tutorials that are pending activation/monitoring and for active tutorials.
m_PendingTutorialQuery = GetEntityQuery(
ComponentType.ReadOnly<TutorialData>(),
ComponentType.ReadOnly<ObjectSelectionActivationData>(),
ComponentType.ReadOnly<TutorialActivated>(),
ComponentType.Exclude<TutorialActive>(),
ComponentType.Exclude<TutorialCompleted>(),
ComponentType.Exclude<ForceActivation>());
m_ActiveTutorialQuery = GetEntityQuery(
ComponentType.ReadOnly<TutorialData>(),
ComponentType.ReadOnly<ObjectSelectionActivationData>(),
ComponentType.ReadOnly<TutorialActivated>(),
ComponentType.ReadOnly<TutorialActive>(),
ComponentType.Exclude<TutorialCompleted>(),
ComponentType.Exclude<ForceActivation>());
// Cache references to systems used to determine player selection
m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
m_NetToolSystem = base.World.GetOrCreateSystemManaged<NetToolSystem>();
m_ObjectToolSystem = base.World.GetOrCreateSystemManaged<ObjectToolSystem>();
}
Notes and implementation details: - This system relies on ObjectSelectionActivationData buffers attached to tutorial entities; those buffers contain prefab references and a flag indicating whether tool selections are permitted. - Deactivation is performed by removing the TutorialActivated component from tutorial entities. The barrier system's EntityCommandBuffer is used to perform these structural changes safely across jobs. - The job compares entities' activation buffers to the current selection (an Entity representing the prefab) and honors the allowTool flag to avoid deactivating tutorials when a tool-based selection should keep them active.