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
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
Methods
This type declares no instance or static methods. It is a plain data container intended for use in DynamicBuffer
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