generated from max/template-unity-project
Work State Serialization
- 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)
This commit is contained in:
37
Runtime/SceneGrid.cs
Normal file
37
Runtime/SceneGrid.cs
Normal file
@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user