ScenePartition/Editor/ScenePartitionEditorWindow.cs
max 8b44c33813 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)
2023-07-09 23:01:48 +02:00

109 lines
4.1 KiB
C#

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;
[MenuItem("Window/ScenePartition")]
public static void ShowExample()
{
ScenePartitionEditorWindow window = GetWindow<ScenePartitionEditorWindow>();
window.titleContent = new GUIContent($"{nameof(ScenePartitionEditorWindow)}");
}
private void OnGUI()
{
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();
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))
{
scrollPos = scope.scrollPosition;
using (new EditorGUI.DisabledGroupScope(true))
{
ScenePartitionSS scenePartitionSS = ScenePartitionSS.instance;
foreach (KeyValuePair<ScenePartitionSO, ScenePartitionData> 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<ulong, ScenePartition> scenePartition in sceneData.Value.ScenePartitions)
{
EditorGUILayout.LongField((long)scenePartition.Key);
}
}
EditorGUILayout.Space();
if (sceneData.Value.HasLoadedPartitions)
{
EditorGUILayout.LabelField($"loadedScenePartitions");
foreach (KeyValuePair<ulong, ScenePartition> scenePartition in sceneData.Value.LoadedScenePartitions)
{
EditorGUILayout.LongField((long)scenePartition.Value.id);
}
}
if (sceneData.Value.SceneGrid != null)
{
EditorGUILayout.LabelField($"generatedSceneGrid");
foreach (KeyValuePair<int, GridList> 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--;
}
}
}
}
}
}
}
}
}