SanAndreasUnity/Assets/Scripts/Editor/InGameWindowDrawer.cs

86 lines
2.5 KiB
C#
Raw Normal View History

2022-01-26 19:33:29 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using SanAndreasUnity.UI;
using System.Linq;
using System;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.Editor
{
public class InGameWindowDrawer : EditorWindowBase
{
private bool m_searchedForWindows = false;
private List<PauseMenuWindow> m_pauseMenuWindows = new List<PauseMenuWindow>();
private int m_selectedWindowIndex = -1;
private Vector2 m_scrollViewPosition = Vector2.zero;
public InGameWindowDrawer()
{
this.titleContent = new GUIContent("In-game window drawer");
this.minSize = new Vector2(450, 300);
}
[MenuItem(EditorCore.MenuName + "/" + "In-game window drawer")]
static void Init()
{
var window = GetWindow<InGameWindowDrawer>();
window.Show();
}
void SearchForWindows()
{
if (m_searchedForWindows)
return;
if (Behaviours.UIManager.Singleton != null)
{
m_searchedForWindows = true;
m_pauseMenuWindows = Behaviours.UIManager.Singleton
.GetComponentsInChildren<PauseMenuWindow>()
.Where(w => w.DrawInEditMode)
.ToList();
}
}
void OnGUI()
{
this.SearchForWindows();
int tabsAreaWidth = 120;
GUILayout.BeginArea(new Rect(0, 0, tabsAreaWidth, this.position.height));
m_scrollViewPosition = GUILayout.BeginScrollView(m_scrollViewPosition);
for (int i = 0; i < m_pauseMenuWindows.Count; i++)
{
if (null == m_pauseMenuWindows[i])
continue;
GUI.enabled = m_selectedWindowIndex != i;
if (GUILayout.Button(m_pauseMenuWindows[i].windowName, GUILayout.Width(tabsAreaWidth - 10)))
m_selectedWindowIndex = i;
GUI.enabled = true;
}
GUILayout.EndScrollView();
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(tabsAreaWidth, 0, this.position.width - tabsAreaWidth, this.position.height));
if (m_selectedWindowIndex >= 0)
{
var window = m_pauseMenuWindows[m_selectedWindowIndex];
if (window != null)
{
window.DrawWindowContent();
}
}
GUILayout.EndArea();
}
}
}