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

Commit 604c499

Browse files
committed
Add Reset button to C# Console
1 parent 8964c48 commit 604c499

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
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.8";
20+
public const string VERSION = "3.2.9";
2121
public const string AUTHOR = "Sinai";
2222
public const string GUID = "com.sinai.unityexplorer";
2323

src/UI/Main/CSConsole/CSharpConsole.cs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UnityExplorer.UI.Reusable;
1313
using UnityExplorer.UI.Main.CSConsole;
1414
using UnityExplorer.Core;
15+
using UnityExplorer.Core.Unity;
1516
#if CPP
1617
using UnityExplorer.Core.Runtime.Il2Cpp;
1718
#endif
@@ -56,13 +57,10 @@ public override bool Init()
5657
DummyBehaviour.Setup();
5758
#endif
5859

59-
ResetConsole();
60+
ResetConsole(false);
6061
// Make sure compiler is supported on this platform
6162
Evaluator.Compile("");
6263

63-
foreach (string use in DefaultUsing)
64-
AddUsing(use);
65-
6664
return true;
6765
}
6866
catch (Exception e)
@@ -79,7 +77,7 @@ public override bool Init()
7977
}
8078
}
8179

82-
public void ResetConsole()
80+
public void ResetConsole(bool log = true)
8381
{
8482
if (Evaluator != null)
8583
Evaluator.Dispose();
@@ -89,14 +87,19 @@ public void ResetConsole()
8987
Evaluator = new ScriptEvaluator(new StringWriter(m_evalLogBuilder)) { InteractiveBaseClass = typeof(ScriptInteraction) };
9088

9189
UsingDirectives = new List<string>();
90+
91+
foreach (string use in DefaultUsing)
92+
AddUsing(use);
93+
94+
if (log)
95+
ExplorerCore.Log($"C# Console reset. Using directives:\r\n{Evaluator.GetUsing()}");
9296
}
9397

9498
public override void Update()
9599
{
96100
UpdateConsole();
97101

98102
AutoCompleter.Update();
99-
100103
#if CPP
101104
Il2CppCoroutine.Process();
102105
#endif
@@ -572,11 +575,40 @@ void SuggestToggleCallback(bool val)
572575
highlightTextInput.supportRichText = true;
573576
highlightTextInput.fontSize = fontSize;
574577

575-
#endregion
578+
#endregion
579+
580+
#region COMPILE BUTTON BAR
581+
582+
var horozGroupObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
583+
var horozGroup = horozGroupObj.GetComponent<HorizontalLayoutGroup>();
584+
horozGroup.padding.left = 2;
585+
horozGroup.padding.top = 2;
586+
horozGroup.padding.right = 2;
587+
horozGroup.padding.bottom = 2;
588+
589+
var resetBtnObj = UIFactory.CreateButton(horozGroupObj);
590+
var resetBtnLayout = resetBtnObj.AddComponent<LayoutElement>();
591+
resetBtnLayout.preferredWidth = 80;
592+
resetBtnLayout.flexibleWidth = 0;
593+
resetBtnLayout.minHeight = 45;
594+
resetBtnLayout.flexibleHeight = 0;
595+
var resetButton = resetBtnObj.GetComponent<Button>();
596+
var resetBtnColors = resetButton.colors;
597+
resetBtnColors.normalColor = "666666".ToColor();
598+
resetButton.colors = resetBtnColors;
599+
var resetBtnText = resetBtnObj.GetComponentInChildren<Text>();
600+
resetBtnText.text = "Reset";
601+
resetBtnText.fontSize = 18;
602+
resetBtnText.color = Color.white;
576603

577-
#region COMPILE BUTTON
604+
// Set compile button callback now that we have the Input Field reference
605+
resetButton.onClick.AddListener(ResetCallback);
606+
void ResetCallback()
607+
{
608+
ResetConsole();
609+
}
578610

579-
var compileBtnObj = UIFactory.CreateButton(Content);
611+
var compileBtnObj = UIFactory.CreateButton(horozGroupObj);
580612
var compileBtnLayout = compileBtnObj.AddComponent<LayoutElement>();
581613
compileBtnLayout.preferredWidth = 80;
582614
compileBtnLayout.flexibleWidth = 0;
@@ -601,7 +633,7 @@ void CompileCallback()
601633
}
602634
}
603635

604-
#endregion
636+
#endregion
605637

606638
//mainTextInput.supportRichText = false;
607639

0 commit comments

Comments
 (0)