Skip to content

Game.Tutorials.TutorialUIActivationSystem

Assembly: Game
Namespace: Game.Tutorials

Type: class

Base: GameSystemBase, ITutorialUIActivationSystem

Summary:
Manages activation of tutorial UI prefabs based on string tags. The system builds a mapping from UI tags (provided by Tutorial prefabs) to Entity instances, tracks active tags, and activates associated tutorial UI entities by adding TutorialActivated and, when required, ForceActivation components. The mapping is rebuilt when the system is created or when a game is loaded.


Fields

  • protected Unity.Entities.EntityCommandBufferSystem m_BarrierSystem
    Holds a reference to a command buffer system (ModificationBarrier4) used to queue structural changes (such as adding components) safely from the system's update.

  • private readonly System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<Unity.Entities.Entity>> m_TutorialMap
    Dictionary mapping UI tag strings to lists of tutorial Entities that expose that tag. Built from Tutorial prefabs' TutorialUIActivation component's uiTag values (split on '|').

  • private readonly System.Collections.Generic.List<string> m_ActiveTags
    List of currently active tags. Used during OnUpdate to determine which tutorial entities should be activated.

  • private Unity.Entities.EntityQuery m_TutorialQuery
    EntityQuery used to find all entities that have UIActivationData and PrefabData components (i.e., tutorial prefab instances).

Properties

  • None (no public properties are declared on this type).

Constructors

  • public TutorialUIActivationSystem()
    Default parameterless constructor. The class relies on OnCreate to initialize runtime state (barrier system, query, and builds the tutorial map).

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system: obtains the ModificationBarrier4 command buffer system, creates the EntityQuery for tutorial UI prefabs (UIActivationData + PrefabData), and calls RebuildTutorialMap() to populate m_TutorialMap.

  • protected override void OnGameLoaded(Context serializationContext) : System.Void
    Called when a game is loaded. Rebuilds the tutorial map and clears any active tags to ensure state is consistent with the loaded save.

  • private void RebuildTutorialMap() : System.Void
    Scans entities matching the tutorial query, retrieves their TutorialPrefab via PrefabSystem, reads the TutorialUIActivation component's m_UITagProvider.uiTag string, splits it by '|' to get multiple tags, trims them, and populates m_TutorialMap mapping tags to entity lists. Skips entries without tags. Uses a temporary NativeArray for the query result and disposes it.

  • public void SetTag(string tag, bool active) : System.Void
    Marks a tag as active or inactive. Only affects m_ActiveTags if the tag exists in the m_TutorialMap (i.e., known from prefabs). If active is true the tag is added to m_ActiveTags; if false it is removed.

  • protected override void OnUpdate() : System.Void
    If m_ActiveTags is empty, does nothing. Otherwise creates an EntityCommandBuffer from m_BarrierSystem and iterates all active tags: for each mapped entity that is not already marked with TutorialCompleted, it adds a TutorialActivated component immediately (via EntityManager) and, if the entity's UIActivationData.m_CanDeactivate is false, schedules adding ForceActivation using the command buffer. This triggers the tutorial UI activation behavior for matching prefabs.

Usage Example

// Example: enable a tutorial UI tag at runtime
var tutorialSystem = World.GetOrCreateSystemManaged<Game.Tutorials.TutorialUIActivationSystem>();
// Enable activation for the "build_mode" tag (only works if that tag exists in any tutorial prefab)
tutorialSystem.SetTag("build_mode", true);

// Typical system initialization occurs internally in OnCreate:
// [Preserve]
// protected override void OnCreate()
// {
//     base.OnCreate();
//     // m_BarrierSystem, query and map are initialized automatically
// }