Game.Companies.Employee
Assembly: Game
Namespace: Game.Companies
Type: struct
Base: IBufferElementData, ISerializable
Summary:
Represents an employee entry stored in a dynamic buffer on an entity (for example, a company entity). Contains a reference to the worker entity and a single byte level value. Implements Colossal.Serialization.Entities.ISerializable so instances are saved/loaded by the game's serialization system.
Fields
-
public Unity.Entities.Entity m_Worker
Reference to the worker entity (Unity.Entities.Entity). This is the entity that performs the job for the company. It is serialized first by the Serialize method and restored by Deserialize. -
public byte m_Level
A one-byte value representing the employee's level (e.g., skill or rank). Defaults to 0 for a default-constructed Employee. Serialized after m_Worker.
Properties
- This type exposes no C# properties; it uses public fields (m_Worker and m_Level) instead.
Constructors
public Employee()
No explicit constructor is defined in the source; the struct has the implicit default constructor. Default-initialized values are m_Worker = default(Entity) and m_Level = 0. Use object-initializer syntax to set fields when creating a new instance.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes this instance to the provided writer. The implementation writes the m_Worker entity first, then the m_Level byte. The order and types must match the Deserialize implementation so serialized data can be read back correctly by the game's save/load system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads this instance from the provided reader. The method reads into the fields in the same order they were written by Serialize: first m_Worker, then m_Level. This method is used by the Colossal.Serialization infrastructure during load operations.
Usage Example
// Add an Employee to a company's dynamic buffer
Entity companyEntity = /* existing company entity */;
Entity workerEntity = /* existing worker entity */;
var employee = new Game.Companies.Employee
{
m_Worker = workerEntity,
m_Level = 2
};
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var buffer = entityManager.AddBuffer<Game.Companies.Employee>(companyEntity);
buffer.Add(employee);
// Iterate employees
foreach (var emp in buffer)
{
Entity worker = emp.m_Worker;
byte level = emp.m_Level;
// use worker and level...
}
// Note: Serialization is handled by the game's Colossal.Serialization system.
// The following demonstrates how the instance methods are defined and could be called
// by a serializer (writer/reader come from the engine's serialization system):
// Serialize (pseudo-code; actual writer is provided by the engine)
TWriter writer = /* provided by engine */;
employee.Serialize(writer);
// Deserialize (pseudo-code)
Game.Companies.Employee loaded = default;
TReader reader = /* provided by engine */;
loaded.Deserialize(reader);