generated from max/template-unity-project
Compare commits
No commits in common. "41df190afb2a3d2d44b758532b220a4a13231be2" and "80c90d884a9a4ea2a43e3ba665daacd412d3955c" have entirely different histories.
41df190afb
...
80c90d884a
@ -1,20 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VertexColor.ScenePartition.Editor
|
||||
{
|
||||
public static class EditorGUIUtils
|
||||
{
|
||||
public static readonly Color horizontalLineColor = Color.white;
|
||||
|
||||
public static void HorizontalLine(Color color)
|
||||
{
|
||||
Color prev = GUI.color;
|
||||
GUI.color = color;
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
|
||||
GUI.color = prev;
|
||||
}
|
||||
|
||||
public static void HorizontalLine() => HorizontalLine(horizontalLineColor);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: befa2e31a4a6ae04696dcd5b72554ea4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -19,23 +19,11 @@ public static void ShowExample()
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField("Cache", EditorStyles.boldLabel);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
if (GUILayout.Button("Save"))
|
||||
{
|
||||
if (GUILayout.Button("Save", EditorStyles.miniButtonLeft))
|
||||
{
|
||||
ScenePartitionSS.Save();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear", EditorStyles.miniButtonRight))
|
||||
{
|
||||
ScenePartitionSS.Save();
|
||||
}
|
||||
ScenePartitionSS.Save();
|
||||
}
|
||||
|
||||
EditorGUIUtils.HorizontalLine();
|
||||
|
||||
DrawSceneDataCache();
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,6 @@ public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||
|
||||
scenePartitionSO.Data.SceneGrid.cellSize = EditorGUILayout.IntSlider("cellSize", scenePartitionSO.Data.SceneGrid.cellSize, 10, 1000);
|
||||
|
||||
foreach (KeyValuePair<int, GridList> item in scenePartitionSO.Data.SceneGrid.Grid)
|
||||
{
|
||||
EditorGUILayout.LongField("gridId", item.Key);
|
||||
@ -99,6 +97,12 @@ public override void OnInspectorGUI()
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("ClearCache"))
|
||||
{
|
||||
scenePartitionSO.ClearCache();
|
||||
ScenePartitionSS.instance.SceneDataCache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace VertexColor.ScenePartition.Editor
|
||||
[InitializeOnLoad]
|
||||
public class ScenePartitionSceneViewEditor : UnityEditor.Editor
|
||||
{
|
||||
private static ScenePartitionSO scenePartitionSO = null;
|
||||
private const int cellSize = 10;
|
||||
|
||||
static ScenePartitionSceneViewEditor()
|
||||
{
|
||||
@ -16,50 +16,24 @@ static ScenePartitionSceneViewEditor()
|
||||
private static void HandleDuringSceneGui(SceneView sceneView)
|
||||
{
|
||||
if (Event.current.modifiers != EventModifiers.Control) return;
|
||||
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out scenePartitionSO)) return;
|
||||
|
||||
int cellSize = scenePartitionSO.Data.SceneGrid.cellSize;
|
||||
Vector3 gridPosition = CalculateGridPosition(Event.current.mousePosition);
|
||||
int gridId = SceneGrid.CalculateGridPosition(gridPosition, cellSize);
|
||||
int gridId = SceneGrid.CalculateGridPosition(gridPosition, 10);
|
||||
|
||||
{ // Draw Cells.
|
||||
foreach (int id in scenePartitionSO.Data.SceneGrid.Grid.Keys)
|
||||
{
|
||||
(int x, int y) = SceneGrid.IntToIntPair(id);
|
||||
int x = Mathf.FloorToInt(gridPosition.x / cellSize);
|
||||
int z = Mathf.FloorToInt(gridPosition.z / cellSize);
|
||||
|
||||
Vector3 cellOrign = new Vector3(x * cellSize, 0, y * cellSize);
|
||||
Vector3[] lines = new Vector3[] {
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(0, 0, cellSize) + cellOrign, // Left Bottom -> Left Top
|
||||
new Vector3(cellSize, 0, 0) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Right Bottom -> Right Top
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(cellSize, 0, 0) + cellOrign, // Left Bottom -> Right Bottom
|
||||
new Vector3(0, 0, cellSize) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Left Top -> Right Top
|
||||
};
|
||||
Vector3 cellOrign = new Vector3(x * cellSize, 0, z * cellSize);
|
||||
Vector3[] lines = new Vector3[] {
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(0, 0, cellSize) + cellOrign, // Left Bottom -> Left Top
|
||||
new Vector3(cellSize, 0, 0) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Right Bottom -> Right Top
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(cellSize, 0, 0) + cellOrign, // Left Bottom -> Right Bottom
|
||||
new Vector3(0, 0, cellSize) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Left Top -> Right Top
|
||||
};
|
||||
|
||||
Handles.DrawLines(lines);
|
||||
}
|
||||
}
|
||||
Handles.DrawDottedLines(lines, 10.0f);
|
||||
Handles.Label(cellOrign + new Vector3(cellSize * 0.5f, 0, cellSize * 0.5f), new GUIContent($"{gridId}"));
|
||||
|
||||
if (!scenePartitionSO.Data.SceneGrid.Grid.ContainsKey(gridId)) return;
|
||||
|
||||
{ // Draw Selection.
|
||||
int x = Mathf.FloorToInt(gridPosition.x / cellSize);
|
||||
int z = Mathf.FloorToInt(gridPosition.z / cellSize);
|
||||
|
||||
Vector3 cellOrign = new Vector3(x * cellSize, 0, z * cellSize);
|
||||
Vector3[] lines = new Vector3[] {
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(0, 0, cellSize) + cellOrign, // Left Bottom -> Left Top
|
||||
new Vector3(cellSize, 0, 0) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Right Bottom -> Right Top
|
||||
new Vector3(0, 0, 0) + cellOrign, new Vector3(cellSize, 0, 0) + cellOrign, // Left Bottom -> Right Bottom
|
||||
new Vector3(0, 0, cellSize) + cellOrign, new Vector3(cellSize, 0, cellSize) + cellOrign, // Left Top -> Right Top
|
||||
};
|
||||
|
||||
Color c = Handles.color;
|
||||
Handles.color = Color.yellow;
|
||||
Handles.DrawLines(lines);
|
||||
Handles.color = c;
|
||||
}
|
||||
|
||||
// Context menu to load.
|
||||
if (Event.current.button == 1 && Event.current.type == EventType.MouseDown)
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
@ -88,11 +62,10 @@ private static Vector3 CalculateGridPosition(Vector2 mousePosition)
|
||||
|
||||
private static void Load(object gridId)
|
||||
{
|
||||
if (scenePartitionSO == null) return;
|
||||
if (gridId == null) return;
|
||||
if (gridId is not int cellId) return;
|
||||
if (gridId is not int gridPos) return;
|
||||
|
||||
|
||||
scenePartitionSO.LoadCell(cellId);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,35 +57,5 @@ private static void FindDeeplyLinkedObjectsRecursive(SortedList<ulong, ScenePart
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetScenePartitionSOForActiveScene(out ScenePartitionSO scenePartitionSO)
|
||||
{
|
||||
scenePartitionSO = null;
|
||||
|
||||
UnityEngine.SceneManagement.Scene activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||
|
||||
if (activeScene == null) return false;
|
||||
|
||||
string filter = $"t:{nameof(ScenePartitionSO)}";
|
||||
string[] assets = AssetDatabase.FindAssets(filter);
|
||||
|
||||
if (assets == null || assets.Length <= 0) return false;
|
||||
|
||||
for (int i = 0; i < assets.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(assets[i]);
|
||||
ScenePartitionSO scenePartition = AssetDatabase.LoadAssetAtPath<ScenePartitionSO>(path);
|
||||
|
||||
if (scenePartition == null) continue;
|
||||
|
||||
if (scenePartition.SceneName == activeScene.name)
|
||||
{
|
||||
scenePartitionSO = scenePartition;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace VertexColor.ScenePartition
|
||||
public class SceneGrid
|
||||
{
|
||||
[SerializeField]
|
||||
public int cellSize = 10;
|
||||
private int cellSize = 10;
|
||||
|
||||
[SerializeField]
|
||||
private SceneGridDictionary grid = new SceneGridDictionary();
|
||||
@ -81,4 +81,4 @@ public static (ulong, ulong) ULongToULongPair(ulong value)
|
||||
return (x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user