generated from max/template-unity-project
max
b6f9052cff
- Worked on serialization issues (some string data doesn't get correctly formatted, but was also not needed, so removed the data part from ScenePartition) - Moved some files to runtime (wip)
38 lines
921 B
C#
38 lines
921 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace VertexColor.ScenePartition.Editor
|
|
{
|
|
[Serializable]
|
|
public class SceneGrid
|
|
{
|
|
[SerializeField]
|
|
private int cellSize = 10;
|
|
|
|
[SerializeField]
|
|
private SceneGridDictionary grid = new SceneGridDictionary();
|
|
|
|
public void Insert(uint id, Vector2 point)
|
|
{
|
|
Vector2 gridPos = CalculateGridPosition(point);
|
|
if (grid.TryGetValue(gridPos, out List<uint> ids))
|
|
{
|
|
ids.Add(id);
|
|
}
|
|
else
|
|
{
|
|
grid.Add(gridPos, new List<uint> { id });
|
|
}
|
|
}
|
|
|
|
public Vector2 CalculateGridPosition(Vector2 point)
|
|
{
|
|
int x = Mathf.FloorToInt(point.x / cellSize);
|
|
int y = Mathf.FloorToInt(point.y / cellSize);
|
|
|
|
return new Vector2(x, y);
|
|
}
|
|
}
|
|
}
|