Game.Citizens.Student
Assembly: Assembly-CSharp
Namespace: Game.Citizens
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a student citizen component used by the game's ECS (Unity.Entities). Holds a reference to the school Entity the student attends, the last commute time (float), and the student's education level (byte). Implements custom binary serialization/deserialization for save/load with version-aware handling of the education level field.
Fields
-
public Entity m_School
Reference to the school Entity this student attends. May be Entity.Null if not assigned. -
public float m_LastCommuteTime
Stores the last commute time for the student (game time unit as used by the simulation). Useful for scheduling or timing when the student last traveled to/from school. -
public byte m_Level
Education level of the student encoded as a byte. When deserializing older save formats that predate the education-trading version, this field is set to byte.MaxValue to indicate an unknown/unset level.
Properties
- This type has no properties.
Constructors
public Student()
Implicit parameterless struct constructor provided by C#. No custom constructors are defined in the source.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer in the following order: m_School, m_LastCommuteTime, m_Level. Used during saving/export. Generic writer must implement IWriter. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component state from the provided reader in the same order as written. The method is version-aware: it always reads m_School and m_LastCommuteTime, but only reads m_Level if reader.context.version >= Version.educationTrading. For older versions, m_Level is set to byte.MaxValue to indicate no level data was stored.
Remarks: - reader.context.version and Version.educationTrading are part of the save/serialization versioning system; this ensures backward compatibility across save formats. - As an IComponentData, instances are intended to be attached to Entities via the ECS EntityManager.
Usage Example
// Add a Student component to an entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity someCitizenEntity = entityManager.CreateEntity();
// Suppose 'schoolEntity' is an existing school Entity in the world
Entity schoolEntity = /* obtain school entity */ Entity.Null;
var student = new Game.Citizens.Student
{
m_School = schoolEntity,
m_LastCommuteTime = 0f,
m_Level = 1 // 0..N education level, or byte.MaxValue to denote unknown
};
entityManager.AddComponentData(someCitizenEntity, student);
// Serialization example (pseudo-usage; actual writer comes from game's save system)
void SaveStudent<TWriter>(ref Game.Citizens.Student s, TWriter writer) where TWriter : IWriter
{
s.Serialize(writer);
}
// Deserialization example (pseudo-usage; actual reader/context provided by game)
Game.Citizens.Student LoadStudent<TReader>(TReader reader) where TReader : IReader
{
var s = new Game.Citizens.Student();
s.Deserialize(reader);
return s;
}