Skip to content

Game.TrainBogiePosition

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: struct

Base: Colossal.Serialization.Entities.ISerializable

Summary:
Represents the position and forward direction of a train bogie (wheel bogie). The struct is a simple, blittable container of two Unity.Mathematics.float3 values (position and direction) and implements Colossal's ISerializable so it can be written to and read from the game's serialization streams (save/load, network, etc.). The position and direction are taken from a Game.Objects.Transform instance — position is the transform's m_Position and direction is the forward vector derived from the transform's rotation (world-space forward).


Fields

  • public Unity.Mathematics.float3 m_Position
    Holds the world-space position of the bogie.

  • public Unity.Mathematics.float3 m_Direction
    Holds the world-space forward direction of the bogie (computed with math.forward on the transform rotation).

Properties

  • (none)

Constructors

  • public TrainBogiePosition(Game.Objects.Transform transform)
    Initializes a TrainBogiePosition from a Game.Objects.Transform. Sets m_Position = transform.m_Position and m_Direction = math.forward(transform.m_Rotation).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
    Writes the struct to a writer. The implementation writes m_Position first, then m_Direction, using the writer.Write(...) overloads for float3.

  • public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
    Reads the struct from a reader. The implementation reads into m_Position and then m_Direction (reads by reference into the existing fields).

Usage Example

// Create from an existing transform
Game.Objects.Transform t = /* obtain transform */;
var bogiePos = new Game.Vehicles.TrainBogiePosition(t);

// Serialize using a writer (TWriter must implement IWriter)
void SaveBogie<TWriter>(TWriter writer, in Game.Vehicles.TrainBogiePosition bp) where TWriter : Colossal.Serialization.Entities.IWriter
{
    bp.Serialize(writer);
}

// Deserialize using a reader (TReader must implement IReader)
Game.Vehicles.TrainBogiePosition LoadBogie<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{
    var bp = new Game.Vehicles.TrainBogiePosition();
    bp.Deserialize(reader);
    return bp;
}

Notes: - Uses Unity.Mathematics.float3 for compact, high-performance math types suitable for jobified code. - The order of write/read is important: position first, then direction — keep that consistent when writing custom serialization logic. - The struct is lightweight and intended to be used in arrays or containers representing bogie state for trains.