Game.Prefabs.CitizenRequirementPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: UnlockRequirementPrefab
Summary:
Prefab class that defines an unlock requirement based on citizen-related metrics. It exposes two configurable fields (minimum population and minimum happiness) and ensures the entity created from this prefab receives the appropriate UnlockRequirement buffer entry and a CitizenRequirementData component populated from the prefab's fields. The class is annotated with a ComponentMenu attribute for Unity editor placement.
Fields
-
public int m_MinimumPopulation = 100
Minimum population threshold required for the unlock. Default value in code is 100. This value is copied into the CitizenRequirementData component during LateInitialize. -
public int m_MinimumHappiness
Minimum happiness threshold required for the unlock. This value is copied into the CitizenRequirementData component during LateInitialize.
Properties
- None (this prefab class has no public properties)
Constructors
public CitizenRequirementPrefab()
Default constructor (implicit if not defined). Prefab values are typically set via the Unity inspector; default for m_MinimumPopulation is 100 as declared.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs) : void
Calls the base implementation to collect prefab dependencies. No extra dependencies are added by this class itself. -
public override void GetPrefabComponents(HashSet<ComponentType> components) : void
Calls the base implementation and then adds a ReadWrite requirement for the CitizenRequirementData component type to the provided components set. This indicates that entities created from this prefab will include that component. -
public override void LateInitialize(EntityManager entityManager, Entity entity) : void
Finalizes entity initialization for the prefab: - Calls base.LateInitialize(entityManager, entity).
- Adds an UnlockRequirement entry to the entity's UnlockRequirement buffer using UnlockFlags.RequireAll.
- Sets the CitizenRequirementData component on the entity, copying m_MinimumPopulation and m_MinimumHappiness into the component fields.
Behavioral notes: - The method relies on the existence of an UnlockRequirement dynamic buffer and the CitizenRequirementData component type on the entity; GetPrefabComponents ensures the CitizenRequirementData component type is declared for the prefab. - The UnlockRequirement entry uses UnlockFlags.RequireAll, meaning all contained checks must pass for the unlock to be satisfied.
Usage Example
// Example: when this prefab is instantiated (values usually set in the inspector),
// LateInitialize will add an UnlockRequirement buffer entry and set the CitizenRequirementData
// with the configured thresholds.
[Preserve]
public class ExampleUsage : CitizenRequirementPrefab
{
// Values are typically edited in the Unity inspector; demonstrating override is optional.
public ExampleUsage()
{
m_MinimumPopulation = 500;
m_MinimumHappiness = 75;
}
// LateInitialize is inherited and will:
// - add an UnlockRequirement(entity, UnlockFlags.RequireAll) to the entity's buffer
// - set CitizenRequirementData { m_MinimumPopulation = 500, m_MinimumHappiness = 75 }
}
{{ Additional information: - This prefab class requires the existence of the following component/data structures in the codebase: - CitizenRequirementData (IComponentData) with fields m_MinimumPopulation and m_MinimumHappiness. - UnlockRequirement dynamic buffer type and UnlockFlags enum. - UnlockRequirementPrefab base class which likely handles some shared unlocking behavior and buffer setup.
- Typical usage: create or configure a CitizenRequirementPrefab asset in the Unity editor, set m_MinimumPopulation and m_MinimumHappiness, and the prefab system will create entities that carry the unlock checks for gameplay unlocking logic. }}