1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-12-18 11:55:52 +01:00
MaiDXR/Assets/uWindowCapture/Editor/UwcEditorUtils.cs
2022-01-05 19:44:30 +01:00

49 lines
1.2 KiB
C#

using UnityEngine;
using UnityEditor;
namespace uWindowCapture
{
public static class EditorUtils
{
public static bool Foldout(string title, bool display)
{
var style = new GUIStyle("ShurikenModuleTitle");
style.font = new GUIStyle(EditorStyles.label).font;
style.border = new RectOffset(15, 7, 4, 4);
style.fixedHeight = 22;
style.contentOffset = new Vector2(20f, -2f);
var rect = GUILayoutUtility.GetRect(16f, 22f, style);
GUI.Box(rect, title, style);
var e = Event.current;
var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
if (e.type == EventType.Repaint)
{
EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
}
if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
{
display = !display;
e.Use();
}
return display;
}
public static void Fold(string name, ref bool folded, System.Action func)
{
folded = Foldout(name, folded);
if (folded)
{
++EditorGUI.indentLevel;
func();
--EditorGUI.indentLevel;
}
}
}
}