Skip to content

Game.Prefabs.RouteData

Assembly:
Game (game assemblies providing ECS prefabs and route systems)

Namespace:
Game.Prefabs

Type:
struct

Base:
Implements: Unity.Entities.IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
RouteData is an ECS component/parameter struct used by the game's prefab & routing systems to describe default route-related archetypes and geometry parameters. It stores archetypes for route entities and their parts (waypoints, connected nodes, segments), plus visual and geometric defaults such as route type, color, width, segment length and a snap distance. The struct implements a minimal custom binary serialization (ISerializable) used by the Colossal serialization system to persist selected fields (route type, width, segment length). During deserialization it also sets sensible defaults for color and snap distance (snap distance defaults to width).


Fields

  • public Unity.Entities.EntityArchetype m_RouteArchetype
    Holds an ECS EntityArchetype used as the archetype for route root entities (the top-level route prefab entity). Used when creating route entities from prefabs or spawning routes via code.

  • public Unity.Entities.EntityArchetype m_WaypointArchetype
    Archetype for the waypoint entities that represent intermediate points on a route.

  • public Unity.Entities.EntityArchetype m_ConnectedArchetype
    Archetype for connected/attachment entities, typically used for nodes or endpoints that connect routes to other systems.

  • public Unity.Entities.EntityArchetype m_SegmentArchetype
    Archetype for route segment entities (the pieces between waypoints).

  • public float m_SnapDistance
    Distance used for snapping route points to other geometry/inputs. Note: during deserialization this is set to the width by default.

  • public RouteType m_Type
    Enumeration describing the route type (e.g., bus, tram, etc.). Serialized as an sbyte when writing.

  • public Color32 m_Color
    Default color for the route. If not serialized/deserialized explicitly, Deserialize sets this to a default mid-gray (128,128,128,255).

  • public float m_Width
    Visual/physical width of the route. This value is serialized and restored on deserialization and is also used to initialize m_SnapDistance during deserialization.

  • public float m_SegmentLength
    Preferred length for each route segment. This value is serialized and restored on deserialization.

Properties

  • None.
    This struct exposes only public fields; it has no C# properties.

Constructors

  • public RouteData()
    Default value-type constructor (struct). All fields will be default-initialized (archetypes = default, numeric fields = 0, m_Color = (0,0,0,0)). Important: the Deserialize method will overwrite some fields (m_Type, m_Width, m_SegmentLength) and will set m_Color to a sensible default and m_SnapDistance to m_Width after reading data from a serialized stream.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes a compact representation of the route data. Specifically, it writes:
  • m_Type as an sbyte,
  • m_Width as a float,
  • m_SegmentLength as a float. Only a subset of fields are serialized (type, width, segment length) — archetypes, color and snap distance are not written.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the serialized values in the same order written by Serialize:

  • reads an sbyte -> m_Type,
  • reads m_Width (float),
  • reads m_SegmentLength (float). After reading, Deserialize sets:
  • m_Color to a default Color32(128,128,128,255),
  • m_SnapDistance to the read m_Width. This ensures sensible defaults when archetype or color data are not present in the serialized data.

Usage Example

// Example: create and assign a RouteData component to a prefab entity via ECS
using Unity.Entities;
using UnityEngine;
using Game.Prefabs;
using Game.Routes;

void SetupRoutePrefab(EntityManager entityManager)
{
    // Create a RouteData and configure basic defaults
    var routeData = new RouteData
    {
        m_Type = RouteType.Bus,
        m_Width = 4f,
        m_SegmentLength = 8f,
        m_Color = new Color32(200, 100, 50, 255),
        m_SnapDistance = 4f
        // Archetypes should be created/assigned based on actual component layout:
        // m_RouteArchetype = entityManager.CreateArchetype(...);
    };

    // Create a prefab entity (example — actual archetype depends on game internals)
    Entity prefab = entityManager.CreateEntity(); // create a new entity
    entityManager.AddComponentData(prefab, routeData); // attach RouteData component
}

Notes: - RouteData is primarily used by the game's prefab and route systems; when manipulating or creating route prefabs, ensure the supporting archetypes (m_RouteArchetype, m_WaypointArchetype, etc.) are correctly created via EntityManager.CreateArchetype with the components required by your route implementation. - The custom serialization only persists a subset of fields. If you need to preserve color or archetype references across serialization, you must extend the serialization logic or handle those values externally.