Skip to content

Game.Zones.Block

Assembly: Assembly-CSharp
Namespace: Game.Zones

Type: struct

Base: IComponentData, IQueryTypeParameter, IEquatable, ISerializable

Summary:
Block is a lightweight ECS component representing a rectangular zone block in the game's zoning system. It stores the block's world-space position, a directional vector (likely the local orientation or facing), and an integer size (width/height in grid units). The struct implements IComponentData so it can be attached to entities, ISerializable for binary (de)serialization via the game's Colossal.Serialization system, and IEquatable for value comparisons.


Fields

  • public float3 m_Position
    Holds the block's position in world space (X, Y, Z). Used as the primary identity in GetHashCode().

  • public float2 m_Direction
    A 2D direction vector representing the block orientation (typically X/Z plane). Comparison uses float2.Equals, so exact float equality is required.

  • public int2 m_Size
    Integer dimensions of the block (width, height) in grid/zone units.

Properties

  • This type defines no properties.

Constructors

  • public Block()
    No explicit constructor is defined in the source; the struct uses the default parameterless/value-type constructor. Initialize fields directly (object initializer) before use when creating new instances.

Methods

  • public bool Equals(Block other)
    Performs a value equality check. Returns true only if m_Position, m_Direction and m_Size are all equal (uses the respective Equals implementations). Note: float equality is exact here — small floating-point differences will cause inequality.

  • public override int GetHashCode()
    Returns the hash code of m_Position only (m_Position.GetHashCode()). Because only position is used for the hash code, different blocks with the same position but differing direction/size will hash the same; be cautious when using Block as a key in hash-based collections.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the fields to the provided writer in the following order: position, direction, size. Uses writer.Write for float3, float2 and int2. This is used by the game's serialization pipeline to save component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads values from the provided reader into the struct's fields in the same order they are written: position, direction, size. Uses reader.Read(out ref) to populate the fields.

Usage Example

// Creating a Block and attaching to an entity (Unity.Entities EntityManager usage)
var block = new Game.Zones.Block {
    m_Position = new Unity.Mathematics.float3(100f, 0f, 200f),
    m_Direction = new Unity.Mathematics.float2(1f, 0f), // facing +X
    m_Size = new Unity.Mathematics.int2(8, 12) // width=8, height=12
};

entityManager.AddComponentData(entity, block);

// Comparing blocks
var b1 = block;
var b2 = new Game.Zones.Block {
    m_Position = new Unity.Mathematics.float3(100f, 0f, 200f),
    m_Direction = new Unity.Mathematics.float2(1f, 0f),
    m_Size = new Unity.Mathematics.int2(8, 12)
};
bool equal = b1.Equals(b2); // true if all fields match exactly

// Serialization example (using Colossal.Serialization writers/readers)
public void SaveBlock<TWriter>(ref Game.Zones.Block block, TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
{
    block.Serialize(writer);
}

public Game.Zones.Block LoadBlock<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{
    var loaded = default(Game.Zones.Block);
    loaded.Deserialize(reader);
    return loaded;
}

Notes and caveats: - Because equality uses exact float equality, consider normalizing or quantizing the direction/position if you need tolerant comparisons. - GetHashCode uses only position; if you intend to use Block as a dictionary key and direction/size matter, provide a custom hash or wrapper that includes those fields.