Game.Creatures.Creature
Assembly: Assembly-CSharp
Namespace: Game.Creatures
Type: struct
Base: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Represents a creature component used by the game to store a queue area (as a Sphere3) and an associated entity that represents the queue. Implements runtime ECS component interfaces and a custom serialization contract so the component can be written to / read from the game's save/stream format. The serialized format is conditional: only the sphere radius is always written; if the radius is greater than 0 the queue entity and sphere position are also written.
Fields
-
public Unity.Entities.Entity m_QueueEntity
Holds the Entity that represents the creature's queue object. Only serialized/deserialized whenm_QueueArea.radius > 0f
. -
public Colossal.Mathematics.Sphere3 m_QueueArea
Defines the queue area as a Sphere3 (containsposition
of typeUnity.Mathematics.float3
and aradius
float). Theradius
is written first during serialization and is used to determine whether the rest of the data (entity + position) are present.
Properties
- (none)
This struct exposes public fields and does not declare C# properties.
Constructors
public Creature()
Default (implicit) value-type constructor. Fields are default-initialized (entity = default(Entity), m_QueueArea.position = float3(0), m_QueueArea.radius = 0f).
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to the provided writer in the following order:- Writes
m_QueueArea.radius
(float). -
If
m_QueueArea.radius > 0f
:- Writes
m_QueueEntity
(Entity). - Writes
m_QueueArea.position
(float3). Notes: The writer must match this exact layout when reading back.
- Writes
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from the provided reader using the same layout as Serialize: - Reads into
m_QueueArea.radius
. - If
m_QueueArea.radius > 0f
:- Reads into
m_QueueEntity
. - Reads into
m_QueueArea.position
. Implementation uses ref locals to write directly into the struct fields.
- Reads into
Usage Example
// Note: IWriter/IReader below are placeholders for the game's actual writer/reader types.
var creature = new Creature();
// Set a queue area with a radius > 0 to cause entity+position to be serialized
creature.m_QueueArea = new Colossal.Mathematics.Sphere3 {
position = new Unity.Mathematics.float3(10f, 0f, 5f),
radius = 2.5f
};
creature.m_QueueEntity = someQueueEntity; // an existing Unity.Entities.Entity
// Serialize
IWriter writer = /* obtain writer from save system */;
creature.Serialize(writer);
// Later / on load: Deserialize
IReader reader = /* obtain reader from save system */;
var loadedCreature = new Creature();
loadedCreature.Deserialize(reader);
Additional notes:
- Ensure writer and reader come from the same serialization version/context; order and presence of fields is strictly conditional on radius
.
- If m_QueueArea.radius
is 0, the entity and position are intentionally omitted from the serialized data to save space and indicate "no queue".
- Sphere3 is expected to contain at least position : float3
and radius : float
.