Game.Prefabs.TrackData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents per-prefab track metadata used by the game (e.g., rail/track type and speed limit). This struct is a Unity ECS component (IComponentData) that can be queried (IQueryTypeParameter) and supports custom binary serialization (ISerializable) for network/save operations. The serialized form writes the track type as a single byte followed by the speed limit as a float.
Fields
-
public TrackTypes m_TrackType
Specifies the kind of track (enum). Stored as a byte during serialization. Default value is the enum's default (usually 0) if not explicitly set. -
public float m_SpeedLimit
The speed limit associated with this track, represented as a float. Serialized immediately after the track type. Default 0.0f if not set.
Properties
- None. This struct exposes only public fields; there are no properties.
Constructors
public TrackData()
Implicit default struct constructor. Initializes m_TrackType to the enum default and m_SpeedLimit to 0.0f. No custom constructors are defined in the source.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to a writer in the following order:- Writes the track type cast to a byte.
-
Writes the speed limit float. This deterministic ordering must be matched by Deserialize to ensure compatibility.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from a reader in the corresponding order: - Reads a byte value and assigns it (cast) to m_TrackType.
- Reads a float and assigns it to m_SpeedLimit. The method uses a temporary byte for the track type read, and reads the float by reference into m_SpeedLimit.
Usage Example
// Create and initialize a TrackData instance and add it as a component to an entity.
var trackData = new TrackData
{
m_TrackType = TrackTypes.Rail, // example enum value
m_SpeedLimit = 80f // speed limit (units depend on game conventions)
};
entityManager.AddComponentData(someEntity, trackData);
// Example pseudo-serialization (IWriter/IReader implementations are game-specific):
using (var writer = new SomeConcreteWriter(stream))
{
trackData.Serialize(writer);
}
// Example pseudo-deserialization:
var readData = new TrackData();
using (var reader = new SomeConcreteReader(stream))
{
readData.Deserialize(reader);
}
Notes: - The binary layout is compact: 1 byte for TrackTypes + 4 bytes for float (speed limit). - Ensure that any custom IWriter/IReader used matches the expected types and endianness used by the game. - Because this is a struct and an IComponentData, it is intended to be used with Unity's ECS (EntityManager, archetypes, queries).