2020-08-07 22:19:03 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using MelonLoader;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
2020-08-13 00:06:39 +10:00
|
|
|
|
public class ScenePage : WindowPage
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
|
|
|
|
public static ScenePage Instance;
|
|
|
|
|
|
|
|
|
|
public override string Name { get => "Scene Explorer"; set => base.Name = value; }
|
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
public PageHelper Pages = new PageHelper();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private float m_timeOfLastUpdate = -1f;
|
|
|
|
|
|
|
|
|
|
// ----- Holders for GUI elements ----- //
|
|
|
|
|
|
|
|
|
|
private string m_currentScene = "";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
// gameobject list
|
|
|
|
|
private Transform m_currentTransform;
|
2020-08-12 18:26:13 +10:00
|
|
|
|
private List<GameObjectCache> m_objectList = new List<GameObjectCache>();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
// search bar
|
|
|
|
|
private bool m_searching = false;
|
|
|
|
|
private string m_searchInput = "";
|
2020-08-12 18:26:13 +10:00
|
|
|
|
private List<GameObjectCache> m_searchResults = new List<GameObjectCache>();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
// ------------ Init and Update ------------ //
|
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnSceneChange()
|
|
|
|
|
{
|
2020-08-18 17:11:58 +10:00
|
|
|
|
m_currentScene = UnityHelpers.ActiveSceneName;
|
2020-08-24 01:42:19 +10:00
|
|
|
|
SetTransformTarget(null);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
//public void CheckOffset(ref int offset, int childCount)
|
|
|
|
|
//{
|
|
|
|
|
// if (offset >= childCount)
|
|
|
|
|
// {
|
|
|
|
|
// offset = 0;
|
|
|
|
|
// m_pageOffset = 0;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (m_searching) return;
|
|
|
|
|
|
|
|
|
|
if (Time.time - m_timeOfLastUpdate < 1f) return;
|
|
|
|
|
m_timeOfLastUpdate = Time.time;
|
|
|
|
|
|
|
|
|
|
m_objectList = new List<GameObjectCache>();
|
|
|
|
|
|
|
|
|
|
var allTransforms = new List<Transform>();
|
|
|
|
|
|
|
|
|
|
// get current list of all transforms (either scene root or our current transform children)
|
|
|
|
|
if (m_currentTransform)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
for (int i = 0; i < m_currentTransform.childCount; i++)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
allTransforms.Add(m_currentTransform.GetChild(i));
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var scene = SceneManager.GetSceneByName(m_currentScene);
|
|
|
|
|
var rootObjects = scene.GetRootGameObjects();
|
|
|
|
|
|
|
|
|
|
foreach (var obj in rootObjects)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
allTransforms.Add(obj.transform);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.Count = allTransforms.Count;
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
int offset = Pages.CalculateOffsetIndex();
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
|
|
|
|
// sort by childcount
|
|
|
|
|
allTransforms.Sort((a, b) => b.childCount.CompareTo(a.childCount));
|
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
for (int i = offset; i < offset + Pages.PageLimit && i < Pages.Count; i++)
|
2020-08-24 01:42:19 +10:00
|
|
|
|
{
|
|
|
|
|
var child = allTransforms[i];
|
|
|
|
|
m_objectList.Add(new GameObjectCache(child.gameObject));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetTransformTarget(Transform t)
|
|
|
|
|
{
|
|
|
|
|
m_currentTransform = t;
|
|
|
|
|
|
|
|
|
|
if (m_searching)
|
|
|
|
|
CancelSearch();
|
|
|
|
|
|
|
|
|
|
m_timeOfLastUpdate = -1f;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TraverseUp()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentTransform.parent != null)
|
|
|
|
|
{
|
|
|
|
|
SetTransformTarget(m_currentTransform.parent);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetTransformTarget(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Search()
|
|
|
|
|
{
|
|
|
|
|
m_searchResults = SearchSceneObjects(m_searchInput);
|
|
|
|
|
m_searching = true;
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.Count = m_searchResults.Count;
|
2020-08-24 01:42:19 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CancelSearch()
|
|
|
|
|
{
|
|
|
|
|
m_searching = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<GameObjectCache> SearchSceneObjects(string _search)
|
|
|
|
|
{
|
|
|
|
|
var matches = new List<GameObjectCache>();
|
|
|
|
|
|
|
|
|
|
foreach (var obj in Resources.FindObjectsOfTypeAll<GameObject>())
|
|
|
|
|
{
|
|
|
|
|
if (obj.name.ToLower().Contains(_search.ToLower()) && obj.scene.name == m_currentScene)
|
|
|
|
|
{
|
|
|
|
|
matches.Add(new GameObjectCache(obj));
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
|
|
|
|
return matches;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
// --------- GUI Draw Function --------- //
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
|
|
|
|
public override void DrawWindow()
|
2020-08-12 05:34:34 +10:00
|
|
|
|
{
|
2020-08-07 22:19:03 +10:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
DrawHeaderArea();
|
2020-08-14 16:19:39 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
2020-08-12 05:34:34 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
DrawPageButtons();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (!m_searching)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
DrawGameObjectList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DrawSearchResultsList();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
MelonLogger.Log("Exception drawing ScenePage! " + e.GetType() + ", " + e.Message);
|
|
|
|
|
MelonLogger.Log(e.StackTrace);
|
|
|
|
|
m_currentTransform = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private void DrawHeaderArea()
|
|
|
|
|
{
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
// Current Scene label
|
|
|
|
|
GUILayout.Label("Current Scene:", new GUILayoutOption[] { GUILayout.Width(120) });
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Need to do 'ToList()' so the object isn't cleaned up by Il2Cpp GC.
|
|
|
|
|
var scenes = SceneManager.GetAllScenes().ToList();
|
|
|
|
|
|
|
|
|
|
if (scenes.Count > 1)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
int changeWanted = 0;
|
|
|
|
|
if (GUILayout.Button("<", new GUILayoutOption[] { GUILayout.Width(30) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
changeWanted = -1;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (GUILayout.Button(">", new GUILayoutOption[] { GUILayout.Width(30) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
changeWanted = 1;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (changeWanted != 0)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
int index = scenes.IndexOf(SceneManager.GetSceneByName(m_currentScene));
|
|
|
|
|
index += changeWanted;
|
|
|
|
|
if (index > scenes.Count - 1)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
index = 0;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
else if (index < 0)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
index = scenes.Count - 1;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
m_currentScene = scenes[index].name;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
catch { }
|
|
|
|
|
GUILayout.Label("<color=cyan>" + m_currentScene + "</color>", null); //new GUILayoutOption[] { GUILayout.Width(250) });
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
// ----- GameObject Search -----
|
|
|
|
|
GUILayout.BeginHorizontal(GUI.skin.box, null);
|
|
|
|
|
GUILayout.Label("<b>Search Scene:</b>", new GUILayoutOption[] { GUILayout.Width(100) });
|
|
|
|
|
m_searchInput = GUILayout.TextField(m_searchInput, null);
|
|
|
|
|
if (GUILayout.Button("Search", new GUILayoutOption[] { GUILayout.Width(80) }))
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
Search();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
GUILayout.Space(5);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private void DrawPageButtons()
|
|
|
|
|
{
|
|
|
|
|
GUILayout.BeginHorizontal(null);
|
2020-08-12 05:34:34 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.DrawLimitInputArea();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
if (Pages.Count > Pages.PageLimit)
|
2020-08-24 01:42:19 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
|
2020-08-24 01:42:19 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.TurnPage(Turn.Left, ref this.scroll);
|
2020-08-24 01:42:19 +10:00
|
|
|
|
Update();
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.CurrentPageLabel();
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
|
2020-08-24 01:42:19 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
Pages.TurnPage(Turn.Right, ref this.scroll);
|
2020-08-24 01:42:19 +10:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private void DrawGameObjectList()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (m_currentTransform != null)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.BeginHorizontal(null);
|
|
|
|
|
if (GUILayout.Button("<-", new GUILayoutOption[] { GUILayout.Width(35) }))
|
|
|
|
|
{
|
|
|
|
|
TraverseUp();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("<color=cyan>" + m_currentTransform.GetGameObjectPath() + "</color>",
|
|
|
|
|
new GUILayoutOption[] { GUILayout.Width(MainMenu.MainRect.width - 187f) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIHelpers.SmallInspectButton(m_currentTransform);
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.Label("Scene Root GameObjects:", null);
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (m_objectList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in m_objectList)
|
|
|
|
|
{
|
|
|
|
|
if (!obj.RefGameObject)
|
|
|
|
|
{
|
|
|
|
|
string label = "<color=red><i>null";
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (obj.RefGameObject != null)
|
|
|
|
|
{
|
|
|
|
|
label += " (Destroyed)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
label += "</i></color>";
|
|
|
|
|
GUILayout.Label(label, null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UIHelpers.FastGameobjButton(obj.RefGameObject,
|
|
|
|
|
obj.EnabledColor,
|
|
|
|
|
obj.Label,
|
|
|
|
|
obj.RefGameObject.activeSelf,
|
|
|
|
|
SetTransformTarget,
|
|
|
|
|
true,
|
|
|
|
|
MainMenu.MainRect.width - 170);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
private void DrawSearchResultsList()
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (GUILayout.Button("<- Cancel Search", new GUILayoutOption[] { GUILayout.Width(150) }))
|
|
|
|
|
{
|
|
|
|
|
CancelSearch();
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-08-24 01:42:19 +10:00
|
|
|
|
GUILayout.Label("Search Results:", null);
|
|
|
|
|
|
|
|
|
|
if (m_searchResults.Count > 0)
|
2020-08-07 22:19:03 +10:00
|
|
|
|
{
|
2020-09-03 19:48:50 +10:00
|
|
|
|
int offset = Pages.CalculateOffsetIndex();
|
2020-08-07 22:19:03 +10:00
|
|
|
|
|
2020-09-03 19:48:50 +10:00
|
|
|
|
for (int i = offset; i < offset + Pages.PageLimit && i < m_searchResults.Count; i++)
|
2020-08-24 01:42:19 +10:00
|
|
|
|
{
|
|
|
|
|
var obj = m_searchResults[i];
|
|
|
|
|
|
2020-08-31 16:27:14 +10:00
|
|
|
|
if (obj.RefGameObject)
|
|
|
|
|
{
|
|
|
|
|
UIHelpers.FastGameobjButton(obj.RefGameObject,
|
|
|
|
|
obj.EnabledColor,
|
|
|
|
|
obj.Label,
|
|
|
|
|
obj.RefGameObject.activeSelf,
|
|
|
|
|
SetTransformTarget,
|
|
|
|
|
true,
|
|
|
|
|
MainMenu.MainRect.width - 170);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("<i><color=red>Null or destroyed!</color></i>", null);
|
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Label("<color=red><i>No results found!</i></color>", null);
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
2020-08-24 01:42:19 +10:00
|
|
|
|
|
|
|
|
|
// -------- Mini GameObjectCache class ---------- //
|
2020-08-12 18:26:13 +10:00
|
|
|
|
|
|
|
|
|
public class GameObjectCache
|
|
|
|
|
{
|
|
|
|
|
public GameObject RefGameObject;
|
|
|
|
|
public string Label;
|
|
|
|
|
public Color EnabledColor;
|
|
|
|
|
public int ChildCount;
|
|
|
|
|
|
|
|
|
|
public GameObjectCache(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
RefGameObject = obj;
|
|
|
|
|
ChildCount = obj.transform.childCount;
|
|
|
|
|
|
|
|
|
|
Label = (ChildCount > 0) ? "[" + obj.transform.childCount + " children] " : "";
|
|
|
|
|
Label += obj.name;
|
|
|
|
|
|
|
|
|
|
bool enabled = obj.activeSelf;
|
|
|
|
|
int childCount = obj.transform.childCount;
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
if (childCount > 0)
|
|
|
|
|
{
|
|
|
|
|
EnabledColor = Color.green;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EnabledColor = UIStyles.LightGreen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EnabledColor = Color.red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 22:19:03 +10:00
|
|
|
|
}
|
|
|
|
|
}
|