2020-08-07 22:19:03 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2020-08-18 17:11:58 +10:00
|
|
|
|
using System.Threading.Tasks;
|
2020-09-04 21:36:40 +10:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnhollowerRuntimeLib;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Object = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
2020-08-18 17:11:58 +10:00
|
|
|
|
public class UIHelpers
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
|
|
|
|
// helper for "Instantiate" button on UnityEngine.Objects
|
|
|
|
|
public static void InstantiateButton(Object obj, float width = 100)
|
|
|
|
|
{
|
|
|
|
|
if (GUILayout.Button("Instantiate", new GUILayoutOption[] { GUILayout.Width(width) }))
|
|
|
|
|
{
|
|
|
|
|
var newobj = Object.Instantiate(obj);
|
|
|
|
|
|
|
|
|
|
WindowManager.InspectObject(newobj, out _);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// helper for drawing a styled button for a GameObject or Transform
|
2020-09-04 21:36:40 +10:00
|
|
|
|
public static void GOButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 20:58:04 +10:00
|
|
|
|
var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject;
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
bool hasChild = obj.transform.childCount > 0;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
string label = hasChild ? $"[{obj.transform.childCount} children] " : "";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
label += obj.name;
|
|
|
|
|
|
2020-08-12 18:26:13 +10:00
|
|
|
|
bool enabled = obj.activeSelf;
|
|
|
|
|
int childCount = obj.transform.childCount;
|
|
|
|
|
Color color;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
2020-08-12 18:26:13 +10:00
|
|
|
|
if (childCount > 0)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-12 18:26:13 +10:00
|
|
|
|
color = Color.green;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-18 17:11:58 +10:00
|
|
|
|
color = UIStyles.LightGreen;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-12 18:26:13 +10:00
|
|
|
|
color = Color.red;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
GOButton_Impl(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
|
2020-08-12 18:26:13 +10:00
|
|
|
|
}
|
2020-08-18 17:11:58 +10:00
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
public static void GOButton_Impl(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
|
2020-08-12 18:26:13 +10:00
|
|
|
|
{
|
2020-09-03 20:58:04 +10:00
|
|
|
|
var obj = _obj as GameObject ?? (_obj as Transform).gameObject;
|
|
|
|
|
|
2020-08-12 18:26:13 +10:00
|
|
|
|
if (!obj)
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("<i><color=red>null</color></i>", null);
|
|
|
|
|
return;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------ toggle active button ------
|
|
|
|
|
|
2020-08-12 18:26:13 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUI.skin.button.alignment = TextAnchor.UpperLeft;
|
|
|
|
|
|
|
|
|
|
GUI.color = activeColor;
|
|
|
|
|
|
2020-08-07 22:19:03 +10:00
|
|
|
|
enabled = GUILayout.Toggle(enabled, "", new GUILayoutOption[] { GUILayout.Width(18) });
|
|
|
|
|
if (obj.activeSelf != enabled)
|
|
|
|
|
{
|
|
|
|
|
obj.SetActive(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------- actual button ---------
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Height(22), GUILayout.Width(width) }))
|
|
|
|
|
{
|
|
|
|
|
if (specialInspectMethod != null)
|
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
specialInspectMethod(obj.transform);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-03 20:58:04 +10:00
|
|
|
|
WindowManager.InspectObject(_obj, out bool _);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------ small "Inspect" button on the right ------
|
|
|
|
|
|
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
|
|
|
|
GUI.color = Color.white;
|
|
|
|
|
|
|
|
|
|
if (showSmallInspectBtn)
|
|
|
|
|
{
|
2020-09-03 20:58:04 +10:00
|
|
|
|
SmallInspectButton(_obj);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
|
|
|
|
public static void SmallInspectButton(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (GUILayout.Button("Inspect", null))
|
|
|
|
|
{
|
|
|
|
|
WindowManager.InspectObject(obj, out bool _);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|