Skip to content

Game.Prefabs.UnlockAllSystem

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: Game.Common.GameSystemBase

Summary:
System that unlocks every locked prefab in the world by issuing Unlock events. On creation it caches references to several dependent systems (MilestoneSystem, a modification barrier for command buffers, UI highlight and signature-building UI systems), builds an entity query for entities with the Locked component (excluding MilestoneData), and prepares an archetype for Unlock event entities. When run, it creates Unlock event entities for each locked prefab, asks the MilestoneSystem to unlock all milestones, and tells UI systems to skip their next update. The system disables itself after performing its operation.


Fields

  • private MilestoneSystem m_MilestoneSystem
    Reference to the MilestoneSystem; used to call UnlockAllMilestones() after generating unlock events.

  • private ModificationBarrier1 m_ModificationBarrier
    Barrier system used to create an EntityCommandBuffer for safe structural changes (creating Unlock event entities) from the system.

  • private UIHighlightSystem m_UIHighlightSystem
    Reference to the UI highlight system; SkipUpdate() is called so UI highlight logic doesn't run immediately after unlocking.

  • private SignatureBuildingUISystem m_SignatureBuildingUISystem
    Reference to the signature building UI system; SkipUpdate() is called to prevent immediate UI updates that would conflict with the unlock operation.

  • private EntityQuery m_LockedQuery
    EntityQuery that matches entities/components with Locked (read-only) and excludes MilestoneData. Used to find all locked prefabs to unlock.

  • private EntityArchetype m_UnlockEventArchetype
    Archetype used to create Unlock event entities. It contains at least Event and Unlock component types.

Properties

  • None. This system exposes no public properties.

Constructors

  • public UnlockAllSystem()
    Default constructor. The system uses the OnCreate override to initialize internal state and dependencies; the constructor itself is empty and marked [Preserve] in compiled code.

Methods

  • protected override void OnCreate()
    Initializes the system:
  • Retrieves/creates dependent systems (MilestoneSystem, ModificationBarrier1, UIHighlightSystem, SignatureBuildingUISystem) from the World.
  • Builds m_LockedQuery to select entities with Locked and without MilestoneData.
  • Creates m_UnlockEventArchetype for Event + Unlock components.
  • Calls RequireForUpdate(m_LockedQuery) so the system only updates when there are matching locked entities.
  • Disables the system (base.Enabled = false) so it only runs when explicitly enabled or when the query becomes non-empty.

  • protected override void OnUpdate()
    Called when the system runs. It calls UnlockAllImpl() to perform the unlocking and then disables itself (base.Enabled = false) so it doesn't continuously run.

  • private void UnlockAllImpl()
    Main implementation:

  • Creates an EntityCommandBuffer via the modification barrier.
  • Converts m_LockedQuery to a NativeArray (Allocator.TempJob) to enumerate all locked prefab entities.
  • For each locked entity, creates a new entity using m_UnlockEventArchetype and sets an Unlock component referring to the locked prefab.
  • Disposes the NativeArray.
  • Calls m_MilestoneSystem.UnlockAllMilestones() to force milestone state changes.
  • Calls SkipUpdate() on m_UIHighlightSystem and m_SignatureBuildingUISystem to avoid immediate UI work that could conflict with the unlock operation.

Notes: - Structural changes are queued via the EntityCommandBuffer; they will be played back by the barrier system at the appropriate synchronization point. - The query uses Allocator.TempJob for listing entities; the array is disposed manually. - The system is written to run once (or when explicitly enabled) and then disable itself.

Usage Example

// Example: trigger the UnlockAllSystem to run once.
// This can be called from other systems or mod code that has access to the World.
[Preserve]
public void TriggerUnlockAll(World world)
{
    var unlockAll = world.GetOrCreateSystemManaged<Game.Prefabs.UnlockAllSystem>();
    // Enabling the system will make it execute OnUpdate on the next simulation tick.
    unlockAll.Enabled = true;
}