Skip to content

Game.Prefabs.School

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase, IServiceUpgrade

Summary:
Prefab component representing a School building (city service). Exposes configurable fields used by the editor (student capacity, level, graduation modifier, wellbeing and health). When converted to entities the prefab registers the appropriate ECS components (SchoolData, UpdateFrameData and, depending on other attached components, Game.Buildings.School, Student, Efficiency and ServiceDistrict). Initialize(...) populates the SchoolData component and sets an UpdateFrameData with a frame interval of 6.


Fields

  • public int m_StudentCapacity = 80
    Defines the number of students the school can handle. Used to populate SchoolData.m_StudentCapacity during initialization.

  • public SchoolLevel m_Level
    Education level of the school (mapped to SchoolData.m_EducationLevel). Enum type SchoolLevel determines the education tier.

  • public float m_GraduationModifier
    Modifier applied to graduation rates; written to SchoolData.m_GraduationModifier.

  • public sbyte m_StudentWellbeing
    Student wellbeing value (signed byte) written to SchoolData.m_StudentWellbeing.

  • public sbyte m_StudentHealth
    Student health value (signed byte) written to SchoolData.m_StudentHealth.

Properties

  • None declared on this prefab.

Constructors

  • public School()
    Implicit default constructor. Field defaults: m_StudentCapacity = 80, other fields are default(T) unless set in inspector.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers components required by the prefab itself when creating a prefab archetype. Adds:
  • SchoolData (ReadWrite)
  • UpdateFrameData (ReadWrite)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Registers components for the runtime archetype produced from this prefab. Always adds Game.Buildings.School. If the prefab does not include ServiceUpgrade:

  • If CityServiceBuilding component is present, adds Efficiency.
  • Adds Student.
  • If UniqueObject component is not present, adds ServiceDistrict. This conditional logic allows the same prefab to be used both as a base service building and as an upgrade/extension.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    Registers the component set used when this prefab is applied as an upgrade. Adds:

  • Game.Buildings.School (ReadWrite)
  • Student (ReadWrite)

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Populates ECS component data on the created entity:

  • Constructs a SchoolData struct and sets:
    • m_EducationLevel = (byte)m_Level
    • m_StudentCapacity = m_StudentCapacity
    • m_GraduationModifier = m_GraduationModifier
    • m_StudentWellbeing = m_StudentWellbeing
    • m_StudentHealth = m_StudentHealth
  • Writes SchoolData to the entity.
  • Writes UpdateFrameData(6) to the entity (schedules update interval).

Usage Example

// Example: how the prefab initializes entity data (equivalent to the Initialize method)
protected override void Initialize(EntityManager entityManager, Entity entity)
{
    var sd = default(SchoolData);
    sd.m_EducationLevel = (byte)m_Level;
    sd.m_StudentCapacity = m_StudentCapacity;
    sd.m_GraduationModifier = m_GraduationModifier;
    sd.m_StudentWellbeing = m_StudentWellbeing;
    sd.m_StudentHealth = m_StudentHealth;
    entityManager.SetComponentData(entity, sd);

    // Make the entity be updated every 6 frames
    entityManager.SetComponentData(entity, new UpdateFrameData(6));
}

{{ Notes: - This prefab relies on other components (ServiceUpgrade, CityServiceBuilding, UniqueObject) to decide which runtime components to include. When authoring custom school-like prefabs, ensure those marker components are present/absent to get the intended archetype. - The SchoolData and other component types referenced must match the game's ECS definitions (namespaces Game.Buildings, etc.).
}}