Skip to content

Game.MapFeatureData

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
struct

Base:
Unity.Entities.IBufferElementData

Summary:
A lightweight IBufferElementData used to store per-element cost information for a map feature in ECS dynamic buffers. The struct is annotated with [InternalBufferCapacity(9)], which hints to the Entities runtime to store up to 9 elements inline in the chunk before allocating additional memory. Typical use is attaching a DynamicBuffer to an Entity to hold variable-length lists of feature costs.


Fields

  • public float m_Cost
    Holds the cost value for a single map feature entry. Stored as a single-precision floating point number. This field is set via the constructor or by assigning to the buffer element directly.

  • [InternalBufferCapacity(9)] (attribute applied to the struct)
    Specifies the internal inline capacity for the dynamic buffer: the first 9 elements are stored in-chunk (avoiding separate heap allocations). If more than 9 elements are added, additional memory will be allocated.

Properties

  • This struct defines no properties. It exposes a single public field instead.

Constructors

  • public MapFeatureData(float cost)
    Initializes a new MapFeatureData instance and sets m_Cost to the provided value.

Methods

  • This struct defines no methods. It is a plain data container meant for use in DynamicBuffer.

Usage Example

// Example: add and use a DynamicBuffer<MapFeatureData> on an entity
using Unity.Entities;
using Game.Prefabs;

public partial class MapFeatureSystem : SystemBase
{
    protected override void OnCreate()
    {
        base.OnCreate();
    }

    protected override void OnUpdate()
    {
        var em = World.DefaultGameObjectInjectionWorld.EntityManager;

        // Create an entity and attach a buffer (in real code, use an archetype or authoring)
        var entity = em.CreateEntity();
        em.AddBuffer<MapFeatureData>(entity);

        // Get the dynamic buffer and add entries
        var buffer = em.GetBuffer<MapFeatureData>(entity);
        buffer.Add(new MapFeatureData(12.5f));
        buffer.Add(new MapFeatureData(7.0f));

        // Iterate the buffer
        for (int i = 0; i < buffer.Length; i++)
        {
            float cost = buffer[i].m_Cost;
            // use cost...
        }
    }
}