Files
riversong-code-showcase/Source/Riversong/Game/World/EntityIdMap/EntityIdMap.cs
2026-05-21 16:04:49 +02:00

47 lines
1.1 KiB
C#

using System;
using Unity.Collections;
using Unity.Mathematics;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class EntityIdMap : IDisposable
{
private NativeGrid<EntityIdMapValue> _data;
public EntityIdMap(int2 size)
{
_data = new NativeGrid<EntityIdMapValue>(size, Allocator.Persistent);
}
public void Dispose()
{
_data?.Dispose();
_data = null;
}
public void SetBuildingId(TileRect rect, int id)
{
foreach (var tile in TileRange.From(rect))
{
ref var value = ref _data.GetValueRW(tile);
value.BuildingId = id;
}
}
public void SetResourceNodeId(int2 tile, int id)
{
ref var value = ref _data.GetValueRW(tile);
value.ResourceNodeId = id;
}
public ref EntityIdMapValue GetValueRW(int2 tile)
{
return ref _data.GetValueRW(tile);
}
public NativeArray<EntityIdMapValue> GetNativeArray()
{
return _data.GetNativeArray();
}
}
}