Skip to content

Game.Unlockable

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
UnlockableBase

Summary:
Unlockable is a prefab component used by the game's prefab system to declare unlock dependencies for a prefab. It exposes arrays for "require all" and "require any" dependencies (PrefabBase references) and a flag to ignore automatically-collected dependencies. During LateInitialize it translates those PrefabBase references (and any dependencies collected from GetDependencies) into runtime UnlockRequirement entries (stored in a DynamicBuffer on the prefab entity) using the PrefabSystem. This component is meant to be attached to prefab definitions to make them behave as unlockable items in the game's unlock system.


Fields

  • public PrefabBase[] m_RequireAll
    Array of PrefabBase references. Each entry here will be added as a RequireAll unlock requirement during LateInitialize if the referenced prefab is itself unlockable. Use this to explicitly declare prefabs that must all be unlocked before this prefab becomes available.

  • public PrefabBase[] m_RequireAny
    Array of PrefabBase references. Each entry here will be added as a RequireAny unlock requirement during LateInitialize if the referenced prefab is unlockable. Use this to declare multiple alternative prerequisites (at least one required).

  • public bool m_IgnoreDependencies
    If true, the component will skip adding dependencies collected via the base/GetDependencies flow. Useful when you want to control unlock requirements only via the explicit m_RequireAll / m_RequireAny arrays.

Properties

  • This class does not define public properties of its own. It relies on behavior inherited from UnlockableBase and interacts with runtime systems (PrefabSystem, DynamicBuffer).

Constructors

  • public Unlockable()
    Default parameterless constructor (implicit). No special initialization logic is defined in the source; initialization of unlock requirements is done in LateInitialize.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Collects dependency PrefabBase references to be provided to the prefab system. Implementation:
  • Calls base.GetDependencies(prefabs).
  • If m_RequireAll is not null, each entry is appended to the provided prefabs list.
  • If m_RequireAny is not null, each entry is appended to the provided prefabs list. This ensures that the explicit require lists are treated as prefab dependencies by the prefab pipeline.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Empty override. The Unlockable component does not add any additional component types to the prefab via this hook (no-op).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override. No archetype components are added by this component (no-op).

  • public override void LateInitialize(EntityManager entityManager, Entity entity, List<PrefabBase> dependencies)
    Converts prefab references into runtime unlock requirements on the prefab's entity:

  • Calls base.LateInitialize.
  • Obtains the PrefabSystem from the entityManager.World.
  • Gets the DynamicBuffer for the entity.
  • If m_IgnoreDependencies is false, iterates the incoming dependencies list; for each PrefabBase that PrefabSystem considers unlockable, it resolves the corresponding Entity and adds an UnlockRequirement with UnlockFlags.RequireAll.
  • Iterates m_RequireAll (if non-null): for each unlockable prefab, adds an UnlockRequirement with UnlockFlags.RequireAll.
  • Iterates m_RequireAny (if non-null): for each unlockable prefab, adds an UnlockRequirement with UnlockFlags.RequireAny. This populates the runtime unlock requirements consumed by the unlock system.

Usage Example

// Example: custom unlockable that adds one extra explicit requirement at runtime
public class CustomUnlockable : Unlockable
{
    public PrefabBase m_ExtraRequirement;

    public override void LateInitialize(EntityManager entityManager, Entity entity, List<PrefabBase> dependencies)
    {
        base.LateInitialize(entityManager, entity, dependencies);

        // Optionally add additional requirement programmatically
        if (m_ExtraRequirement != null)
        {
            var prefabSystem = entityManager.World.GetExistingSystemManaged<PrefabSystem>();
            if (prefabSystem.IsUnlockable(m_ExtraRequirement))
            {
                var buffer = entityManager.GetBuffer<UnlockRequirement>(entity);
                buffer.Add(new UnlockRequirement(prefabSystem.GetEntity(m_ExtraRequirement), UnlockFlags.RequireAll));
            }
        }
    }
}

Notes and Implementation Details: - UnlockRequirement and UnlockFlags are the runtime structures/flags used by the unlock system; this component fills a DynamicBuffer on the prefab entity. - PrefabSystem.IsUnlockable(prefab) and PrefabSystem.GetEntity(prefab) are used to translate PrefabBase references into Entities; only prefabs that are themselves unlockable are added as requirements. - m_IgnoreDependencies controls whether dependencies gathered from other means (base class or prefab pipeline) are included; explicit m_RequireAll/m_RequireAny entries are always processed unless null.