37 lines
713 B
C#
37 lines
713 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using Voile.Extensions;
|
|
|
|
namespace Voile;
|
|
|
|
public class GridSet<T>
|
|
{
|
|
public float GridSize { get; }
|
|
public GridSet(float gridSize = 32.0f)
|
|
{
|
|
GridSize = gridSize;
|
|
}
|
|
|
|
public void Add(Vector2 position, T child)
|
|
{
|
|
var snap = Vector2.One * GridSize;
|
|
position = position.Snapped(snap);
|
|
|
|
if (_values.TryGetValue(position, out var list))
|
|
{
|
|
list.Add(child);
|
|
}
|
|
else
|
|
{
|
|
_values.Add(position, new List<T>());
|
|
}
|
|
}
|
|
|
|
public void Remove(T child)
|
|
{
|
|
|
|
}
|
|
|
|
private Dictionary<Vector2, List<T>> _values = new();
|
|
} |