Game.UnlockableBase
Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs
Type: abstract class
Base: ComponentBase
Summary:
UnlockableBase is an abstract ComponentBase intended for prefabs that can be locked/unlocked by dependencies. It provides no prefab/archetype component defaults itself but exposes a LateInitialize overload that accepts a dependency list and a static helper DefaultLateInitialize which populates an entity's UnlockRequirement buffer for any dependent prefabs that are considered "unlockable" by the game's PrefabSystem.
Fields
- This class declares no instance fields.
Properties
- This class declares no properties.
Constructors
public UnlockableBase()
This class does not define an explicit constructor; the default constructor is provided by the runtime. As an abstract type it is intended to be subclassed.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Empty override. Intended for derived types to add required ComponentType entries for prefab creation. The base implementation does nothing. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. Intended for derived types to add required ComponentType entries for archetype creation. The base implementation does nothing. -
public virtual void LateInitialize(EntityManager entityManager, Entity entity, List<PrefabBase> dependencies)
By default this implementation calls the parameterless LateInitialize(entityManager, entity) (presumably inherited from ComponentBase). Derived classes can override this method to perform late initialization that has access to the list of dependent prefabs. -
public static void DefaultLateInitialize(EntityManager entityManager, Entity entity, List<PrefabBase> dependencies)
Static helper that scans the provided dependencies list and, for each dependency that the PrefabSystem reports as unlockable, adds an UnlockRequirement to the entity's DynamicBuffer. Each requirement is created with UnlockFlags.RequireAll. Implementation details: - Resolves PrefabSystem via entityManager.World.GetExistingSystemManaged
(). - Obtains the entity's DynamicBuffer
using entityManager.GetBuffer (entity). - Iterates dependencies; for each PrefabBase where PrefabSystem.IsUnlockable(prefabBase) is true, gets the corresponding entity with PrefabSystem.GetEntity(prefabBase) and appends new UnlockRequirement(entity, UnlockFlags.RequireAll).
Effect: after calling this helper the entity will require unlocking of all detected unlockable prefabs listed in dependencies (RequireAll).
Usage Example
// Example derived unlockable prefab that uses the default helper to add unlock requirements
public class MyUnlockable : UnlockableBase
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
// add any components your prefab needs, e.g.
// components.Add(ComponentType.ReadWrite<SomeComponent>());
}
public override void LateInitialize(EntityManager entityManager, Entity entity, List<PrefabBase> dependencies)
{
// Call base to preserve any behavior from ComponentBase (base implementation calls the
// parameterless LateInitialize(entityManager, entity)).
base.LateInitialize(entityManager, entity, dependencies);
// Populate UnlockRequirement buffer from dependencies that are unlockable.
UnlockableBase.DefaultLateInitialize(entityManager, entity, dependencies);
// Additional late initialization for this prefab...
}
}
Notes and tips: - DefaultLateInitialize is useful when a prefab should become unlockable only after certain dependent prefabs are unlocked. - The UnlockRequirement buffer and UnlockFlags semantics are part of the game's unlocking system; RequireAll enforces that all listed requirements must be satisfied. - If you need custom unlock logic (e.g., different flags per dependency), override LateInitialize and populate the UnlockRequirement buffer manually.