using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace VertexColor.ScenePartition.Editor { public class ScenePartitionEditorWindow : EditorWindow { private const int cellSize = 10; private Vector2 scrollPos = Vector2.zero; private bool foldoutGroupEnabled = false; private ulong id = 0; private int gridId = 0; [MenuItem("Window/ScenePartition")] public static void ShowExample() { ScenePartitionEditorWindow window = GetWindow(); window.titleContent = new GUIContent($"{nameof(ScenePartitionEditorWindow)}"); } private void OnGUI() { 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() { EditorGUILayout.LabelField("Cache", EditorStyles.boldLabel); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Save", EditorStyles.miniButtonLeft)) { ScenePartitionSS.Save(); } if (GUILayout.Button("Clear", EditorStyles.miniButtonRight)) { ScenePartitionSS.Save(); } } EditorGUIUtils.HorizontalLine(); using (EditorGUIUtils.FoldoutHeaderScope foldoutGroup = new EditorGUIUtils.FoldoutHeaderScope("SceneDataCache", ref foldoutGroupEnabled)) { if (!foldoutGroupEnabled) return; using (EditorGUILayout.ScrollViewScope scope = new EditorGUILayout.ScrollViewScope(scrollPos)) { scrollPos = scope.scrollPosition; using (new EditorGUI.DisabledGroupScope(true)) { ScenePartitionSS scenePartitionSS = ScenePartitionSS.instance; foreach (KeyValuePair sceneData in scenePartitionSS.SceneDataCache) { if (sceneData.Key == null || sceneData.Value == null) continue; EditorGUILayout.LabelField($"{sceneData.Key.name}"); if (sceneData.Value.HasCreatedPartitions) { EditorGUILayout.LabelField($"scenePartitions"); foreach (KeyValuePair scenePartition in sceneData.Value.ScenePartitions) { EditorGUILayout.LongField((long)scenePartition.Key); } } EditorGUILayout.Space(); if (sceneData.Value.HasLoadedPartitions) { EditorGUILayout.LabelField($"loadedScenePartitions"); foreach (KeyValuePair scenePartition in sceneData.Value.LoadedScenePartitions) { EditorGUILayout.LongField((long)scenePartition.Value.id); } } if (sceneData.Value.SceneGrid != null) { EditorGUILayout.LabelField($"generatedSceneGrid"); foreach (KeyValuePair item in sceneData.Value.SceneGrid.Grid) { EditorGUILayout.IntField("gridId", item.Key); EditorGUI.indentLevel++; foreach (ulong id in item.Value.list) { EditorGUILayout.LongField((long)id); } EditorGUI.indentLevel--; } } } } } } } } }