Skip to content

Game.Prefabs.Modes.EducationParametersMode

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes

Type: class (public)

Base: EntityQueryModePrefab

Summary:
A mode prefab used to configure education-related probabilities for the game's ECS systems. This MonoBehaviour exposes serialized probability parameters (with UnityEngine.Range attributes) that are applied to the EducationParameterData component on a singleton entity. The class provides methods to produce an EntityQueryDesc for the relevant component, apply the current mode values to the ECS component, and restore default values from the EducationPrefab stored in the PrefabSystem.


Fields

  • public float m_InoperableSchoolLeaveProbability
    A serialized probability (0..1) that controls how likely people leave inoperable schools. Decorated with [Range(0f, 1f)] so it can be adjusted from the Unity inspector.

  • public float m_EnterHighSchoolProbability
    A serialized probability (0..1) that controls the chance to enter high school. Decorated with [Range(0f, 1f)] for inspector editing.

  • public float m_AdultEnterHighSchoolProbability
    A serialized probability (0..1) indicating the chance that adults enter high school. Decorated with [Range(0f, 1f)].

  • public float m_WorkerContinueEducationProbability
    A serialized probability (0..1) representing the chance a worker continues education. Decorated with [Range(0f, 1f)].

Properties

  • This class does not declare additional properties beyond what it inherits from its base types.

Constructors

  • public EducationParametersMode()
    Default parameterless constructor (implicit). The type is a MonoBehaviour-derived prefab and will typically be instantiated/attached in the Unity editor or by prefab code; there is no custom construction logic defined in this class.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that targets entities having the EducationParameterData component. Implementation builds and returns an EntityQueryDesc with All = [ ComponentType.ReadOnly() ].

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Calls entityManager.GetComponentData(entity). This method is intended to be used by the base mode/prefab system to read/record the current component state before applying changes (no local change tracking logic is performed here).

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Applies the serialized mode values to the EducationParameterData on the singleton entity found via requestedQuery.GetSingletonEntity(). The method:

  • Retrieves the singleton entity from the provided query.
  • Reads the EducationParameterData component, sets its probability fields from the serialized fields on this MonoBehaviour, and writes the updated component back via entityManager.SetComponentData.
  • Returns the incoming JobHandle deps unchanged.

Note: requestedQuery must resolve to a singleton entity (GetSingletonEntity will throw if it does not).

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Restores default values for the first entity in the provided entities array by:
  • Getting the EducationPrefab from the PrefabSystem for the entity.
  • Reading the current EducationParameterData component and overwriting its probability fields with the defaults from the EducationPrefab.
  • Writing the updated component back to the entity via entityManager.SetComponentData.

This method is used by the prefab/mode system to revert changes back to the prefab-defined defaults.

Usage Example

// Example: configure the mode from code (typically done in the editor)
var go = new GameObject("EducationMode");
var mode = go.AddComponent<Game.Prefabs.Modes.EducationParametersMode>();
mode.m_InoperableSchoolLeaveProbability = 0.05f;
mode.m_EnterHighSchoolProbability = 0.8f;
mode.m_AdultEnterHighSchoolProbability = 0.1f;
mode.m_WorkerContinueEducationProbability = 0.25f;

// Example: apply mode to ECS (simplified — requires valid EntityManager and EntityQuery)
// EntityQueryDesc desc = mode.GetEntityQueryDesc();
// EntityQuery query = entityManager.CreateEntityQuery(desc);
// mode.ApplyModeData(entityManager, query, default);

Additional notes: - The MonoBehaviour is decorated with [ComponentMenu("Modes/Mode Parameters/")] making it available in the Unity editor menu. - The class assumes the presence of an EducationParameterData component on a singleton entity and an EducationPrefab accessible via the PrefabSystem when restoring defaults. - Ensure the provided EntityQuery resolves to a singleton entity before calling ApplyModeData to avoid exceptions.