Game.Prefabs.ForceUnlockRequirement
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
A prefab component that causes a ForceUnlockRequirementData component to be written to the prefab's entity during LateInitialize. It stores a reference to another prefab (m_Prefab) and, if that referenced prefab can be resolved to an Entity via the PrefabSystem, writes that Entity into the ForceUnlockRequirementData for the current prefab entity. This is used to mark a prefab as having a forced unlock requirement referencing another prefab.
Fields
public PrefabBase m_Prefab
Holds a reference to the target prefab that this prefab requires (the one to force as an unlock requirement). Set in the prefab (inspector or by code). During LateInitialize this reference is resolved to an Entity via PrefabSystem and stored into the entity component data (ForceUnlockRequirementData).
Properties
- This type does not declare any properties.
Constructors
public ForceUnlockRequirement()
Default parameterless constructor (inherited/auto-generated). No special construction logic in this class.
Methods
-
public override void GetPrefabComponents(System.Collections.Generic.HashSet<ComponentType> components)
Adds the runtime component type that should be attached to the prefab's entity: ComponentType.ReadWrite(). This ensures the ECS entity for the prefab contains (or can contain) the ForceUnlockRequirementData component. -
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<ComponentType> components)
No archetype components are added by this class — method intentionally left empty. -
public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
During LateInitialize, if m_Prefab is set and the PrefabSystem can resolve that PrefabBase to an Entity, this method creates a ForceUnlockRequirementData instance, sets its m_Prefab field to the resolved entity, and writes it to the given entity via entityManager.SetComponentData. Relies on PrefabSystem being available in the same World.
Notes and implementation details: - Depends on PrefabSystem.TryGetEntity to resolve PrefabBase to an Entity; if resolution fails, no component data is written. - The written ForceUnlockRequirementData.m_Prefab is an Entity reference (the code sets componentData.m_Prefab = entity2). - Ensure the referenced prefab is registered/loaded in the PrefabSystem prior to LateInitialize, otherwise resolution will fail.
Usage Example
// Example: assign a target prefab in code so that the current prefab will get
// a ForceUnlockRequirementData pointing to the target prefab's entity at LateInitialize.
public void AssignRequirement(PrefabBase sourcePrefab, PrefabBase requiredPrefab)
{
var comp = sourcePrefab.GetComponent<Game.Prefabs.ForceUnlockRequirement>();
if (comp == null)
{
comp = sourcePrefab.AddComponent<Game.Prefabs.ForceUnlockRequirement>();
}
comp.m_Prefab = requiredPrefab;
}
// After the game's prefab initialization runs, the source prefab's ECS entity
// will have ForceUnlockRequirementData.m_Prefab set to the required prefab's Entity
// if the PrefabSystem could resolve requiredPrefab to an Entity.