Files
Continentis/Assets/OtherPlugins/Modern UI Pack/Scripts/Window/WindowManagerEditor.cs

160 lines
6.7 KiB
C#
Raw Normal View History

2025-10-03 00:02:43 -04:00
#if UNITY_EDITOR
using UnityEditor;
2026-03-20 11:56:50 -04:00
using UnityEngine;
2025-10-03 00:02:43 -04:00
namespace Michsky.MUIP
{
[CustomEditor(typeof(WindowManager))]
public class WindowManagerEditor : Editor
{
2026-03-20 11:56:50 -04:00
private int currentTab;
2025-10-03 00:02:43 -04:00
private GUISkin customSkin;
private UIManagerWindowManager tempUIM;
2026-03-20 11:56:50 -04:00
private WindowManager wmTarget;
2025-10-03 00:02:43 -04:00
private void OnEnable()
{
wmTarget = (WindowManager)target;
2026-03-20 11:56:50 -04:00
try
{
tempUIM = wmTarget.GetComponent<UIManagerWindowManager>();
}
catch
{
}
2025-10-03 00:02:43 -04:00
2026-03-20 11:56:50 -04:00
if (EditorGUIUtility.isProSkin)
customSkin = MUIPEditorHandler.GetDarkEditor(customSkin);
else
customSkin = MUIPEditorHandler.GetLightEditor(customSkin);
2025-10-03 00:02:43 -04:00
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "WM Top Header");
2026-03-20 11:56:50 -04:00
var toolbarTabs = new GUIContent[2];
2025-10-03 00:02:43 -04:00
toolbarTabs[0] = new GUIContent("Content");
toolbarTabs[1] = new GUIContent("Settings");
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
currentTab = 0;
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
currentTab = 1;
GUILayout.EndHorizontal();
var windows = serializedObject.FindProperty("windows");
var currentWindowIndex = serializedObject.FindProperty("currentWindowIndex");
var cullWindows = serializedObject.FindProperty("cullWindows");
var onWindowChange = serializedObject.FindProperty("onWindowChange");
var initializeButtons = serializedObject.FindProperty("initializeButtons");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (wmTarget.windows.Count != 0)
{
2026-03-20 11:56:50 -04:00
if (Application.isPlaying) GUI.enabled = false;
2025-10-03 00:02:43 -04:00
GUILayout.BeginVertical(EditorStyles.helpBox);
2026-03-20 11:56:50 -04:00
EditorGUILayout.LabelField(new GUIContent("Selected Window:"), customSkin.FindStyle("Text"),
GUILayout.Width(120));
currentWindowIndex.intValue = EditorGUILayout.IntSlider(currentWindowIndex.intValue, 0,
wmTarget.windows.Count - 1);
2025-10-03 00:02:43 -04:00
GUILayout.Space(2);
2026-03-20 11:56:50 -04:00
EditorGUILayout.LabelField(
new GUIContent(wmTarget.windows[currentWindowIndex.intValue].windowName),
customSkin.FindStyle("Text"));
if (!Application.isPlaying &&
wmTarget.windows[currentWindowIndex.intValue].windowObject != null)
for (var i = 0; i < wmTarget.windows.Count; i++)
if (i == currentWindowIndex.intValue)
2025-10-03 00:02:43 -04:00
{
2026-03-20 11:56:50 -04:00
var tempCG = wmTarget.windows[currentWindowIndex.intValue].windowObject
.GetComponent<CanvasGroup>();
if (tempCG != null) tempCG.alpha = 1;
2025-10-03 00:02:43 -04:00
}
else if (wmTarget.windows[i].windowObject != null)
{
var tempCG = wmTarget.windows[i].windowObject.GetComponent<CanvasGroup>();
2026-03-20 11:56:50 -04:00
if (tempCG != null) tempCG.alpha = 0;
2025-10-03 00:02:43 -04:00
}
GUI.enabled = true;
GUILayout.EndVertical();
}
2026-03-20 11:56:50 -04:00
else
{
EditorGUILayout.HelpBox("Window List is empty. Create a new item to see more options.",
MessageType.Info);
}
2025-10-03 00:02:43 -04:00
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(windows, new GUIContent("Window Items"), true);
if (GUILayout.Button("+ Add a new window", customSkin.button))
wmTarget.AddNewItem();
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onWindowChange, new GUIContent("On Window Change"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
2026-03-20 11:56:50 -04:00
cullWindows.boolValue =
MUIPEditorHandler.DrawToggle(cullWindows.boolValue, customSkin, "Cull Transparent Windows");
initializeButtons.boolValue = MUIPEditorHandler.DrawToggle(initializeButtons.boolValue, customSkin,
"Initialize Buttons");
2025-10-03 00:02:43 -04:00
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
if (tempUIM != null)
{
MUIPEditorHandler.DrawUIManagerConnectedHeader();
if (GUILayout.Button("Open UI Manager", customSkin.button))
EditorApplication.ExecuteMenuItem("Tools/Modern UI Pack/Show UI Manager");
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
2026-03-20 11:56:50 -04:00
if (EditorUtility.DisplayDialog("Modern UI Pack",
"Are you sure you want to disable UI Manager connection with the object? " +
"This operation cannot be undone.", "Yes", "Cancel"))
try
{
DestroyImmediate(tempUIM);
}
catch
{
Debug.LogError("<b>[Window Manager]</b> Failed to delete UI Manager connection.",
this);
}
2025-10-03 00:02:43 -04:00
}
2026-03-20 11:56:50 -04:00
else if (tempUIM == null)
{
MUIPEditorHandler.DrawUIManagerDisconnectedHeader();
}
2025-10-03 00:02:43 -04:00
break;
}
2026-03-20 11:56:50 -04:00
if (!Application.isPlaying) Repaint();
2025-10-03 00:02:43 -04:00
serializedObject.ApplyModifiedProperties();
}
}
}
#endif