Files
UnityExplorer_Fix/src/UI/Shared/Buttons.cs
sinaioutlander 3c964cfef9 2.0.7
* More unstripping fixes. Explorer now works 100% on a blank Unity project (so should therefore work on any Unity game, regardless of stripping).
* Some cleanups
2020-10-18 21:41:04 +11:00

101 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Explorer.UI.Shared
{
public class Buttons
{
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 _);
}
}
public static void InspectButton(object obj)
{
if (GUILayout.Button("Inspect", new GUILayoutOption[0]))
{
WindowManager.InspectObject(obj, out bool _);
}
}
public static void GameObjectButton(object _obj, Action<Transform> inspectOverride = null, bool showSmallInspect = true, float width = 380)
{
var go = (_obj as GameObject) ?? (_obj as Transform).gameObject;
if (!go) return;
bool hasChild = go.transform.childCount > 0;
string label = hasChild ? $"[{go.transform.childCount} children] " : "";
label += go.name;
bool enabled = go.activeSelf;
int childCount = go.transform.childCount;
Color color;
if (enabled)
{
if (childCount > 0)
{
color = Color.green;
}
else
{
color = UIStyles.LightGreen;
}
}
else
{
color = Color.red;
}
// ------ toggle active button ------
GUIHelper.BeginHorizontal(new GUILayoutOption[0]);
GUI.skin.button.alignment = TextAnchor.UpperLeft;
GUI.color = color;
enabled = GUILayout.Toggle(enabled, "", new GUILayoutOption[] { GUILayout.Width(18) });
if (go.activeSelf != enabled)
{
go.SetActive(enabled);
}
// ------- actual button ---------
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Height(22), GUILayout.Width(width) }))
{
if (inspectOverride != null)
{
inspectOverride(go.transform);
}
else
{
WindowManager.InspectObject(_obj, out bool _);
}
}
// ------ small "Inspect" button on the right ------
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
GUI.color = Color.white;
if (showSmallInspect)
{
InspectButton(_obj);
}
GUILayout.EndHorizontal();
}
}
}