2023-06-27 00:24:46 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace VertexColor.ScenePartition.Editor
|
|
|
|
{
|
|
|
|
public class ScenePartitionEditorWindow : EditorWindow
|
|
|
|
{
|
2023-06-29 00:20:01 +02:00
|
|
|
private const int cellSize = 10;
|
|
|
|
|
2023-06-27 00:24:46 +02:00
|
|
|
private Vector2 scrollPos = Vector2.zero;
|
2023-07-09 23:01:48 +02:00
|
|
|
private bool foldoutGroupEnabled = false;
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-26 23:52:13 +02:00
|
|
|
private ulong id = 0;
|
|
|
|
private int gridId = 0;
|
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
[MenuItem("Window/ScenePartition")]
|
2023-06-27 00:24:46 +02:00
|
|
|
public static void ShowExample()
|
|
|
|
{
|
|
|
|
ScenePartitionEditorWindow window = GetWindow<ScenePartitionEditorWindow>();
|
|
|
|
window.titleContent = new GUIContent($"{nameof(ScenePartitionEditorWindow)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGUI()
|
2023-07-26 23:52:13 +02:00
|
|
|
{
|
|
|
|
using (new EditorGUILayout.VerticalScope())
|
|
|
|
{
|
|
|
|
DrawScenePartition();
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace();
|
|
|
|
|
|
|
|
DrawSceneDataCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawScenePartition()
|
|
|
|
{
|
|
|
|
if (!ScenePartitionUtils.TryGetScenePartitionSOForActiveScene(out var scenePartitionSO)) return;
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField($"ScenePartition | {scenePartitionSO.SceneName}", EditorStyles.boldLabel);
|
|
|
|
|
|
|
|
if (scenePartitionSO.SceneAsset == null)
|
|
|
|
{
|
|
|
|
if (GUILayout.Button("Create Scene"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.CreateScene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GUILayout.Button("Load All"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.LoadAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
using (new EditorGUILayout.HorizontalScope())
|
|
|
|
{
|
|
|
|
if (GUILayout.Button(new GUIContent("Unload", "Empty the scene and save it (so it has no changes in source control)."), EditorStyles.miniButtonLeft))
|
|
|
|
{
|
|
|
|
scenePartitionSO.Unload();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GUILayout.Button(new GUIContent("Reload", "Discard changes and reload loaded partitions."), EditorStyles.miniButtonRight))
|
|
|
|
{
|
|
|
|
scenePartitionSO.Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GUILayout.Button("Save"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorGUIUtils.HorizontalLine();
|
|
|
|
|
|
|
|
using (new EditorGUILayout.HorizontalScope())
|
|
|
|
{
|
|
|
|
id = (ulong)EditorGUILayout.LongField("id", (long)id);
|
|
|
|
|
|
|
|
if (GUILayout.Button("Load Id"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.LoadPartitions(new ulong[1] { id });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorGUIUtils.HorizontalLine();
|
|
|
|
|
|
|
|
ScenePartitionSceneViewEditor.cellSize = EditorGUILayout.IntSlider("cellSize", ScenePartitionSceneViewEditor.cellSize, 10, 1000);
|
|
|
|
|
|
|
|
if (GUILayout.Button("GenerateSceneGrid"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.GenerateSceneGridData();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scenePartitionSO.Data.SceneGrid != null)
|
|
|
|
{
|
|
|
|
using (new EditorGUILayout.HorizontalScope())
|
|
|
|
{
|
|
|
|
gridId = EditorGUILayout.IntField("gridId", gridId);
|
|
|
|
|
|
|
|
if (GUILayout.Button("LoadSceneGrid"))
|
|
|
|
{
|
|
|
|
scenePartitionSO.LoadCell(gridId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorGUIUtils.HorizontalLine();
|
|
|
|
|
|
|
|
if (GUILayout.Button("Open Scene Data Folder"))
|
|
|
|
{
|
|
|
|
EditorUtility.RevealInFinder(ScenePartitionUtils.GetDataPath(scenePartitionSO));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DrawSceneDataCache()
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-04 23:34:54 +02:00
|
|
|
EditorGUILayout.LabelField("Cache", EditorStyles.boldLabel);
|
|
|
|
|
|
|
|
using (new EditorGUILayout.HorizontalScope())
|
2023-06-28 01:07:27 +02:00
|
|
|
{
|
2023-07-04 23:34:54 +02:00
|
|
|
if (GUILayout.Button("Save", EditorStyles.miniButtonLeft))
|
|
|
|
{
|
|
|
|
ScenePartitionSS.Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GUILayout.Button("Clear", EditorStyles.miniButtonRight))
|
|
|
|
{
|
|
|
|
ScenePartitionSS.Save();
|
|
|
|
}
|
2023-06-28 01:07:27 +02:00
|
|
|
}
|
|
|
|
|
2023-07-04 23:34:54 +02:00
|
|
|
EditorGUIUtils.HorizontalLine();
|
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("SceneDataCache", ref foldoutGroupEnabled))
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
if (!foldoutGroupEnabled) return;
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos))
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
scrollPos = scope.scrollPosition;
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
using (new EditorGUI.DisabledGroupScope(true))
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
ScenePartitionSS scenePartitionSS = ScenePartitionSS.instance;
|
2023-06-30 03:28:44 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
foreach (KeyValuePair<ScenePartitionSO, ScenePartitionData> sceneData in scenePartitionSS.SceneDataCache)
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
if (sceneData.Key == null || sceneData.Value == null) continue;
|
|
|
|
|
|
|
|
EditorGUILayout.LabelField($"{sceneData.Key.name}");
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
if (sceneData.Value.HasCreatedPartitions)
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
EditorGUILayout.LabelField($"scenePartitions");
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.ScenePartitions)
|
|
|
|
{
|
|
|
|
EditorGUILayout.LongField((long)scenePartition.Key);
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
EditorGUILayout.Space();
|
2023-06-27 00:24:46 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
if (sceneData.Value.HasLoadedPartitions)
|
2023-06-27 00:24:46 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
EditorGUILayout.LabelField($"loadedScenePartitions");
|
2023-06-28 01:07:27 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.LoadedScenePartitions)
|
|
|
|
{
|
|
|
|
EditorGUILayout.LongField((long)scenePartition.Value.id);
|
|
|
|
}
|
|
|
|
}
|
2023-06-28 01:07:27 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
if (sceneData.Value.SceneGrid != null)
|
2023-06-28 01:07:27 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
EditorGUILayout.LabelField($"generatedSceneGrid");
|
2023-06-28 01:07:27 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
foreach (KeyValuePair<int, GridList> item in sceneData.Value.SceneGrid.Grid)
|
2023-06-28 01:07:27 +02:00
|
|
|
{
|
2023-07-09 23:01:48 +02:00
|
|
|
EditorGUILayout.IntField("gridId", item.Key);
|
|
|
|
|
|
|
|
EditorGUI.indentLevel++;
|
2023-06-28 01:07:27 +02:00
|
|
|
|
2023-07-09 23:01:48 +02:00
|
|
|
foreach (ulong id in item.Value.list)
|
|
|
|
{
|
|
|
|
EditorGUILayout.LongField((long)id);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
}
|
2023-06-28 01:07:27 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-27 00:24:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|