Skip to content

Game.Prefabs.CitizenParametersPrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: PrefabBase

Summary:
A Unity MonoBehaviour-style prefab class used to expose and configure citizen-related simulation parameters in editor (via tooltips) and to inject those values into ECS as a CitizenParametersData component during prefab initialization. This prefab makes the runtime systems read configurable rates such as divorce, birth, job-switching and partner-seeking behavior from the entity component that it writes in LateInitialize.


Fields

  • public float m_DivorceRate
    The divorce rate as a fractional value (e.g., 0.16 means 16%). Exposed in inspector with a Tooltip.

  • public float m_LookForPartnerRate
    The probability (fraction) a single citizen will look for a partner (e.g., 0.08 means 8%). Exposed in inspector with a Tooltip.

  • public float2 m_LookForPartnerTypeRate
    Pair of rates (Unity.Mathematics.float2): x = Same Gender rate, y = Any Gender rate. The remainder (1 - x - y) represents Different Gender rate. Exposed in inspector with a Tooltip.

  • public float m_BaseBirthRate
    The base birth rate as a fraction (e.g., 0.02 means 2%). Exposed in inspector with a Tooltip.

  • public float m_AdultFemaleBirthRateBonus
    Additional birth-rate bonus applied to adult females (added to base birth rate). For example, 0.08 means adult female final birth rate = base (0.02) + bonus (0.08) = 0.10 (10%). Exposed in inspector with a Tooltip.

  • public float m_StudentBirthRateAdjust
    Multiplier applied to final birth rate for students (for example, 0.5 means students have half the final birth rate). Exposed in inspector with a Tooltip.

  • public float m_SwitchJobRate
    Chance (fraction) a citizen with a job will check to switch jobs. Also gated by the LookForNewJobEmployableRate check. Example: 0.032 means 3.2%. Exposed in inspector with a Tooltip.

  • public float m_LookForNewJobEmployableRate
    A ratio used to compare free workplace positions to employable workers. For example, 2 means twice as many free positions as employable workers; the prefab logic is used to skip looking for new jobs if free positions < random(rate * employable workers). Exposed in inspector with a Tooltip.

Properties

  • None.

Constructors

  • public CitizenParametersPrefab()
    Default MonoBehaviour-style prefab constructor (no custom logic defined in source).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the required ECS component type(s) that this prefab will produce. Specifically this method adds ReadWrite so the prefab system knows to include that component on the created entity.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Writes the prefab-field values into the entity's CitizenParametersData component using EntityManager.SetComponentData. This maps:

  • CitizenParametersData.m_DivorceRate <- m_DivorceRate
  • CitizenParametersData.m_LookForPartnerRate <- m_LookForPartnerRate
  • CitizenParametersData.m_LookForPartnerTypeRate <- m_LookForPartnerTypeRate
  • CitizenParametersData.m_BaseBirthRate <- m_BaseBirthRate
  • CitizenParametersData.m_AdultFemaleBirthRateBonus <- m_AdultFemaleBirthRateBonus
  • CitizenParametersData.m_StudentBirthRateAdjust <- m_StudentBirthRateAdjust
  • CitizenParametersData.m_SwitchJobRate <- m_SwitchJobRate
  • CitizenParametersData.m_LookForNewJobEmployableRate <- m_LookForNewJobEmployableRate

This method is called by the prefab system when converting/creating the ECS entity and ensures runtime systems have the configured values.

Usage Example

// Place this script on a prefab in the editor and configure the exposed fields via the Inspector.
// At runtime, when the prefab system converts the prefab to an ECS entity, LateInitialize
// will populate the CitizenParametersData component on that entity.

public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    entityManager.SetComponentData(entity, new CitizenParametersData
    {
        m_DivorceRate = m_DivorceRate,
        m_LookForPartnerRate = m_LookForPartnerRate,
        m_LookForPartnerTypeRate = m_LookForPartnerTypeRate,
        m_BaseBirthRate = m_BaseBirthRate,
        m_AdultFemaleBirthRateBonus = m_AdultFemaleBirthRateBonus,
        m_StudentBirthRateAdjust = m_StudentBirthRateAdjust,
        m_SwitchJobRate = m_SwitchJobRate,
        m_LookForNewJobEmployableRate = m_LookForNewJobEmployableRate
    });
}

Additional notes: - The prefab uses Unity.Mathematics.float2 for partner-type rates. - Ensure the CitizenParametersData struct exists and has matching field names/types for correct mapping. - This prefab class is attributed with ComponentMenu("Settings/") so it appears under Settings in Unity's Add Component menu.