Skip to content

Game.Prefabs.NavigationAreaData

Assembly: Assembly-CSharp (in-game)
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents navigation area metadata used by the game's routing/navigation systems. Holds primary and secondary route connection types and bitflags for allowed track and road types. Implements Unity's ECS IComponentData so it can be attached to entities, IQueryTypeParameter for query usage, and a simple binary ISerializable implementation used for save/network serialization. The serialized form writes each enum as a single byte in a fixed order.


Fields

  • public RouteConnectionType m_ConnectionType
    Primary route connection type used by this navigation area (stored as a byte during serialization).

  • public RouteConnectionType m_SecondaryType
    Secondary route connection type; often used as an alternate or fallback connection classification (stored as a byte during serialization).

  • public TrackTypes m_TrackTypes
    Bitflag enum indicating which track types are allowed in this navigation area (serialized as a byte). Typically used to restrict rail/track-based vehicles.

  • public RoadTypes m_RoadTypes
    Bitflag enum indicating which road types are allowed in this navigation area (serialized as a byte). Used to restrict road vehicle movement.

Properties

  • This type declares no properties.

Constructors

  • public NavigationAreaData()
    No explicit constructor is declared in the source; the struct has the implicit default constructor which initializes enum fields to their default values (usually the 0-value for each enum). To create a custom instance, initialize the fields directly when constructing.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component to a binary writer in a fixed order: m_ConnectionType, m_SecondaryType, m_TrackTypes, m_RoadTypes. Each enum/value is cast to byte and written as a single byte. This compact format is used for saves and network messages — important to keep the same order and sizes for compatibility.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads four bytes in the same order they were written and casts them back to the respective enum fields: m_ConnectionType, m_SecondaryType, m_TrackTypes, m_RoadTypes. The method expects the data layout to match the Serialize implementation exactly.

Usage Example

// Create an entity and attach NavigationAreaData (using Unity.Entities API)
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity();

// Initialize with specific route/track/road types
var navData = new Game.Prefabs.NavigationAreaData
{
    m_ConnectionType = RouteConnectionType.Road,        // example enum value
    m_SecondaryType = RouteConnectionType.None,        // example enum value
    m_TrackTypes = TrackTypes.None,                    // example bitflags
    m_RoadTypes = RoadTypes.Car | RoadTypes.Bus        // example bitflags (if applicable)
};

em.AddComponentData(entity, navData);

// Example: serializing the struct to a writer (pseudo-code; use engine writer)
TWriter writer = /* obtain a writer implementing IWriter */;
navData.Serialize(writer);

// Later: deserializing back
TReader reader = /* obtain a reader implementing IReader */;
Game.Prefabs.NavigationAreaData loaded;
loaded.Deserialize(reader);

Additional notes: - Keep enum definitions (RouteConnectionType, TrackTypes, RoadTypes) consistent with expected byte values; adding new enum values >255 or changing ordering will break serialization compatibility. - Because the component implements IComponentData, it is intended for use with Unity DOTS/ECS. Use EntityManager or systems to create/query entities with this component.