2020-08-07 22:19:03 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using MelonLoader;
|
|
|
|
|
using UnhollowerRuntimeLib;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
2020-08-13 00:06:39 +10:00
|
|
|
|
public class GameObjectWindow : UIWindow
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-30 01:08:48 +10:00
|
|
|
|
public override string Title => WindowManager.TabView
|
2020-08-30 07:01:13 +10:00
|
|
|
|
? $"<color=cyan>[G]</color> {m_object.name}"
|
|
|
|
|
: $"GameObject Inspector ({m_object.name})";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
public GameObject m_object;
|
|
|
|
|
|
|
|
|
|
// gui element holders
|
|
|
|
|
private string m_name;
|
|
|
|
|
private string m_scene;
|
|
|
|
|
|
|
|
|
|
private Transform[] m_children;
|
2020-09-03 19:48:50 +10:00
|
|
|
|
private Vector2 m_transformScroll = Vector2.zero;
|
|
|
|
|
private PageHelper ChildPages = new PageHelper();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
private Component[] m_components;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
private Vector2 m_compScroll = Vector2.zero;
|
2020-09-03 19:48:50 +10:00
|
|
|
|
private PageHelper CompPages = new PageHelper();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
private float m_translateAmount = 0.3f;
|
|
|
|
|
private float m_rotateAmount = 50f;
|
|
|
|
|
private float m_scaleAmount = 0.1f;
|
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
private readonly List<Component> m_cachedDestroyList = new List<Component>();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
//private string m_addComponentInput = "";
|
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
private string m_setParentInput = "Enter a GameObject name or path";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
public bool GetObjectAsGameObject()
|
|
|
|
|
{
|
|
|
|
|
if (Target == null)
|
|
|
|
|
{
|
|
|
|
|
MelonLogger.Log("Target is null!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var targetType = Target.GetType();
|
|
|
|
|
|
|
|
|
|
if (targetType == typeof(GameObject))
|
|
|
|
|
{
|
|
|
|
|
m_object = Target as GameObject;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (targetType == typeof(Transform))
|
|
|
|
|
{
|
|
|
|
|
m_object = (Target as Transform).gameObject;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MelonLogger.Log("Error: Target is null or not a GameObject/Transform!");
|
|
|
|
|
DestroyWindow();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
if (!GetObjectAsGameObject())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_name = m_object.name;
|
2020-08-29 21:15:54 +10:00
|
|
|
|
m_scene = string.IsNullOrEmpty(m_object.scene.name)
|
2020-09-04 01:27:44 +10:00
|
|
|
|
? "None"
|
|
|
|
|
: m_object.scene.name;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Update();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
2020-08-28 00:45:34 +10:00
|
|
|
|
try
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-28 00:45:34 +10:00
|
|
|
|
if (!m_object && !GetObjectAsGameObject())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Object is null!");
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
var list = new List<Transform>();
|
|
|
|
|
for (int i = 0; i < m_object.transform.childCount; i++)
|
|
|
|
|
{
|
|
|
|
|
list.Add(m_object.transform.GetChild(i));
|
|
|
|
|
}
|
|
|
|
|
list.Sort((a, b) => b.childCount.CompareTo(a.childCount));
|
|
|
|
|
m_children = list.ToArray();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
ChildPages.ItemCount = m_children.Length;
|
2020-09-03 19:48:50 +10:00
|
|
|
|
|
|
|
|
|
var list2 = new List<Component>();
|
2020-08-29 21:15:54 +10:00
|
|
|
|
foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType))
|
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
var ilType = comp.GetIl2CppType();
|
|
|
|
|
if (ilType == ReflectionHelpers.TransformType)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list2.Add(comp);
|
2020-08-29 21:15:54 +10:00
|
|
|
|
}
|
2020-09-03 19:48:50 +10:00
|
|
|
|
m_components = list2.ToArray();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
CompPages.ItemCount = m_components.Length;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-28 00:45:34 +10:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DestroyOnException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DestroyOnException(Exception e)
|
|
|
|
|
{
|
2020-09-04 01:27:44 +10:00
|
|
|
|
MelonLogger.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}");
|
2020-08-28 00:45:34 +10:00
|
|
|
|
DestroyWindow();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private void InspectGameObject(Transform obj)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
|
|
|
|
var window = WindowManager.InspectObject(obj, out bool created);
|
|
|
|
|
|
|
|
|
|
if (created)
|
|
|
|
|
{
|
|
|
|
|
window.m_rect = new Rect(this.m_rect.x, this.m_rect.y, this.m_rect.width, this.m_rect.height);
|
|
|
|
|
DestroyWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReflectObject(Il2CppSystem.Object obj)
|
|
|
|
|
{
|
|
|
|
|
var window = WindowManager.InspectObject(obj, out bool created);
|
|
|
|
|
|
|
|
|
|
if (created)
|
|
|
|
|
{
|
|
|
|
|
if (this.m_rect.x <= (Screen.width - this.m_rect.width - 100))
|
|
|
|
|
{
|
|
|
|
|
window.m_rect = new Rect(
|
|
|
|
|
this.m_rect.x + this.m_rect.width + 20,
|
|
|
|
|
this.m_rect.y,
|
|
|
|
|
550,
|
|
|
|
|
700);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.m_rect = new Rect(this.m_rect.x + 50, this.m_rect.y + 50, 550, 700);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WindowFunction(int windowID)
|
|
|
|
|
{
|
2020-08-28 00:45:34 +10:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-30 01:08:48 +10:00
|
|
|
|
var rect = WindowManager.TabView ? TabViewWindow.Instance.m_rect : this.m_rect;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
if (!WindowManager.TabView)
|
|
|
|
|
{
|
|
|
|
|
Header();
|
|
|
|
|
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
scroll = GUIUnstrip.BeginScrollView(scroll);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
|
|
|
|
|
if (m_scene == UnityHelpers.ActiveSceneName)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 20:58:04 +10:00
|
|
|
|
if (GUILayout.Button("<color=#00FF00>Send to Scene View</color>", new GUILayoutOption[] { GUILayout.Width(150) }))
|
2020-08-28 00:45:34 +10:00
|
|
|
|
{
|
|
|
|
|
ScenePage.Instance.SetTransformTarget(m_object.transform);
|
|
|
|
|
MainMenu.SetCurrentPage(0);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-09-03 20:58:04 +10:00
|
|
|
|
if (GUILayout.Button("Reflection Inspect", new GUILayoutOption[] { GUILayout.Width(150) }))
|
|
|
|
|
{
|
|
|
|
|
WindowManager.InspectObject(Target, out _, true);
|
|
|
|
|
}
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUILayout.Label("Path:", new GUILayoutOption[] { GUILayout.Width(50) });
|
|
|
|
|
string pathlabel = m_object.transform.GetGameObjectPath();
|
|
|
|
|
if (m_object.transform.parent != null)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-28 00:45:34 +10:00
|
|
|
|
if (GUILayout.Button("<-", new GUILayoutOption[] { GUILayout.Width(35) }))
|
|
|
|
|
{
|
|
|
|
|
InspectGameObject(m_object.transform.parent);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.TextArea(pathlabel, null);
|
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUILayout.Label("Name:", new GUILayoutOption[] { GUILayout.Width(50) });
|
|
|
|
|
GUILayout.TextArea(m_name, null);
|
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
// --- Horizontal Columns section ---
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) });
|
|
|
|
|
TransformList(rect);
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.EndVertical();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) });
|
|
|
|
|
ComponentList(rect);
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.EndVertical();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.EndHorizontal(); // end horiz columns
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GameObjectControls();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
GUIUnstrip.EndScrollView();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
if (!WindowManager.TabView)
|
|
|
|
|
{
|
|
|
|
|
m_rect = ResizeDrag.ResizeWindow(rect, windowID);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
GUILayout.EndArea();
|
|
|
|
|
}
|
2020-08-28 00:45:34 +10:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DestroyOnException(e);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
private void TransformList(Rect m_rect)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-04 01:27:44 +10:00
|
|
|
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
2020-09-04 21:36:40 +10:00
|
|
|
|
m_transformScroll = GUIUnstrip.BeginScrollView(m_transformScroll);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
GUILayout.Label("<b><size=15>Children</size></b>", null);
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
ChildPages.DrawLimitInputArea();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
if (ChildPages.ItemCount > ChildPages.ItemsPerPage)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
ChildPages.CurrentPageLabel();
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
ChildPages.TurnPage(Turn.Left, ref this.m_transformScroll);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-09-03 19:48:50 +10:00
|
|
|
|
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
ChildPages.TurnPage(Turn.Right, ref this.m_transformScroll);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
if (m_children != null && m_children.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
int start = ChildPages.CalculateOffsetIndex();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
for (int j = start; (j < start + ChildPages.ItemsPerPage && j < ChildPages.ItemCount); j++)
|
2020-09-03 19:48:50 +10:00
|
|
|
|
{
|
|
|
|
|
var obj = m_children[j];
|
|
|
|
|
|
2020-08-07 22:19:03 +10:00
|
|
|
|
if (!obj)
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("null", null);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-09-03 19:48:50 +10:00
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
UIHelpers.GOButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 80);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("<i>None</i>", null);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
GUIUnstrip.EndScrollView();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 01:08:48 +10:00
|
|
|
|
private void ComponentList(Rect m_rect)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-04 01:27:44 +10:00
|
|
|
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
2020-09-04 21:36:40 +10:00
|
|
|
|
m_compScroll = GUIUnstrip.BeginScrollView(m_compScroll);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUILayout.Label("<b><size=15>Components</size></b>", null);
|
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
CompPages.DrawLimitInputArea();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
if (CompPages.ItemCount > CompPages.ItemsPerPage)
|
2020-09-03 19:48:50 +10:00
|
|
|
|
{
|
|
|
|
|
CompPages.CurrentPageLabel();
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
|
|
|
|
|
{
|
|
|
|
|
CompPages.TurnPage(Turn.Left, ref this.m_compScroll);
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
|
|
|
|
|
{
|
|
|
|
|
CompPages.TurnPage(Turn.Right, ref this.m_compScroll);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
if (m_cachedDestroyList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
m_cachedDestroyList.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 21:15:54 +10:00
|
|
|
|
if (m_components != null)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
int start = CompPages.CalculateOffsetIndex();
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
for (int j = start; (j < start + CompPages.ItemsPerPage && j < CompPages.ItemCount); j++)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
var component = m_components[j];
|
|
|
|
|
|
2020-08-29 21:15:54 +10:00
|
|
|
|
if (!component) continue;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-29 21:15:54 +10:00
|
|
|
|
var ilType = component.GetIl2CppType();
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
if (ReflectionHelpers.BehaviourType.IsAssignableFrom(ilType))
|
|
|
|
|
{
|
|
|
|
|
BehaviourEnabledBtn(component.TryCast<Behaviour>());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Space(26);
|
|
|
|
|
}
|
2020-09-03 19:48:50 +10:00
|
|
|
|
if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) }))
|
2020-08-29 21:15:54 +10:00
|
|
|
|
{
|
|
|
|
|
ReflectObject(component);
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.Button("<color=red>-</color>", new GUILayoutOption[] { GUILayout.Width(20) }))
|
|
|
|
|
{
|
|
|
|
|
m_cachedDestroyList.Add(component);
|
|
|
|
|
}
|
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
|
|
|
|
if (m_cachedDestroyList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = m_cachedDestroyList.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
var comp = m_cachedDestroyList[i];
|
|
|
|
|
GameObject.Destroy(comp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 21:36:40 +10:00
|
|
|
|
GUIUnstrip.EndScrollView();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BehaviourEnabledBtn(Behaviour obj)
|
|
|
|
|
{
|
|
|
|
|
var _col = GUI.color;
|
|
|
|
|
bool _enabled = obj.enabled;
|
|
|
|
|
if (_enabled)
|
|
|
|
|
{
|
|
|
|
|
GUI.color = Color.green;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUI.color = Color.red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------ toggle active button ------
|
|
|
|
|
|
|
|
|
|
_enabled = GUILayout.Toggle(_enabled, "", new GUILayoutOption[] { GUILayout.Width(18) });
|
|
|
|
|
if (obj.enabled != _enabled)
|
|
|
|
|
{
|
|
|
|
|
obj.enabled = _enabled;
|
|
|
|
|
}
|
|
|
|
|
GUI.color = _col;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GameObjectControls()
|
|
|
|
|
{
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) });
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUILayout.Label("<b><size=15>GameObject Controls</size></b>", null);
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
bool m_active = m_object.activeSelf;
|
|
|
|
|
m_active = GUILayout.Toggle(m_active, (m_active ? "<color=lime>Enabled " : "<color=red>Disabled") + "</color>",
|
|
|
|
|
new GUILayoutOption[] { GUILayout.Width(80) });
|
|
|
|
|
if (m_object.activeSelf != m_active) { m_object.SetActive(m_active); }
|
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
UIHelpers.InstantiateButton(m_object, 100);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
if (GUILayout.Button("Set DontDestroyOnLoad", new GUILayoutOption[] { GUILayout.Width(170) }))
|
|
|
|
|
{
|
|
|
|
|
GameObject.DontDestroyOnLoad(m_object);
|
|
|
|
|
m_object.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
m_setParentInput = GUILayout.TextField(m_setParentInput, null);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
if (GUILayout.Button("Set Parent", new GUILayoutOption[] { GUILayout.Width(80) }))
|
|
|
|
|
{
|
|
|
|
|
if (GameObject.Find(m_setParentInput) is GameObject newparent)
|
|
|
|
|
{
|
|
|
|
|
m_object.transform.parent = newparent.transform;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MelonLogger.LogWarning($"Could not find gameobject '{m_setParentInput}'");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-28 00:45:34 +10:00
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Detach from parent", new GUILayoutOption[] { GUILayout.Width(160) }))
|
|
|
|
|
{
|
|
|
|
|
m_object.transform.parent = null;
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
|
|
|
|
|
|
|
|
|
var t = m_object.transform;
|
|
|
|
|
TranslateControl(t, TranslateType.Position, ref m_translateAmount, false);
|
|
|
|
|
TranslateControl(t, TranslateType.Rotation, ref m_rotateAmount, true);
|
|
|
|
|
TranslateControl(t, TranslateType.Scale, ref m_scaleAmount, false);
|
|
|
|
|
|
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
|
2020-08-28 00:45:34 +10:00
|
|
|
|
if (GUILayout.Button("<color=red><b>Destroy</b></color>", new GUILayoutOption[] { GUILayout.Width(120) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
|
|
|
|
GameObject.Destroy(m_object);
|
|
|
|
|
DestroyWindow();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum TranslateType
|
|
|
|
|
{
|
|
|
|
|
Position,
|
|
|
|
|
Rotation,
|
|
|
|
|
Scale
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TranslateControl(Transform transform, TranslateType mode, ref float amount, bool multByTime)
|
|
|
|
|
{
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUILayout.Label("<color=cyan><b>" + mode + "</b></color>:", new GUILayoutOption[] { GUILayout.Width(65) });
|
|
|
|
|
|
|
|
|
|
Vector3 vector = Vector3.zero;
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case TranslateType.Position: vector = transform.localPosition; break;
|
|
|
|
|
case TranslateType.Rotation: vector = transform.localRotation.eulerAngles; break;
|
|
|
|
|
case TranslateType.Scale: vector = transform.localScale; break;
|
|
|
|
|
}
|
|
|
|
|
GUILayout.Label(vector.ToString(), new GUILayoutOption[] { GUILayout.Width(250) });
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
GUI.skin.label.alignment = TextAnchor.MiddleRight;
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("<color=cyan>X:</color>", new GUILayoutOption[] { GUILayout.Width(20) });
|
|
|
|
|
PlusMinusFloat(ref vector.x, amount, multByTime);
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("<color=cyan>Y:</color>", new GUILayoutOption[] { GUILayout.Width(20) });
|
|
|
|
|
PlusMinusFloat(ref vector.y, amount, multByTime);
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("<color=cyan>Z:</color>", new GUILayoutOption[] { GUILayout.Width(20) });
|
|
|
|
|
PlusMinusFloat(ref vector.z, amount, multByTime);
|
|
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case TranslateType.Position: transform.localPosition = vector; break;
|
|
|
|
|
case TranslateType.Rotation: transform.localRotation = Quaternion.Euler(vector); break;
|
|
|
|
|
case TranslateType.Scale: transform.localScale = vector; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("+/-:", new GUILayoutOption[] { GUILayout.Width(30) });
|
|
|
|
|
var input = amount.ToString("F3");
|
|
|
|
|
input = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(40) });
|
|
|
|
|
if (float.TryParse(input, out float f))
|
|
|
|
|
{
|
|
|
|
|
amount = f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PlusMinusFloat(ref float f, float amount, bool multByTime)
|
|
|
|
|
{
|
|
|
|
|
string s = f.ToString("F3");
|
|
|
|
|
s = GUILayout.TextField(s, new GUILayoutOption[] { GUILayout.Width(60) });
|
|
|
|
|
if (float.TryParse(s, out float f2))
|
|
|
|
|
{
|
|
|
|
|
f = f2;
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) }))
|
|
|
|
|
{
|
|
|
|
|
f -= multByTime ? amount * Time.deltaTime : amount;
|
|
|
|
|
}
|
|
|
|
|
if (GUILayout.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) }))
|
|
|
|
|
{
|
|
|
|
|
f += multByTime ? amount * Time.deltaTime : amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|