Skip to content

Game.Areas.Expand

Assembly: Game
Namespace: Game.Areas

Type: struct

Base: IBufferElementData, IEmptySerializable

Summary: Expand is a small value type used as a dynamic buffer element in the Unity ECS (DOTS) world of Cities: Skylines 2 modding. It holds a 2D offset (float2) and is annotated with InternalBufferCapacity(4) to hint the entity archetype to reserve space for up to 4 elements inline. The IBufferElementData interface makes it usable via DynamicBuffer, and IEmptySerializable (from Colossal.Serialization.Entities) marks it for the game's serialization expectations.


Fields

  • public Unity.Mathematics.float2 m_Offset This field stores the 2D offset (x,y) for this Expand element. Typically used to represent local expansion offsets (for example, offsets of tiles or regions) relative to some origin.

Additional notes: - float2 is from Unity.Mathematics and stores two single-precision floats. - The field is public and plain POD, making the struct cheap to copy and suitable as a buffer element.

  • Attribute: [InternalBufferCapacity(4)]
    Although not a "field", this attribute applied to the struct instructs the ECS to reserve space for up to 4 elements of this buffer inline in the entity (avoiding heap allocations for small buffers). Adjusting this value affects memory layout/efficiency.

Properties

This type declares no properties. It exposes its data via the public field m_Offset.

Constructors

  • public Expand(Unity.Mathematics.float2 offset)
    Constructs a new Expand instance and assigns the provided float2 to m_Offset.

Usage details: - Use this constructor when adding new elements to a DynamicBuffer or creating temporary values to manipulate buffer contents.

Methods

This type declares no instance or static methods. It is a plain data container intended for use in DynamicBuffer operations.

Usage Example

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

// Example: create an entity with a DynamicBuffer<Expand> and add elements
public class ExpandBufferExampleSystem : SystemBase
{
    protected override void OnCreate()
    {
        base.OnCreate();
        // Create an entity archetype that contains a DynamicBuffer<Expand>
        var archetype = EntityManager.CreateArchetype(typeof(Expand));
        var entity = EntityManager.CreateEntity(archetype);

        // Get the dynamic buffer and add Expand elements
        var buffer = EntityManager.AddBuffer<Expand>(entity);
        buffer.Add(new Expand(new float2( 1f,  0f)));
        buffer.Add(new Expand(new float2(-1f,  0f)));
        buffer.Add(new Expand(new float2( 0f,  1f)));
        buffer.Add(new Expand(new float2( 0f, -1f)));
    }

    protected override void OnUpdate()
    {
        // Example of iterating over entities that have the Expand buffer
        Entities
            .WithName("ProcessExpands")
            .ForEach((in DynamicBuffer<Expand> expands) =>
            {
                for (int i = 0; i < expands.Length; i++)
                {
                    float2 offset = expands[i].m_Offset;
                    // Process offset...
                }
            }).Run();
    }
}

Additional guidance: - Because Expand implements IBufferElementData, access it via DynamicBuffer. - The InternalBufferCapacity(4) attribute optimizes small buffers; if you expect larger lists, the buffer will still grow but may allocate additional memory. - The IEmptySerializable marker is part of Colossal's serialization system—keep it if the game expects this for save/load compatibility.