Skip to content

Game.Prefabs.NetPieceArea

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: public struct

Base: IBufferElementData, IComparable

Summary:
Represents a single area/segment used by net (network) pieces (roads/rails/etc.) for placement and snapping logic. This struct is a buffer element (InternalBufferCapacity(0)) intended to be stored in a DynamicBuffer on an Entity. It contains positional, width and snapping information and implements IComparable to allow sorting by the X coordinate of m_Position.


Fields

  • public NetAreaFlags m_Flags
    Flags describing properties of the area (likely an enum used by the game's network placement system). Used to convey state/attributes for this area (e.g., whether it's available for placement, if it's a junction, etc.).

  • public float3 m_Position
    World/local position of the area. The CompareTo implementation sorts by the X component of this vector.

  • public float m_Width
    Width of the area (in world units) used for placement/overlap calculations.

  • public float3 m_SnapPosition
    Position used for snapping mechanics (where pieces should snap to). Often differs from m_Position if there is a dedicated snap point.

  • public float m_SnapWidth
    Width used for snap testing (may be different than m_Width to adjust snapping tolerance).

Properties

  • None (no automatic or explicit properties defined in this type).

Constructors

  • public NetPieceArea() (implicit default)
    As a value type (struct) there is an implicit parameterless constructor that initializes numeric fields to zero and enums to their default value. Typical usage constructs instances with object initializers to set meaningful values.

Methods

  • public int CompareTo(NetPieceArea other)
    Compares this instance with another NetPieceArea by the X component of m_Position. Implementation logic:
  • Returns 0 if m_Position.x == other.m_Position.x.
  • Returns 1 if m_Position.x > other.m_Position.x.
  • Returns -1 if m_Position.x < other.m_Position.x.

Implementation note: it uses Unity.Mathematics.math.select to compute the result. Comparison uses direct floating-point equality/inequality on the X components (no epsilon), so small floating-point differences may affect ordering.

Usage Example

// Example: creating and sorting a list of NetPieceArea by X position
using System.Collections.Generic;
using Unity.Mathematics;
using Game.Prefabs;

var areas = new List<NetPieceArea>
{
    new NetPieceArea { m_Position = new float3(10f, 0f, 0f), m_Width = 2f, m_SnapPosition = new float3(10f,0f,0f), m_SnapWidth = 1f },
    new NetPieceArea { m_Position = new float3(2f, 0f, 0f),  m_Width = 2f, m_SnapPosition = new float3(2f,0f,0f),  m_SnapWidth = 1f },
    new NetPieceArea { m_Position = new float3(5f, 0f, 0f),  m_Width = 2f, m_SnapPosition = new float3(5f,0f,0f),  m_SnapWidth = 1f }
};

areas.Sort(); // Uses CompareTo to sort by m_Position.x in ascending order

// Example: storing areas in an Entity's DynamicBuffer (ECS)
using Unity.Entities;

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = em.CreateEntity();
em.AddBuffer<NetPieceArea>(e);
var buffer = em.GetBuffer<NetPieceArea>(e);

buffer.Add(new NetPieceArea
{
    m_Position = new float3(0f, 0f, 0f),
    m_Width = 3f,
    m_SnapPosition = new float3(0f, 0f, 0f),
    m_SnapWidth = 1.5f,
    m_Flags = default // set appropriate NetAreaFlags value
});

Additional notes: - The attribute [InternalBufferCapacity(0)] indicates the entity archetype will not reserve inline capacity for this buffer; it will use an external buffer allocation initially. - Because CompareTo only considers m_Position.x, if sorting should consider Y or Z or other tie-breakers, you may want to supply a custom comparer or extend the struct's CompareTo logic. - Be mindful of floating-point equality when relying on exact comparisons of m_Position.x; consider using tolerances if appropriate.