generated from max/template-unity-project
Editor layout
- Cleanup the editors a bit - Editor foldout scope - Cell size to editor (this is user preference data, could be put in EditorPrefs later)
This commit is contained in:
parent
ddf71ef7d7
commit
8b44c33813
@ -16,5 +16,18 @@ public static void HorizontalLine(Color color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void HorizontalLine() => HorizontalLine(horizontalLineColor);
|
public static void HorizontalLine() => HorizontalLine(horizontalLineColor);
|
||||||
|
|
||||||
|
public class FoldoutHeaderScope : System.IDisposable
|
||||||
|
{
|
||||||
|
public FoldoutHeaderScope(string label, ref bool foldout)
|
||||||
|
{
|
||||||
|
foldout = EditorGUILayout.BeginFoldoutHeaderGroup(foldout, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,8 +9,9 @@ public class ScenePartitionEditorWindow : EditorWindow
|
|||||||
private const int cellSize = 10;
|
private const int cellSize = 10;
|
||||||
|
|
||||||
private Vector2 scrollPos = Vector2.zero;
|
private Vector2 scrollPos = Vector2.zero;
|
||||||
|
private bool foldoutGroupEnabled = false;
|
||||||
|
|
||||||
[MenuItem("Max/ScenePartitionWindow")]
|
[MenuItem("Window/ScenePartition")]
|
||||||
public static void ShowExample()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
ScenePartitionEditorWindow window = GetWindow<ScenePartitionEditorWindow>();
|
ScenePartitionEditorWindow window = GetWindow<ScenePartitionEditorWindow>();
|
||||||
@ -41,6 +42,10 @@ private void OnGUI()
|
|||||||
|
|
||||||
private void DrawSceneDataCache()
|
private void DrawSceneDataCache()
|
||||||
{
|
{
|
||||||
|
using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("SceneDataCache", ref foldoutGroupEnabled))
|
||||||
|
{
|
||||||
|
if (!foldoutGroupEnabled) return;
|
||||||
|
|
||||||
using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos))
|
using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos))
|
||||||
{
|
{
|
||||||
scrollPos = scope.scrollPosition;
|
scrollPos = scope.scrollPosition;
|
||||||
@ -100,4 +105,5 @@ private void DrawSceneDataCache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -281,11 +281,11 @@ public void GenerateSceneGridData()
|
|||||||
|
|
||||||
if (ids[i].targetPrefabId == 0) // 0 = no prefab.
|
if (ids[i].targetPrefabId == 0) // 0 = no prefab.
|
||||||
{
|
{
|
||||||
Data.SceneGrid.Insert(ids[i].targetObjectId, rootGameObjects[i].transform.position);
|
Data.SceneGrid.Insert(ids[i].targetObjectId, rootGameObjects[i].transform.position, ScenePartitionSceneViewEditor.cellSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Data.SceneGrid.Insert(ids[i].targetPrefabId, rootGameObjects[i].transform.position);
|
Data.SceneGrid.Insert(ids[i].targetPrefabId, rootGameObjects[i].transform.position, ScenePartitionSceneViewEditor.cellSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ public class ScenePartitionSOEditor : UnityEditor.Editor
|
|||||||
{
|
{
|
||||||
private ulong id = 0;
|
private ulong id = 0;
|
||||||
private int gridId = 0;
|
private int gridId = 0;
|
||||||
|
private bool foldoutGroupEnabled = false;
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
@ -20,7 +21,7 @@ public override void OnInspectorGUI()
|
|||||||
//EditorGUILayout.PropertyField(sceneAssetProperty);
|
//EditorGUILayout.PropertyField(sceneAssetProperty);
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUIUtils.HorizontalLine();
|
||||||
|
|
||||||
if (scenePartitionSO.SceneAsset == null)
|
if (scenePartitionSO.SceneAsset == null)
|
||||||
{
|
{
|
||||||
@ -31,47 +32,62 @@ public override void OnInspectorGUI()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (GUILayout.Button("Load All"))
|
|
||||||
{
|
|
||||||
scenePartitionSO.LoadAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button("Reload"))
|
|
||||||
{
|
|
||||||
scenePartitionSO.Reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button("Save"))
|
|
||||||
{
|
|
||||||
scenePartitionSO.Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GUILayout.Button("Unload"))
|
|
||||||
{
|
|
||||||
scenePartitionSO.Unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
|
||||||
|
|
||||||
if (GUILayout.Button("Open Scene Data Folder"))
|
if (GUILayout.Button("Open Scene Data Folder"))
|
||||||
{
|
{
|
||||||
EditorUtility.RevealInFinder(ScenePartitionUtils.GetDataPath(scenePartitionSO));
|
EditorUtility.RevealInFinder(ScenePartitionUtils.GetDataPath(scenePartitionSO));
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUIUtils.HorizontalLine();
|
||||||
|
|
||||||
|
using (new EditorGUILayout.HorizontalScope())
|
||||||
|
{
|
||||||
|
if (GUILayout.Button("Load All", EditorStyles.miniButtonLeft))
|
||||||
|
{
|
||||||
|
scenePartitionSO.LoadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Unload", EditorStyles.miniButtonRight))
|
||||||
|
{
|
||||||
|
scenePartitionSO.Unload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (new EditorGUILayout.HorizontalScope())
|
||||||
|
{
|
||||||
|
if (GUILayout.Button("Save", EditorStyles.miniButtonLeft))
|
||||||
|
{
|
||||||
|
scenePartitionSO.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button(new GUIContent("Reload", "Discard changes and reload"), EditorStyles.miniButtonRight))
|
||||||
|
{
|
||||||
|
scenePartitionSO.Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUIUtils.HorizontalLine();
|
||||||
|
|
||||||
|
using (new EditorGUILayout.HorizontalScope())
|
||||||
|
{
|
||||||
id = (ulong)EditorGUILayout.LongField("id", (long)id);
|
id = (ulong)EditorGUILayout.LongField("id", (long)id);
|
||||||
|
|
||||||
if (GUILayout.Button("Load Section"))
|
if (GUILayout.Button("Load Id"))
|
||||||
{
|
{
|
||||||
scenePartitionSO.LoadPartitions(new ulong[1] { id });
|
scenePartitionSO.LoadPartitions(new ulong[1] { id });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUIUtils.HorizontalLine();
|
||||||
|
|
||||||
|
ScenePartitionSceneViewEditor.cellSize = EditorGUILayout.IntSlider("cellSize", ScenePartitionSceneViewEditor.cellSize, 10, 1000);
|
||||||
|
|
||||||
if (GUILayout.Button("GenerateSceneGrid"))
|
if (GUILayout.Button("GenerateSceneGrid"))
|
||||||
{
|
{
|
||||||
scenePartitionSO.GenerateSceneGridData();
|
scenePartitionSO.GenerateSceneGridData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scenePartitionSO.Data.SceneGrid != null)
|
||||||
|
{
|
||||||
gridId = EditorGUILayout.IntField("gridId", gridId);
|
gridId = EditorGUILayout.IntField("gridId", gridId);
|
||||||
|
|
||||||
if (GUILayout.Button("LoadSceneGrid"))
|
if (GUILayout.Button("LoadSceneGrid"))
|
||||||
@ -79,11 +95,11 @@ public override void OnInspectorGUI()
|
|||||||
scenePartitionSO.LoadCell(gridId);
|
scenePartitionSO.LoadCell(gridId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scenePartitionSO.Data.SceneGrid != null)
|
using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("gridData", ref foldoutGroupEnabled))
|
||||||
{
|
{
|
||||||
EditorGUILayout.LabelField($"generatedSceneGrid");
|
if (!foldoutGroupEnabled) return;
|
||||||
|
|
||||||
scenePartitionSO.Data.SceneGrid.cellSize = EditorGUILayout.IntSlider("cellSize", scenePartitionSO.Data.SceneGrid.cellSize, 10, 1000);
|
EditorGUILayout.LabelField($"generatedSceneGrid");
|
||||||
|
|
||||||
foreach (KeyValuePair<int, GridList> item in scenePartitionSO.Data.SceneGrid.Grid)
|
foreach (KeyValuePair<int, GridList> item in scenePartitionSO.Data.SceneGrid.Grid)
|
||||||
{
|
{
|
||||||
@ -102,4 +118,5 @@ public override void OnInspectorGUI()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ namespace VertexColor.ScenePartition.Editor
|
|||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public class ScenePartitionSceneViewEditor : UnityEditor.Editor
|
public class ScenePartitionSceneViewEditor : UnityEditor.Editor
|
||||||
{
|
{
|
||||||
|
public static int cellSize = 100;
|
||||||
|
|
||||||
private static ScenePartitionSO scenePartitionSO = null;
|
private static ScenePartitionSO scenePartitionSO = null;
|
||||||
|
|
||||||
static ScenePartitionSceneViewEditor()
|
static ScenePartitionSceneViewEditor()
|
||||||
@ -18,7 +20,6 @@ private static void HandleDuringSceneGui(SceneView sceneView)
|
|||||||
if (Event.current.modifiers != EventModifiers.Control) return;
|
if (Event.current.modifiers != EventModifiers.Control) return;
|
||||||
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out scenePartitionSO)) return;
|
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out scenePartitionSO)) return;
|
||||||
|
|
||||||
int cellSize = scenePartitionSO.Data.SceneGrid.cellSize;
|
|
||||||
Vector3 gridPosition = CalculateGridPosition(Event.current.mousePosition);
|
Vector3 gridPosition = CalculateGridPosition(Event.current.mousePosition);
|
||||||
int gridId = SceneGrid.CalculateGridPosition(gridPosition, cellSize);
|
int gridId = SceneGrid.CalculateGridPosition(gridPosition, cellSize);
|
||||||
|
|
||||||
|
@ -5,15 +5,12 @@ namespace VertexColor.ScenePartition
|
|||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class SceneGrid
|
public class SceneGrid
|
||||||
{
|
{
|
||||||
[SerializeField]
|
|
||||||
public int cellSize = 10;
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private SceneGridDictionary grid = new SceneGridDictionary();
|
private SceneGridDictionary grid = new SceneGridDictionary();
|
||||||
|
|
||||||
public SceneGridDictionary Grid => grid;
|
public SceneGridDictionary Grid => grid;
|
||||||
|
|
||||||
public void Insert(ulong scenePartitionId, Vector3 point)
|
public void Insert(ulong scenePartitionId, Vector3 point, int cellSize)
|
||||||
{
|
{
|
||||||
int gridId = CalculateGridPosition(point, cellSize);
|
int gridId = CalculateGridPosition(point, cellSize);
|
||||||
if (grid.TryGetValue(gridId, out GridList ids))
|
if (grid.TryGetValue(gridId, out GridList ids))
|
||||||
|
Loading…
Reference in New Issue
Block a user