Skip to content

Game.Prefabs.TutorialPrefab

Assembly:
Assembly-CSharp (Assembly-CSharp.dll)

Namespace:
Game.Prefabs

Type:
class

Base:
PrefabBase

Summary:
Represents a Tutorial prefab that groups one or more TutorialPhasePrefab instances into a tutorial sequence. Adds the required ECS components and links tutorial phases and other prefabs (via TutorialLinkData) during initialization. Supports options to replace the active tutorial, mark a tutorial as mandatory or editor-only, and fire telemetry events.


Fields

  • public TutorialPhasePrefab[] m_Phases
    Array of phase prefabs that make up this tutorial. Marked [NotNull]. Each entry will be converted to a TutorialPhaseRef in the entity and will have tutorial links generated.

  • public int m_Priority
    Integer priority used when creating the TutorialData component on the tutorial entity. Higher values may affect ordering/selection.

  • public bool m_ReplaceActive
    If true, the prefab adds ReplaceActiveData to the tutorial entity via GetPrefabComponents, indicating it should replace the currently active tutorial when started.

  • public bool m_Mandatory
    Flag indicating the tutorial is mandatory. (Stored on the prefab but not directly manipulated in the shown code — may be used elsewhere by the tutorial system.)

  • public bool m_EditorTutorial
    If true, LateInitialize adds an EditorTutorial tag/component to the created entity so the tutorial is recognized as an editor-only tutorial.

  • public bool m_FireTelemetry
    If true, the prefab adds a ReadOnly component to the entity so the tutorial system will fire telemetry events.

Properties

  • public override bool ignoreUnlockDependencies { get; }
    Always returns true. This override tells the prefab system to ignore unlock/tech dependencies for this prefab (tutorials are not gated by standard unlock dependencies).

Constructors

  • public TutorialPrefab()
    Default constructor. (Prefab instances are typically created/instantiated by the game's prefab system or asset pipeline rather than constructed manually in gameplay code.)

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds all TutorialPhasePrefab instances referenced in m_Phases to the provided prefabs list. Ensures the phase prefabs are treated as dependencies of this tutorial prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required ECS component types for the tutorial entity:

  • ReadWrite
  • ReadWrite
  • Conditionally ReadWrite if m_ReplaceActive is true
  • Conditionally ReadOnly if m_FireTelemetry is true

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab initialization. Sets TutorialData on the entity using m_Priority (entityManager.SetComponentData(entity, new TutorialData(m_Priority));).

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs late initialization that requires access to other systems and entities:

  • Gets the PrefabSystem from the default world.
  • Builds a DynamicBuffer on the tutorial entity and fills it with the Entity references of each phase (via PrefabSystem.GetEntity).
  • Calls GenerateTutorialLinks on each TutorialPhasePrefab to collect any linked prefabs into a NativeParallelHashSet.
  • For each linked entity found, ensures it has a DynamicBuffer and appends a TutorialLinkData entry pointing back to this tutorial entity.
  • If m_EditorTutorial is true, adds the EditorTutorial component/tag to the tutorial entity.
  • Disposes the native hash set (uses Allocator.TempJob).

Notes: LateInitialize uses a NativeParallelHashSet with Allocator.TempJob to collect linked prefabs and explicitly disposes it at the end.

Usage Example

// Example: read the TutorialData for a TutorialPrefab instance after prefabs are created
var prefabSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<PrefabSystem>();
Entity tutorialEntity = prefabSystem.GetEntity(myTutorialPrefab); // myTutorialPrefab is a TutorialPrefab asset
var tutorialData = entityManager.GetComponentData<TutorialData>(tutorialEntity);
UnityEngine.Debug.Log($"Tutorial priority: {tutorialData.m_Priority}");

// When creating a TutorialPrefab asset, assign phases and set flags in the inspector or asset code:
// myTutorialPrefab.m_Phases = new[] { phase1Prefab, phase2Prefab };
// myTutorialPrefab.m_ReplaceActive = true;
// myTutorialPrefab.m_FireTelemetry = true;