Game.Prefabs.SchoolData
Assembly: Assembly-CSharp (typical for game code)
Namespace: Game.Prefabs
Type: struct
Base: Implements IComponentData, IQueryTypeParameter, ICombineData
Summary:
Represents serialized prefab/component data for a school. Holds configuration and aggregated runtime data used by the ECS (Unity.Entities) systems, such as student capacity, education level, graduation modifier, and student wellbeing/health. Supports combining (merging) with other SchoolData instances (used when aggregating multiple sources) and custom binary serialization/deserialization with version-aware handling for happiness/health fields.
Fields
-
public int m_StudentCapacity
The capacity (number of students) attributable to this school prefab/data. Used when aggregating total capacity. -
public float m_GraduationModifier
Modifier applied to graduation rate or graduation-related calculations. Combined additively when merging data. -
public byte m_EducationLevel
Education level provided by the school (stored as a byte). When combining, the maximum between two levels is kept. -
public sbyte m_StudentWellbeing
Signed byte representing student wellbeing. This value is combined additively. Note: its presence in deserialization is version-gated. -
public sbyte m_StudentHealth
Signed byte representing student health. Also combined additively. Presence in deserialization is version-gated.
Properties
- None (no C# properties are declared in this struct).
Constructors
public SchoolData()
The struct uses the implicit default constructor (no explicit constructor declared). All fields default to their CLR defaults (0, 0f, 0, 0, 0).
Methods
public void Combine(SchoolData otherData)
Merges another SchoolData into this instance:- Adds otherData.m_StudentCapacity to m_StudentCapacity.
- Sets m_EducationLevel to the maximum of the two education levels.
- Adds otherData.m_GraduationModifier to m_GraduationModifier.
- Adds otherData.m_StudentWellbeing to m_StudentWellbeing.
-
Adds otherData.m_StudentHealth to m_StudentHealth. Use this when aggregating data from multiple prefabs or sources (ICombineData semantics).
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes fields to a writer in the following order: - m_StudentCapacity (int)
- m_GraduationModifier (float)
- m_EducationLevel (byte)
- m_StudentWellbeing (sbyte)
-
m_StudentHealth (sbyte)
This method is used to persist prefab/component data to the game's binary format. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields from a reader in the same order as serialization. The last two fields (m_StudentWellbeing and m_StudentHealth) are only read if the reader.context.version is greater than or equal to Version.happinessAdjustRefactoring. This version check preserves compatibility with older save/prefab formats that did not include wellbeing/health fields.
Usage Example
// Combining two SchoolData instances (e.g., when aggregating multiple sources)
SchoolData a = new SchoolData { m_StudentCapacity = 100, m_GraduationModifier = 0.05f, m_EducationLevel = 2, m_StudentWellbeing = 1, m_StudentHealth = 0 };
SchoolData b = new SchoolData { m_StudentCapacity = 50, m_GraduationModifier = 0.02f, m_EducationLevel = 3, m_StudentWellbeing = -1, m_StudentHealth = 1 };
a.Combine(b);
// Result:
// a.m_StudentCapacity == 150
// a.m_GraduationModifier == 0.07f
// a.m_EducationLevel == 3
// a.m_StudentWellbeing == 0
// a.m_StudentHealth == 1
// Serialization example (writer implementation provided by the game's serialization system)
void SaveSchoolData<TWriter>(TWriter writer, SchoolData data) where TWriter : IWriter
{
data.Serialize(writer);
}
// Deserialization example (reader implementation provided by the game's serialization system)
SchoolData LoadSchoolData<TReader>(TReader reader) where TReader : IReader
{
SchoolData data = default;
data.Deserialize(reader); // will respect reader.context.version for wellbeing/health
return data;
}
Notes: - The struct is intended for use with Unity's ECS (IComponentData) and the game's custom serialization. When writing mods that create or modify prefab/component data, follow the same serialization order and respect version checks to remain compatible with game saves and other mods. - Version.happinessAdjustRefactoring is a game-defined version constant — ensure compatibility if you manipulate saved data formats.