Skip to content

Game.Prefabs.TutorialObjectSelectionTriggerPrefab

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: TutorialTriggerPrefabBase

Summary:
Prefab class used by the tutorial system to define object-selection triggers. It holds an array of ObjectSelectionTriggerInfo entries, each mapping a prefab (the object that can be selected) to an optional tutorial phase to transition to when that object is selected. The prefab provides dependency collection, declares the runtime component required (ObjectSelectionTriggerData), initializes entity buffers with trigger data during LateInitialize, and generates tutorial link references. When multiple triggers provide explicit go-to phases, the target phases are marked for branching (TutorialPhaseBranch).


Fields

  • public ObjectSelectionTriggerInfo[] m_Triggers
    Array of trigger definitions. Each entry specifies the PrefabBase that acts as the selectable trigger and an optional TutorialPhasePrefab to transition to when the trigger is activated. This array is typically configured in the prefab inspector.

  • public class ObjectSelectionTriggerInfo (nested, [Serializable])
    Container type for individual trigger entries. Fields:

  • public PrefabBase m_Trigger ([NotNull])
    The prefab that serves as the selectable trigger.

  • public TutorialPhasePrefab m_GoToPhase ([CanBeNull])
    Optional tutorial phase to enter when the corresponding prefab is selected. If null, selection does not direct to another phase.

Properties

  • public override bool phaseBranching { get; }
    Returns true if any entry in m_Triggers has a non-null m_GoToPhase. This indicates the prefab can cause phase branching in the tutorial (multiple possible next phases).

Constructors

  • public TutorialObjectSelectionTriggerPrefab()
    Default constructor (no explicit initialization in source). Instances are typically configured via the Unity inspector.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds referenced prefabs to the provided dependency list. Implementation:
  • Calls base.GetDependencies(prefabs).
  • Adds each m_Trigger prefab.
  • If an entry's m_GoToPhase is non-null, adds that phase prefab as well. This ensures referenced prefabs/phases are included when resolving dependencies for the tutorial prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers component types required by this prefab at runtime. Implementation:

  • Calls base.GetPrefabComponents(components).
  • Adds ComponentType.ReadWrite() to indicate instances need a buffer/component for trigger data.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Converts the prefab configuration into ECS runtime data. Implementation:

  • Calls base.LateInitialize(entityManager, entity).
  • Obtains a DynamicBuffer on the created entity.
  • Resolves referenced prefabs/phases to Entities via PrefabSystem (existingSystemManaged.GetEntity).
  • Adds an ObjectSelectionTriggerData entry per configured trigger with m_Prefab (entity) and m_GoToPhase (entity or Entity.Null).
  • If more than one trigger is defined, iterates triggers and for any with a non-null go-to phase, adds the TutorialPhaseBranch component to the target phase entity to mark it as branched.

  • public override void GenerateTutorialLinks(EntityManager entityManager, NativeParallelHashSet<Entity> linkedPrefabs)
    Registers prefab entity links used by the tutorial graph. Implementation:

  • Calls base.GenerateTutorialLinks(entityManager, linkedPrefabs).
  • Resolves each m_Trigger to its Entity via PrefabSystem and adds it to linkedPrefabs. This helps the tutorial system know which prefabs are linked/related to this trigger prefab.

Usage Example

// Example: configuring triggers in code (normally done in the prefab inspector)
public class ExampleSetup : MonoBehaviour
{
    public TutorialObjectSelectionTriggerPrefab triggerPrefab; // assigned in inspector
    public PrefabBase housePrefab;
    public TutorialPhasePrefab nextPhase;

    void Reset()
    {
        triggerPrefab.m_Triggers = new TutorialObjectSelectionTriggerPrefab.ObjectSelectionTriggerInfo[]
        {
            new TutorialObjectSelectionTriggerPrefab.ObjectSelectionTriggerInfo
            {
                m_Trigger = housePrefab,
                m_GoToPhase = nextPhase
            }
        };
    }
}

Notes: - The prefab requires the runtime component/buffer ObjectSelectionTriggerData to be present on the created entity; GetPrefabComponents ensures this is declared. - If multiple triggers specify different go-to phases, those target phases will get a TutorialPhaseBranch component added during LateInitialize, enabling branching behavior in the tutorial flow. - Prefab references (both triggers and phases) are added to dependency and link collections so the tutorial system can correctly load and connect them.