Game.Routes.RouteModifier
Assembly: Assembly-CSharp (typical game assembly)
Namespace: Game.Routes
Type: struct
Base: Implements Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.ISerializable
Attributes: [InternalBufferCapacity(0)]
Summary:
RouteModifier is a small ECS buffer element that stores a 2D delta (float2) used to modify route data. It is serializable via the game's Colossal.Serialization system and contains version-aware deserialization logic to remain compatible with older saved data formats (prior to Version.modifierRefactoring only the Y component was stored).
Fields
public Unity.Mathematics.float2 m_Delta
Holds the modification delta as a float2 (x, y). Written in full during serialization. During deserialization the code checks the saved data version and will read both components for newer versions; for older versions it only reads the Y component to preserve backward compatibility.
Properties
- (none)
This struct exposes no properties; it only contains the public m_Delta field.
Constructors
public RouteModifier()
(implicit default)
No explicit constructor is declared; the default parameterless struct constructor initializes m_Delta to float2(0,0).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the full float2 m_Delta to the provided writer. Used by the Colossal.Serialization system to persist the buffer element. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from the provided reader with version-aware logic: - If reader.context.version >= Version.modifierRefactoring: reads the entire float2 into m_Delta.
- Else (older versions): reads only the Y component into m_Delta.y (m_Delta.x remains default/0). This preserves compatibility with older save formats where only the Y component was stored.
Usage Example
// Add and use RouteModifier as a dynamic buffer element on an entity
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
// Add the buffer component to the entity
em.AddBuffer<Game.Routes.RouteModifier>(e);
// Populate the buffer
var buffer = em.GetBuffer<Game.Routes.RouteModifier>(e);
buffer.Add(new Game.Routes.RouteModifier { m_Delta = new Unity.Mathematics.float2(1.5f, -0.75f) });
{{ Additional notes:
- Because RouteModifier implements IBufferElementData it is intended for use with DynamicBuffer