Game.Routes.Segment
Assembly:
Namespace: Game.Routes
Type: struct
Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
A lightweight ECS component that represents a route segment by storing an integer index. Designed to be attached to entities in Unity's DOTS (Entities) system for route management and query operations. Implements serialization interfaces so the segment index can be persisted and restored by the game's serialization system.
Fields
public int m_Index
Holds the integer identifier/index for this route segment. Used by route systems and queries to identify which segment an entity corresponds to. Defaults to 0 if not initialized.
Properties
- This type defines no properties.
The struct exposes the segment value directly via the public field m_Index rather than through properties.
Constructors
public Segment(int index)
Initializes a new Segment instance setting m_Index to the provided index value.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Index value to the provided writer. Used by the game's serialization pipeline to persist the component state. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an integer from the provided reader into m_Index. Used to restore the component state during load/deserialization.
Usage Example
// Create and add the component to an entity (requires a valid EntityManager)
var segmentComponent = new Game.Routes.Segment(5);
entityManager.AddComponentData(entity, segmentComponent);
// Example serialization call (pseudo-code, depends on concrete writer/reader types)
var writer = /* obtain IWriter implementation */;
segmentComponent.Serialize(writer);
// Example deserialization into a new instance (pseudo-code)
var reader = /* obtain IReader implementation */;
var loadedSegment = new Game.Routes.Segment();
loadedSegment.Deserialize(reader);
// loadedSegment.m_Index now contains the persisted index