Skip to content

Game.Tutorials.TutorialInfoviewActivationSystem

Assembly:
Assembly-CSharp (game code)

Namespace:
Game.Tutorials

Type:
class

Base:
GameSystemBase

Summary:
Monitors tutorial entities that have InfoviewActivationData and, when the player's active infoview (from the ToolSystem) matches the infoview referenced by a tutorial, marks that tutorial as activated by adding a TutorialActivated component. The system schedules a Burst-compiled IJobChunk (CheckActivationJob) that iterates matching chunks and issues parallel EntityCommandBuffer operations to add the activation tag.


Fields

  • protected EntityCommandBufferSystem m_BarrierSystem
    Used to obtain an EntityCommandBuffer (as a ParallelWriter) to safely add components from the chunk job. Set to a modification barrier (ModificationBarrier4) obtained from the world.

  • private PrefabSystem m_PrefabSystem
    Reference to the game's PrefabSystem. Used to map a prefab object reference (m_ToolSystem.infoview) to its Entity via GetEntity.

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem used to read the currently active infoview and the infoview prefab reference.

  • private EntityQuery m_TutorialQuery
    Query selecting tutorial entities that have TutorialData and InfoviewActivationData but which do not yet have TutorialActivated or TutorialCompleted. This is the set of entities the job will scan.

  • private TypeHandle __TypeHandle
    Holds component- and entity-type handles for use in jobs. Populated via __AssignHandles in OnCreateForCompiler.

  • (nested) private struct CheckActivationJob
    Burst-compiled IJobChunk that reads InfoviewActivationData and Entity from chunks, compares the stored infoview Entity to the active infoview, and uses an EntityCommandBuffer.ParallelWriter to add the TutorialActivated component.

  • (nested) private struct TypeHandle
    Container for ComponentTypeHandle and EntityTypeHandle with an __AssignHandles method to initialize them from a SystemState.

Properties

  • (no public properties)
    The system does not expose public CLR properties. It uses internal type handles and references to other systems.

Constructors

  • public TutorialInfoviewActivationSystem()
    Default constructor. Marked with [Preserve] to avoid stripping; no custom initialization beyond base construction. Real initialization occurs in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes system references and the entity query:
  • Retrieves ModificationBarrier4 as m_BarrierSystem.
  • Retrieves ToolSystem and PrefabSystem.
  • Creates m_TutorialQuery: reads TutorialData and InfoviewActivationData, excludes TutorialActivated and TutorialCompleted.

  • protected override void OnUpdate()
    Main runtime logic:

  • If m_TutorialQuery is not empty and ToolSystem.activeInfoview is not null:

    • Constructs CheckActivationJob with component/ entity type handles (via InternalCompilerInterface.Get... using cached __TypeHandle), sets m_Infoview to the prefab entity obtained from m_PrefabSystem.GetEntity(m_ToolSystem.infoview), and supplies a parallel command buffer writer from m_BarrierSystem.
    • Schedules the job in parallel over the query and updates base.Dependency.
    • Registers the job handle with m_BarrierSystem so the barrier system knows to play back the command buffer after the job completes.
  • protected override void OnCreateForCompiler()
    Compiler helper used to assign queries and assign type handles for the Burst job. Calls __AssignQueries and TypeHandle.__AssignHandles with the system's checked state.

  • private void __AssignQueries(ref SystemState state)
    Helper used at compiler-time; in this implementation it simply constructs and disposes an EntityQueryBuilder (placeholder). Real Query initialization happens in OnCreate.

  • (nested) CheckActivationJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    IJobChunk execution method. For each entity in the chunk:

  • Reads InfoviewActivationData and Entity arrays.
  • If an entity's InfoviewActivationData.m_Infoview equals the currently active infoview Entity (m_Infoview), issues m_Writer.AddComponent(unfilteredChunkIndex, entity) to mark the tutorial as activated.
  • The job is Burst-compiled and uses parallel command buffer writing for thread-safety and performance.

  • (nested) TypeHandle.__AssignHandles(ref SystemState state)
    Initializes the ComponentTypeHandle and EntityTypeHandle using the provided SystemState. Marked AggressiveInlining for performance.

Notes: - The system relies on InternalCompilerInterface to obtain type handles for burst jobs and uses JobChunkExtensions.ScheduleParallel to execute the chunk job. - The job is Burst-compiled ([BurstCompile]) for performance. - The code excludes already activated/completed tutorials by query shape, preventing duplicate additions.

Usage Example

This system runs automatically as part of the ECS world. Example showing how a tutorial entity would be created so this system can activate it when the matching infoview is opened:

// Create a tutorial entity that should activate when a specific infoview prefab is opened:
var tutorialArchetype = entityManager.CreateArchetype(
    typeof(TutorialData),
    typeof(InfoviewActivationData)
);

// Create the entity and set the infoview prefab reference (assumes prefabSystem and infoview prefab object are available)
Entity tutorialEntity = entityManager.CreateEntity(tutorialArchetype);

InfoviewActivationData activation = new InfoviewActivationData {
    // Suppose prefabSystem.GetEntity(infoviewPrefab) returns the entity representing the infoview prefab.
    m_Infoview = prefabSystem.GetEntity(infoviewPrefab)
};
entityManager.SetComponentData(tutorialEntity, activation);

// At runtime, when the player opens the infoview represented by infoviewPrefab,
// TutorialInfoviewActivationSystem's job will detect the match and add the TutorialActivated component:
// entityManager.HasComponent<TutorialActivated>(tutorialEntity) -> true (after system job and barrier playback)

Additional remarks: - Because the job uses an EntityCommandBuffer.ParallelWriter, the actual addition of the TutorialActivated tag happens asynchronously; the barrier system ensures safe playback. - The system is optimized to only run its job when there are candidate tutorials (m_TutorialQuery not empty) and when there is an active infoview in the ToolSystem.