Skip to content

Game.Areas.Node

Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Areas

Type: struct

Base: IBufferElementData, IStrideSerializable, ISerializable

Summary:
Represents a single node used by area data in the game ECS. Each Node stores a 3D position (Unity.Mathematics.float3) and a single float elevation. The struct is annotated with [InternalBufferCapacity(4)] so it is intended to be stored in a DynamicBuffer on entities. Implements IStrideSerializable/ISerializable for Colossal serialization with version-aware deserialization (elevation was added in a later version).


Fields

  • public Unity.Mathematics.float3 m_Position
    Holds the local/world position of the node as a float3 (x, y, z). Stored first in the serialized layout.

  • public float m_Elevation
    Elevation value for the node (single-precision float). Note: deserialization only reads this field when the reader context version is at or above Version.laneElevation to maintain backward compatibility.

Properties

  • This type does not define any C# properties. It exposes two public fields (m_Position, m_Elevation).

Constructors

  • public Node(float3 position, float elevation)
    Creates a Node instance with the given position and elevation.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the node to the provided writer in the following order: position (float3), then elevation (float). Used by the game's serialization framework.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the node from the provided reader. Always reads m_Position. Reads m_Elevation only if reader.context.version >= Version.laneElevation, enabling compatibility with older saved data that does not include elevation.

  • public int GetStride(Context context)
    Returns the byte stride used for this element when serialized/packed: UnsafeUtility.SizeOf() + 4. On typical platforms this is 12 (float3) + 4 = 16 bytes.

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Game.Areas;

// Create an entity and attach a DynamicBuffer<Node>
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
DynamicBuffer<Node> buffer = em.AddBuffer<Node>(e);

// Add nodes
buffer.Add(new Node(new float3(0f, 0f, 0f), 0f));
buffer.Add(new Node(new float3(10f, 0f, 5f), 1.2f));

// Get stride (typically 16)
Node sample = buffer[0];
int stride = sample.GetStride(default); // supply appropriate Context if needed

// Serialization example (pseudo-code, depends on available writer implementation)
// var writer = ...; // implementation of IWriter
// foreach (var node in buffer) node.Serialize(writer);

Notes: - The [InternalBufferCapacity(4)] attribute indicates a small default internal capacity for DynamicBuffer allocations (optimizes common cases with few nodes). - The struct is intended for use with Unity DOTS ECS as a buffer element (IBufferElementData). - The Deserialize logic is version-aware: older serialized data that predates Version.laneElevation will not contain the elevation value and the code guards against reading it.