Game.Prefabs.EducationPrefab
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
Prefab that configures education-related parameters for an education service in the ECS world. This prefab holds references and probability parameters used to populate the EducationParameterData component on the prefab entity during initialization. It's intended for use in modding Cities: Skylines 2 to adjust how students and adults interact with schools (entering high school, leaving inoperable schools, etc.).
Fields
-
public PrefabBase m_EducationServicePrefab
Reference to another prefab that represents the underlying education service. During LateInitialize this prefab reference is resolved to an Entity via the PrefabSystem and stored in EducationParameterData.m_EducationServicePrefab. -
public float m_InoperableSchoolLeaveProbability
Probability (range 0..1) that a student leaves a disabled/inoperable school. Attribute: Tooltip("Probability that a student leaves a disabled school (1024 rolls per day)"), Range(0f,1f). Default: 0.1f. -
public float m_EnterHighSchoolProbability
Probability (range 0..1) that a student enters the high school. Attribute: Tooltip("Probability that a student enter the high school"), Range(0f,1f). Default: 0.75f. -
public float m_AdultEnterHighSchoolProbability
Probability (range 0..1) that an adult will enter high school. Attribute: Tooltip("Probability for adult to enter the high school"), Range(0f,1f). Default: 0.1f. -
public float m_WorkerContinueEducationProbability
Probability (range 0..1) that a worker continues education (enters high school / continues education). Attribute: Tooltip("Probability for worker to enter the high school"), Range(0f,1f). Default: 0.1f.
Properties
- This class does not declare any public properties. It exposes configuration via public fields and writes runtime data into the EducationParameterData component during LateInitialize.
Constructors
public EducationPrefab()
No custom constructor is defined in the source; the class uses the default parameterless constructor provided by C#. Initialization of runtime ECS data is performed in LateInitialize rather than in a constructor.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the EducationParameterData component type to the provided hash set so that the prefab's entity will include that component. Calls base.GetPrefabComponents(components) first to include any base prefab components. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Overrides the base method but does not add any additional archetype components beyond what the base adds. Kept for extensibility and explicitness. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called after the prefab entity has been created. Resolves the referenced m_EducationServicePrefab to an Entity using PrefabSystem (obtained from entityManager.World.GetOrCreateSystemManaged()) and sets the EducationParameterData component on the entity with the floating-point probability values and the resolved education service entity. This is where prefab authoring values are transferred into runtime ECS component data.
Usage Example
// Example: After prefabs are initialized, read the EducationParameterData from the prefab entity
var world = World.DefaultGameObjectInjectionWorld; // or other world where prefabs are created
var entityManager = world.EntityManager;
var prefabSystem = world.GetOrCreateSystemManaged<PrefabSystem>();
// Suppose you have a reference to the EducationPrefab authoring asset (educationPrefabAuthoring)
// and want to get the entity for it (this is how LateInitialize will have set up the data).
Entity prefabEntity = prefabSystem.GetEntity(educationPrefabAuthoring);
// Now read the component that was written during LateInitialize:
if (entityManager.HasComponent<EducationParameterData>(prefabEntity))
{
var eduParams = entityManager.GetComponentData<EducationParameterData>(prefabEntity);
Debug.Log($"Education service entity: {eduParams.m_EducationServicePrefab}");
Debug.Log($"Inoperable leave prob: {eduParams.m_InoperableSchoolLeaveProbability}");
Debug.Log($"Enter high school prob: {eduParams.m_EnterHighSchoolProbability}");
Debug.Log($"Adult enter high school prob: {eduParams.m_AdultEnterHighSchoolProbability}");
Debug.Log($"Worker continue education prob: {eduParams.m_WorkerContinueEducationProbability}");
}
Notes and tips: - EducationParameterData is the runtime component type populated by this prefab; its fields mirror the public fields on this prefab (including m_EducationServicePrefab as an Entity reference). - The PrefabSystem is used to map authoring PrefabBase references to ECS Entities — ensure it has been run/initialized in the world you are querying. - Probabilities are specified as floats in the 0..1 range; tooltips and Range attributes are available for in-editor guidance.