Game.Serialization.StudentSystem
Assembly:
Assembly-CSharp
Namespace:
Game.Serialization
Type:
class StudentSystem
Base:
GameSystemBase
Summary:
StudentSystem is an ECS system that collects Citizen Student components and appends references to those student entities into building buffers representing schools. It queries for entities with Game.Citizens.Student, then schedules a chunk job (StudentJob) that iterates over those students and, if their school buffer exists, adds a Game.Buildings.Student element containing the student Entity to the school's dynamic buffer. The system uses a TypeHandle helper to cache Entity/Component/Buffer handles for efficient access and to cooperate with the compiler-generated job scheduling pattern.
Fields
-
private EntityQuery m_StudentQuery
Holds the EntityQuery used to find all entities with the Game.Citizens.Student component. This query is created in OnCreate and is used to schedule the StudentJob. -
private TypeHandle __TypeHandle
A compiler-generated helper struct instance used to store and assign type handles (EntityTypeHandle, ComponentTypeHandle, and BufferLookup ) required by the job. __TypeHandle.__AssignHandles is called to populate these handles from the SystemState. -
private struct StudentJob
(nested)
Nested IJobChunk implementation that does the work for each chunk. It has read-only handles for entities and students and a BufferLookup for building student buffers. Its Execute method iterates chunk elements and, for each student, checks for the school's buffer and adds a Game.Buildings.Student entry linking the student Entity. -
private struct TypeHandle
(nested)
Nested helper struct that stores the type handles and exposes __AssignHandles(ref SystemState) to populate them via the SystemState (GetEntityTypeHandle, GetComponentTypeHandle, GetBufferLookup).
Properties
- None (this system does not expose public properties)
Constructors
public StudentSystem()
[Preserve] default constructor. The attribute indicates the constructor should be kept by code stripping / IL2CPP tooling. Standard compiler-generated constructor; no custom initialization logic beyond base constructor.
Methods
-
protected override void OnCreate()
Initializes the system. Creates m_StudentQuery with ComponentType.ReadOnly() and calls RequireForUpdate(m_StudentQuery) so the system is only updated when matching entities exist. -
protected override void OnUpdate()
Builds a StudentJob instance by retrieving the cached type handles via InternalCompilerInterface (converting the stored __TypeHandle handles into runtime handles via base.CheckedStateRef), then schedules the job with JobChunkExtensions.Schedule over m_StudentQuery and the system's base.Dependency. -
protected override void OnCreateForCompiler()
Compiler helper called to prepare queries and assign handles during compilation-time codegen. It calls __AssignQueries and __TypeHandle.__AssignHandles to ensure type handles and query setups are prepared for the compiled system. -
private void __AssignQueries(ref SystemState state)
Compiler-generated method that constructs any EntityQueryBuilder calls required at compile time. In this implementation it creates and disposes an EntityQueryBuilder(Allocator.Temp) — effectively a placeholder used by codegen. -
private void TypeHandle.__AssignHandles(ref SystemState state)
(Inner method on the nested TypeHandle struct) Populates the cached handles: - __Unity_Entities_Entity_TypeHandle = state.GetEntityTypeHandle();
- __Game_Citizens_Student_RO_ComponentTypeHandle = state.GetComponentTypeHandle
(isReadOnly: true); -
__Game_Buildings_Student_RW_BufferLookup = state.GetBufferLookup
(); -
private struct StudentJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
(Inner job method) For each chunk it: - Retrieves a NativeArray
and NativeArray . - Iterates elements: for each student entity, checks if m_Students.HasBuffer(student.m_School).
- If the buffer exists, appends a new Game.Buildings.Student record with m_Student set to the student entity.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Create a query for all entities with the Student component and require it for updates
m_StudentQuery = GetEntityQuery(ComponentType.ReadOnly<Game.Citizens.Student>());
RequireForUpdate(m_StudentQuery);
}