SceneDebugViewer/Editor/SceneDebugViewerWindow.cs

119 lines
2.7 KiB
C#
Raw Normal View History

2021-03-31 01:20:21 +02:00
using System.Collections.Generic;
2021-03-30 15:36:30 +02:00
using UnityEngine;
using UnityEditor;
namespace TAO.SceneDebugViewer.Editor
{
public class SceneDebugViewerWindow : EditorWindow
{
public static SceneDebugViewerWindow window = null;
public static List<ReplacementShaderSetupScriptableObject> options = new List<ReplacementShaderSetupScriptableObject>();
private GUIStyle optionsButtonStyle = null;
2021-04-20 20:23:13 +02:00
private Vector2 scrollPos;
2021-03-30 15:36:30 +02:00
2021-04-23 17:02:34 +02:00
[MenuItem("Window/Analysis/SceneDebugViewer/SDV")]
static void Init()
{
2021-03-31 01:20:21 +02:00
Load();
2021-03-31 01:20:21 +02:00
window = (SceneDebugViewerWindow)GetWindow(typeof(SceneDebugViewerWindow));
window.titleContent = new GUIContent("SDV");
//window.maxSize = new Vector2(101, window.maxSize.y);
2021-03-31 14:01:01 +02:00
window.minSize = new Vector2(101, window.minSize.y);
window.Show();
}
private void OnGUI()
{
if (window == null)
{
window = (SceneDebugViewerWindow)GetWindow(typeof(SceneDebugViewerWindow));
}
2021-03-31 01:20:21 +02:00
using (new GUILayout.VerticalScope())
{
2021-03-31 01:20:21 +02:00
if (GUILayout.Button("Reload"))
{
2021-03-31 01:20:21 +02:00
Load();
}
2021-04-20 20:23:13 +02:00
using (var scope = new GUILayout.ScrollViewScope(scrollPos, false, false))
{
2021-04-20 20:23:13 +02:00
scrollPos = scope.scrollPosition;
2021-03-31 01:20:21 +02:00
2021-04-20 20:23:13 +02:00
if (window.position.width <= 101)
{
2021-04-20 20:23:13 +02:00
// Compact grid.
optionsButtonStyle = new GUIStyle(GUI.skin.button)
{
2021-04-20 20:23:13 +02:00
alignment = TextAnchor.MiddleCenter,
fixedHeight = 44
};
2021-03-31 14:01:01 +02:00
2021-04-20 20:23:13 +02:00
for (int i = 0; i < options.Count; i += 2)
{
2021-04-20 20:23:13 +02:00
GUILayout.BeginHorizontal();
if (GUILayout.Button(options[i].Content.compact, optionsButtonStyle))
{
2021-04-20 20:23:13 +02:00
options[i].Replace();
}
if (i + 1 < options.Count)
{
if (GUILayout.Button(options[i + 1].Content.compact, optionsButtonStyle))
{
options[i + 1].Replace();
}
}
2021-04-20 20:23:13 +02:00
GUILayout.EndHorizontal();
}
2021-03-31 01:20:21 +02:00
}
2021-04-20 20:23:13 +02:00
else
{
2021-04-20 20:23:13 +02:00
// Normal list.
optionsButtonStyle = new GUIStyle(GUI.skin.button)
{
alignment = TextAnchor.MiddleLeft,
fixedHeight = 44
};
2021-03-31 14:01:01 +02:00
2021-04-20 20:23:13 +02:00
for (int i = 0; i < options.Count; i ++)
2021-03-31 14:01:01 +02:00
{
2021-04-20 20:23:13 +02:00
if (GUILayout.Button(options[i].Content.normal, optionsButtonStyle))
{
options[i].Replace();
}
2021-03-31 14:01:01 +02:00
}
}
2021-03-31 01:20:21 +02:00
}
}
}
private static void Load()
{
options.Clear();
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(ReplacementShaderSetupScriptableObject).ToString()), null);
2021-03-31 01:20:21 +02:00
foreach (string guid in guids)
{
options.Add((ReplacementShaderSetupScriptableObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(ReplacementShaderSetupScriptableObject)));
}
SortOptions();
}
private static void SortOptions()
{
if (options != null)
{
RSSOComparer comparer = new RSSOComparer();
options.Sort(comparer);
}
}
}
}