Skip to content

Game.Prefabs.StrictObjectBuiltRequirementPrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: UnlockRequirementPrefab

Summary:
Prefab class that defines an unlock requirement which is satisfied when a specific prefab (object) has been built a minimum number of times. The class: - Exposes a reference to the required prefab (m_Requirement) and the minimum count (m_MinimumCount, default 1). - Declares that the StrictObjectBuiltRequirementData component is required on the instantiated entity. - Adds an UnlockRequirement entry (with UnlockFlags.RequireAll) to the entity's UnlockRequirement buffer. - Resolves the referenced PrefabBase to its runtime Entity via PrefabSystem and stores that Entity in the StrictObjectBuiltRequirementData during LateInitialize.

This class is annotated with [ComponentMenu("Prefabs/Unlocking/", new Type[] { })] so it appears under the Prefabs/Unlocking menu in the editor.


Fields

  • public PrefabBase m_Requirement
    Reference to the prefab that must be built to satisfy this unlock requirement. The referenced PrefabBase is resolved to an Entity (via PrefabSystem.GetEntity) during LateInitialize and stored in the runtime StrictObjectBuiltRequirementData.

  • public int m_MinimumCount = 1
    Minimum number of instances of the required prefab that must exist to satisfy the requirement. Defaults to 1 and is copied into the StrictObjectBuiltRequirementData in LateInitialize.

Properties

  • None. This prefab class exposes only public fields; no C# properties are defined.

Constructors

  • public StrictObjectBuiltRequirementPrefab()
    Implicit default constructor. The prefab relies on its serialized fields (m_Requirement, m_MinimumCount) being set (typically in the editor) and performs runtime wiring in LateInitialize.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Calls base.GetDependencies(prefabs) and adds m_Requirement to the provided prefabs list. This ensures the referenced prefab is treated as a dependency of this prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Calls base.GetPrefabComponents(components) and adds ComponentType.ReadWrite() to the set, declaring that spawned entities require that component type.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization after the prefab entity has been created:

  • Calls the base LateInitialize.
  • Adds an UnlockRequirement entry to the entity's UnlockRequirement buffer with UnlockFlags.RequireAll.
  • Resolves the referenced PrefabBase (m_Requirement) to an Entity using the PrefabSystem from the entityManager.World.
  • Creates a StrictObjectBuiltRequirementData instance with the resolved entity and m_MinimumCount, and writes it to the entity via entityManager.SetComponentData(entity, componentData).

Usage Example

// Example: configure the prefab in code (typically done in editor)
var reqPrefab = new StrictObjectBuiltRequirementPrefab
{
    m_Requirement = someOtherPrefab, // PrefabBase reference set in editor or code
    m_MinimumCount = 2
};

// At runtime, LateInitialize will be called by the prefab system.
// The resulting entity will:
// - have an UnlockRequirement entry (RequireAll)
// - have StrictObjectBuiltRequirementData with m_Requirement set to the resolved Entity of someOtherPrefab
// - have m_MinimumCount copied into the component data