Game.Prefabs.Modes.SchoolMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
SchoolMode is a mode prefab component used to modify runtime SchoolData for one or more school prefabs. It contains an array of ModeData entries that reference target school prefabs and the values to apply when the mode is enabled. The component overrides lifecycle methods to (a) ensure the targeted School entity/components are accessed (RecordChanges), (b) apply mode-specific multipliers and modifiers to the SchoolData (ApplyModeData), and (c) restore the default values from the original School prefab (RestoreDefaultData). The class logs a critical error if a referenced PrefabBase does not contain a School component.
Fields
public ModeData[] m_ModeDatas
Holds the set of ModeData entries describing which school prefabs to affect and what values to apply for each.
Nested type ModeData (Serializable):
-
public PrefabBase m_Prefab
Reference to the school prefab to modify. -
public float m_StudentCapacityMultifier
Multiplier applied to the prefab's Student capacity when ApplyModeData runs. (Note: spelled "Multifier" in source.) -
public float m_GraduationModifier
Value to set for the school's graduation modifier when the mode is applied. -
public sbyte m_StudentWellbeing
Value to set for student wellbeing in SchoolData. -
public sbyte m_StudentHealth
Value to set for student health in SchoolData.
Properties
- (None declared in this class)
Constructors
public SchoolMode()
Implicit default constructor (not declared explicitly in source).
Methods
-
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Iterates over m_ModeDatas, looks up the School component on the referenced PrefabBase, gets the corresponding ECS Entity via prefabSystem.GetEntity(component.prefab), and calls entityManager.GetComponentData(entity). The method includes a null check and logs a critical error if the School component is not found on the referenced prefab. In the original code, GetComponentData is invoked (likely to ensure the component exists/is touched for change tracking). -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: resolves the target School prefab and its ECS entity, reads the current SchoolData from the entity, multiplies m_StudentCapacity by m_StudentCapacityMultifier, sets m_GraduationModifier, m_StudentWellbeing and m_StudentHealth from the ModeData, then writes the modified SchoolData back to the entity (entityManager.SetComponentData). Logs a critical error and skips the entry if the School component is not present on the referenced PrefabBase. -
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
For each ModeData entry: resolves the target School prefab and its ECS entity, obtains the SchoolData for that entity, and restores fields from the original MonoBehaviour School component values (m_StudentCapacity, m_GraduationModifier, m_StudentWellbeing, m_StudentHealth). Writes the restored SchoolData back to the entity. Logs a critical error and skips the entry if the School component is missing.
Usage Example
// Example: apply a school mode at runtime.
// Assumes you have valid references to an EntityManager and PrefabSystem,
// and a PrefabBase reference (someSchoolPrefab) pointing to a School prefab.
var mode = new Game.Prefabs.Modes.SchoolMode();
mode.m_ModeDatas = new Game.Prefabs.Modes.SchoolMode.ModeData[]
{
new Game.Prefabs.Modes.SchoolMode.ModeData
{
m_Prefab = someSchoolPrefab,
m_StudentCapacityMultifier = 1.25f,
m_GraduationModifier = 1.1f,
m_StudentWellbeing = 3,
m_StudentHealth = 2
}
};
// Apply the mode (modify ECS SchoolData for the referenced prefab entities)
mode.ApplyModeData(entityManager, prefabSystem);
// To restore defaults later:
mode.RestoreDefaultData(entityManager, prefabSystem);
Notes and tips: - The component expects the referenced PrefabBase to contain a School MonoBehaviour. If not found, it logs via ComponentBase.baseLog.Critical and skips that entry. - The code uses PrefabSystem.GetEntity(component.prefab) to map the prefab to its ECS Entity; ensure the prefab is registered with the game's PrefabSystem. - Be mindful that m_StudentCapacityMultifier multiplies the current SchoolData.m_StudentCapacity — if you call ApplyModeData multiple times the effect will stack unless you restore defaults first.