Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 1a5843f

Browse files
committed
disable main menu page on failed init
1 parent 25e48f2 commit 1a5843f

File tree

7 files changed

+36
-14
lines changed

7 files changed

+36
-14
lines changed

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace UnityExplorer
1717
public class ExplorerCore
1818
{
1919
public const string NAME = "UnityExplorer";
20-
public const string VERSION = "3.2.3";
20+
public const string VERSION = "3.2.4";
2121
public const string AUTHOR = "Sinai";
2222
public const string GUID = "com.sinai.unityexplorer";
2323

src/UI/Main/BaseMenuPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public bool Enabled
2121
}
2222

2323

24-
public abstract void Init();
24+
public abstract bool Init();
2525
public abstract void Update();
2626
}
2727
}

src/UI/Main/CSConsole/CSharpConsole.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UnityEngine.UI;
1313
using UnityExplorer.UI.Reusable;
1414
using UnityExplorer.UI.Main.CSConsole;
15+
using UnityExplorer.Core;
1516

1617
namespace UnityExplorer.UI.Main
1718
{
@@ -40,13 +41,12 @@ public class CSharpConsole : BaseMenuPage
4041
#endif
4142
};
4243

43-
public override void Init()
44+
public override bool Init()
4445
{
4546
Instance = this;
4647

4748
try
4849
{
49-
//m_codeEditor = new UI.CSConsole.CSharpConsole();
5050
InitConsole();
5151

5252
AutoCompleter.Init();
@@ -57,14 +57,21 @@ public override void Init()
5757
m_evaluator.Compile("");
5858

5959
foreach (string use in DefaultUsing)
60-
{
6160
AddUsing(use);
62-
}
61+
62+
return true;
6363
}
6464
catch (Exception e)
6565
{
66-
ExplorerCore.LogWarning($"Error setting up console!\r\nMessage: {e.Message}");
67-
MainMenu.Instance.Pages.RemoveAll(it => it is CSharpConsole);
66+
string info = "The C# Console has been disabled because";
67+
if (e is NotSupportedException && e.TargetSite?.Name == "DefineDynamicAssembly")
68+
info += " Reflection.Emit is not supported.";
69+
else
70+
info += $" of an unknown error.\r\n({e.ReflectionExToString()})";
71+
72+
ExplorerCore.LogWarning(info);
73+
74+
return false;
6875
}
6976
}
7077

src/UI/Main/Home/HomePage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class HomePage : BaseMenuPage
1313

1414
public static HomePage Instance { get; internal set; }
1515

16-
public override void Init()
16+
public override bool Init()
1717
{
1818
Instance = this;
1919

@@ -24,6 +24,8 @@ public override void Init()
2424
new InspectorManager();
2525

2626
SceneExplorer.Instance.Init();
27+
28+
return true;
2729
}
2830

2931
public override void Update()

src/UI/Main/MainMenu.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ public MainMenu()
4949
for (int i = 0; i < Pages.Count; i++)
5050
{
5151
var page = Pages[i];
52-
page.Init();
53-
54-
if (!Pages.Contains(page))
52+
53+
if (!page.Init())
54+
{
55+
// page init failed.
56+
Pages.RemoveAt(i);
5557
i--;
58+
59+
if (page.RefNavbarButton)
60+
page.RefNavbarButton.interactable = false;
61+
62+
if (page.Content)
63+
GameObject.Destroy(page.Content);
64+
}
5665
}
5766

5867
// hide menu until each page has init layout (bit of a hack)

src/UI/Main/Options/OptionsPage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public class OptionsPage : BaseMenuPage
1818
private InputField m_defaultOutputInput;
1919
private Toggle m_hideOnStartupToggle;
2020

21-
public override void Init()
21+
public override bool Init()
2222
{
2323
ConstructUI();
24+
25+
return true;
2426
}
2527

2628
public override void Update()

src/UI/Main/Search/SearchPage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public SearchPage()
5555
Instance = this;
5656
}
5757

58-
public override void Init()
58+
public override bool Init()
5959
{
6060
ConstructUI();
61+
62+
return true;
6163
}
6264

6365
public void OnSceneChange()

0 commit comments

Comments
 (0)