* Added exception handling for scrollview when unstripping fails
* Added some better logging in some places
This commit is contained in:
sinaioutlander 2020-09-04 01:27:44 +10:00
parent 51cfbe524e
commit 5de771389e
6 changed files with 56 additions and 25 deletions

View File

@ -12,7 +12,7 @@ namespace Explorer
public class CppExplorer : MelonMod
{
public const string GUID = "com.sinai.cppexplorer";
public const string VERSION = "1.5.2";
public const string VERSION = "1.5.3";
public const string AUTHOR = "Sinai";
public const string NAME = "CppExplorer"
@ -99,6 +99,8 @@ namespace Explorer
public override void OnGUI()
{
if (!ShowMenu) return;
MainMenu.Instance.OnGUI();
WindowManager.Instance.OnGUI();
InspectUnderMouse.OnGUI();

View File

@ -10,6 +10,35 @@ namespace Explorer
{
public class UIHelpers
{
private static bool ScrollUnstrippingFailed = false;
public static Vector2 BeginScrollView(Vector2 scroll) => BeginScrollView(scroll, null);
public static Vector2 BeginScrollView(Vector2 scroll, GUIStyle style, params GUILayoutOption[] layoutOptions)
{
if (ScrollUnstrippingFailed) return scroll;
try
{
if (style != null)
return GUILayout.BeginScrollView(scroll, style, layoutOptions);
else
return GUILayout.BeginScrollView(scroll, layoutOptions);
}
catch
{
ScrollUnstrippingFailed = true;
return scroll;
}
}
public static void EndScrollView()
{
if (ScrollUnstrippingFailed) return;
GUILayout.EndScrollView();
}
// helper for "Instantiate" button on UnityEngine.Objects
public static void InstantiateButton(Object obj, float width = 100)
{

View File

@ -51,15 +51,12 @@ namespace Explorer
public void OnGUI()
{
if (CppExplorer.ShowMenu)
{
var origSkin = GUI.skin;
GUI.skin = UIStyles.WindowSkin;
var origSkin = GUI.skin;
GUI.skin = UIStyles.WindowSkin;
MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME);
MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME);
GUI.skin = origSkin;
}
GUI.skin = origSkin;
}
private void MainWindow(int id)
@ -77,9 +74,12 @@ namespace Explorer
MainHeader();
var page = Pages[m_currentPage];
page.scroll = GUILayout.BeginScrollView(page.scroll, GUI.skin.scrollView);
page.scroll = UIHelpers.BeginScrollView(page.scroll);
page.DrawWindow();
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);

View File

@ -132,7 +132,7 @@ namespace Explorer
GUILayout.EndHorizontal();
resultsScroll = GUILayout.BeginScrollView(resultsScroll, GUI.skin.scrollView);
resultsScroll = UIHelpers.BeginScrollView(resultsScroll);
var _temprect = new Rect(MainMenu.MainRect.x, MainMenu.MainRect.y, MainMenu.MainRect.width + 160, MainMenu.MainRect.height);
@ -153,7 +153,7 @@ namespace Explorer
GUILayout.Label("<color=red><i>No results found!</i></color>", null);
}
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
GUILayout.EndVertical();
}
catch

View File

@ -73,8 +73,8 @@ namespace Explorer
m_name = m_object.name;
m_scene = string.IsNullOrEmpty(m_object.scene.name)
? "None"
: m_object.scene.name;
? "None"
: m_object.scene.name;
Update();
}
@ -121,7 +121,7 @@ namespace Explorer
private void DestroyOnException(Exception e)
{
MelonLogger.Log($"{e.GetType()}, {e.Message}");
MelonLogger.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}");
DestroyWindow();
}
@ -169,7 +169,7 @@ namespace Explorer
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
}
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
scroll = UIHelpers.BeginScrollView(scroll);
GUILayout.BeginHorizontal(null);
GUILayout.Label("Scene: <color=cyan>" + (m_scene == "" ? "n/a" : m_scene) + "</color>", null);
@ -220,7 +220,7 @@ namespace Explorer
GameObjectControls();
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
if (!WindowManager.TabView)
{
@ -237,8 +237,8 @@ namespace Explorer
private void TransformList(Rect m_rect)
{
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView);
GUILayout.BeginVertical(GUI.skin.box, null);
m_transformScroll = UIHelpers.BeginScrollView(m_transformScroll);
GUILayout.Label("<b><size=15>Children</size></b>", null);
@ -287,14 +287,14 @@ namespace Explorer
GUILayout.Label("<i>None</i>", null);
}
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
GUILayout.EndVertical();
}
private void ComponentList(Rect m_rect)
{
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView);
GUILayout.BeginVertical(GUI.skin.box, null);
m_compScroll = UIHelpers.BeginScrollView(m_compScroll);
GUILayout.Label("<b><size=15>Components</size></b>", null);
GUILayout.BeginHorizontal(null);
@ -369,7 +369,7 @@ namespace Explorer
}
}
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
GUILayout.EndVertical();
}

View File

@ -283,7 +283,7 @@ namespace Explorer
// ====== BODY ======
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
scroll = UIHelpers.BeginScrollView(scroll);
GUILayout.Space(10);
@ -316,7 +316,7 @@ namespace Explorer
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
UIHelpers.EndScrollView();
if (!WindowManager.TabView)
{