diff --git a/src/Core/Utility/IOUtility.cs b/src/Core/Utility/IOUtility.cs index 3e6fdda..2904e5a 100644 --- a/src/Core/Utility/IOUtility.cs +++ b/src/Core/Utility/IOUtility.cs @@ -13,7 +13,12 @@ namespace UnityExplorer public static string EnsureValidDirectory(string path) { - return string.Concat(path.Split(invalidDirectoryCharacters)); + path = string.Concat(path.Split(invalidDirectoryCharacters)); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + return path; } public static string EnsureValidFilename(string filename) diff --git a/src/UI/CSConsole/ConsoleController.cs b/src/UI/CSConsole/ConsoleController.cs index 945dda3..9b786e5 100644 --- a/src/UI/CSConsole/ConsoleController.cs +++ b/src/UI/CSConsole/ConsoleController.cs @@ -227,8 +227,8 @@ namespace UnityExplorer.UI.CSConsole if (ScriptEvaluator._reportPrinter.ErrorsCount > 0) throw new FormatException($"Unable to compile the code. Evaluator's last output was:\r\n{output}"); - if (!supressLog) - ExplorerCore.Log("Code executed successfully."); + //if (!supressLog) + // ExplorerCore.Log("Code executed successfully."); } catch (FormatException fex) { diff --git a/src/UI/CSConsole/ScriptInteraction.cs b/src/UI/CSConsole/ScriptInteraction.cs index cbeca00..52c77e9 100644 --- a/src/UI/CSConsole/ScriptInteraction.cs +++ b/src/UI/CSConsole/ScriptInteraction.cs @@ -5,33 +5,34 @@ using UnityEngine; using System.Collections.Generic; using System.Linq; using UnityExplorer.Core.Runtime; +using System.Text; namespace UnityExplorer.UI.CSConsole { public class ScriptInteraction : InteractiveBase { - internal const string STARTUP_TEXT = @"Welcome to the UnityExplorer C# Console. + internal const string STARTUP_TEXT = @"// Compile a using directive to add it to the console (until Reset) +using SomeNamespace; -Use this console to declare temporary C# classes, or evaluate standalone expressions as though you were executing a method body. "+ -@"Use the Reset button to clear all classes and variables, and restore the default using directives. +// Compile a C# class and it will exist until Reset +public class SomeClass { + public static void SomeMethod() { + } +} -* using SomeNamespace; to add a namespace to the Console. This is not required if you use full namespaces to access classes. - -When evaluating standalone expressions, these helpers are available: - -* System.Object CurrentTarget - the target of the active Inspector tab - -* System.Object[] AllTargets - an array containing the targets of all Inspector tabs - -* void Log(""message"") - logs a message to the console log +// If not compiling any usings or classes, the code will run immediately (REPL). +// Variables you define in REPL mode will also exist until Reset. +// In REPL context, the following helpers are available: +* System.Object CurrentTarget - the target of the active Inspector tab +* System.Object[] AllTargets - an array containing the targets of all Inspector tabs +* void Log(""message"") - prints a message to the console log * void Inspect(someObject) - inspect an instance, eg. Inspect(Camera.main); - * void Inspect(typeof(SomeClass)) - inspect a Class with static reflection - * void StartCoroutine(ienumerator) - start the IEnumerator as a Coroutine - -"; +* void GetUsing() - prints the current using directives to the console log +* void GetVars() - prints the variables you have defined and their current values +* void GetClasses() - prints the names of the classes you have defined, and their members"; public static void Log(object message) { @@ -56,5 +57,36 @@ When evaluating standalone expressions, these helpers are available: { RuntimeProvider.Instance.StartCoroutine(ienumerator); } + + public static void GetUsing() + { + Log(Evaluator.GetUsing()); + } + + public static void GetVars() + { + Log(Evaluator.GetVars()); + } + + public static void GetClasses() + { + if (ReflectionUtility.GetFieldInfo(typeof(Evaluator), "source_file") + .GetValue(Evaluator) is CompilationSourceFile sourceFile + && sourceFile.Containers.Any()) + { + var sb = new StringBuilder(); + sb.Append($"There are {sourceFile.Containers.Count} defined classes:"); + foreach (TypeDefinition type in sourceFile.Containers.Where(it => it is TypeDefinition)) + { + sb.Append($"\n\n{type.MemberName.Name}:"); + foreach (var member in type.Members) + sb.Append($"\n\t- {member.AttributeTargets}: \"{member.MemberName.Name}\" ({member.ModFlags})"); + } + Log(sb.ToString()); + } + else + ExplorerCore.LogWarning("No classes seem to be defined."); + + } } } \ No newline at end of file diff --git a/src/UI/IValues/InteractiveColor.cs b/src/UI/IValues/InteractiveColor.cs index 4a38d0c..3778b49 100644 --- a/src/UI/IValues/InteractiveColor.cs +++ b/src/UI/IValues/InteractiveColor.cs @@ -155,12 +155,6 @@ namespace UnityExplorer.UI.IValues var horiGroup = UIFactory.CreateHorizontalGroup(UIRoot, "ColorEditor", false, false, true, true, 5, default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft); - // apply button - - m_applyButton = UIFactory.CreateButton(horiGroup, "ApplyButton", "Apply", new Color(0.2f, 0.26f, 0.2f)); - UIFactory.SetLayoutElement(m_applyButton.Component.gameObject, minHeight: 25, minWidth: 90); - m_applyButton.OnClick += SetValueToOwner; - // sliders / inputs var grid = UIFactory.CreateGridGroup(horiGroup, "Grid", new Vector2(140, 25), new Vector2(2, 2), new Color(1, 1, 1, 0)); @@ -169,6 +163,12 @@ namespace UnityExplorer.UI.IValues for (int i = 0; i < 4; i++) AddEditorRow(i, grid); + // apply button + + m_applyButton = UIFactory.CreateButton(horiGroup, "ApplyButton", "Apply", new Color(0.2f, 0.26f, 0.2f)); + UIFactory.SetLayoutElement(m_applyButton.Component.gameObject, minHeight: 25, minWidth: 90); + m_applyButton.OnClick += SetValueToOwner; + // image of color var imgObj = UIFactory.CreateUIObject("ColorImageHelper", horiGroup); diff --git a/src/UI/Panels/CSConsolePanel.cs b/src/UI/Panels/CSConsolePanel.cs index d40538c..944ae25 100644 --- a/src/UI/Panels/CSConsolePanel.cs +++ b/src/UI/Panels/CSConsolePanel.cs @@ -15,7 +15,7 @@ namespace UnityExplorer.UI.Panels { public override string Name => "C# Console"; public override UIManager.Panels PanelType => UIManager.Panels.CSConsole; - public override int MinWidth => 400; + public override int MinWidth => 750; public override int MinHeight => 300; public InputFieldScroller InputScroll { get; private set; } @@ -62,36 +62,29 @@ namespace UnityExplorer.UI.Panels { mainPanelRect.localPosition = Vector2.zero; mainPanelRect.pivot = new Vector2(0f, 1f); - mainPanelRect.anchorMin = new Vector2(0.4f, 0.1f); - mainPanelRect.anchorMax = new Vector2(0.9f, 0.85f); + mainPanelRect.anchorMin = new Vector2(0.4f, 0.175f); + mainPanelRect.anchorMax = new Vector2(0.85f, 0.925f); } public override void ConstructPanelContent() { - #region TOP BAR + // Tools Row - // Main group object - - var topBarObj = UIFactory.CreateHorizontalGroup(this.content, "TopBar", true, true, true, true, 10, new Vector4(8, 8, 30, 30), - default, TextAnchor.LowerCenter); - UIFactory.SetLayoutElement(topBarObj, minHeight: 50, flexibleHeight: 0); - - //// Top label - - //var topBarLabel = UIFactory.CreateLabel(topBarObj, "TopLabel", "C# Console", TextAnchor.MiddleLeft, default, true, 25); - //UIFactory.SetLayoutElement(topBarLabel.gameObject, preferredWidth: 150, flexibleWidth: 5000); + var toolsRow = UIFactory.CreateHorizontalGroup(this.content, "ToggleRow", false, false, true, true, 5, new Vector4(8, 8, 10, 5), + default, TextAnchor.MiddleLeft); + UIFactory.SetLayoutElement(toolsRow, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999); // Enable Ctrl+R toggle - var ctrlRToggleObj = UIFactory.CreateToggle(topBarObj, "CtrlRToggle", out var CtrlRToggle, out Text ctrlRToggleText); - UIFactory.SetLayoutElement(ctrlRToggleObj, minWidth: 140, flexibleWidth: 0, minHeight: 25); + var ctrlRToggleObj = UIFactory.CreateToggle(toolsRow, "CtrlRToggle", out var CtrlRToggle, out Text ctrlRToggleText); + UIFactory.SetLayoutElement(ctrlRToggleObj, minWidth: 150, flexibleWidth: 0, minHeight: 25); ctrlRToggleText.alignment = TextAnchor.UpperLeft; - ctrlRToggleText.text = "Run on Ctrl+R"; + ctrlRToggleText.text = "Compile on Ctrl+R"; CtrlRToggle.onValueChanged.AddListener((bool val) => { OnCtrlRToggled?.Invoke(val); }); // Enable Suggestions toggle - var suggestToggleObj = UIFactory.CreateToggle(topBarObj, "SuggestionToggle", out var SuggestionsToggle, out Text suggestToggleText); + var suggestToggleObj = UIFactory.CreateToggle(toolsRow, "SuggestionToggle", out var SuggestionsToggle, out Text suggestToggleText); UIFactory.SetLayoutElement(suggestToggleObj, minWidth: 120, flexibleWidth: 0, minHeight: 25); suggestToggleText.alignment = TextAnchor.UpperLeft; suggestToggleText.text = "Suggestions"; @@ -99,15 +92,25 @@ namespace UnityExplorer.UI.Panels // Enable Auto-indent toggle - var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, "IndentToggle", out var AutoIndentToggle, out Text autoIndentToggleText); + var autoIndentToggleObj = UIFactory.CreateToggle(toolsRow, "IndentToggle", out var AutoIndentToggle, out Text autoIndentToggleText); UIFactory.SetLayoutElement(autoIndentToggleObj, minWidth: 180, flexibleWidth: 0, minHeight: 25); autoIndentToggleText.alignment = TextAnchor.UpperLeft; autoIndentToggleText.text = "Auto-indent"; AutoIndentToggle.onValueChanged.AddListener((bool val) => { OnAutoIndentToggled?.Invoke(val); }); - #endregion + // Buttons - #region CONSOLE INPUT + var resetButton = UIFactory.CreateButton(toolsRow, "ResetButton", "Reset", new Color(0.33f, 0.33f, 0.33f)); + UIFactory.SetLayoutElement(resetButton.Component.gameObject, minHeight: 28, minWidth: 80, flexibleHeight: 0); + resetButton.ButtonText.fontSize = 15; + resetButton.OnClick += OnResetClicked; + + var compileButton = UIFactory.CreateButton(toolsRow, "CompileButton", "Compile", new Color(0.33f, 0.5f, 0.33f)); + UIFactory.SetLayoutElement(compileButton.Component.gameObject, minHeight: 28, minWidth: 130, flexibleHeight: 0); + compileButton.ButtonText.fontSize = 15; + compileButton.OnClick += OnCompileClicked; + + // Console Input int fontSize = 16; @@ -140,24 +143,6 @@ namespace UnityExplorer.UI.Panels Input.PlaceholderText.font = UIManager.ConsoleFont; HighlightText.font = UIManager.ConsoleFont; - #endregion - - #region COMPILE BUTTON BAR - - var horozGroupObj = UIFactory.CreateHorizontalGroup(this.content, "BigButtons", true, true, true, true, 0, new Vector4(2, 2, 2, 2), - new Color(1, 1, 1, 0)); - - var resetButton = UIFactory.CreateButton(horozGroupObj, "ResetButton", "Reset", new Color(0.33f, 0.33f, 0.33f)); - UIFactory.SetLayoutElement(resetButton.Component.gameObject, minHeight: 45, minWidth: 80, flexibleHeight: 0); - resetButton.ButtonText.fontSize = 18; - resetButton.OnClick += OnResetClicked; - - var compileButton = UIFactory.CreateButton(horozGroupObj, "CompileButton", "Compile", new Color(0.33f, 0.5f, 0.33f)); - UIFactory.SetLayoutElement(compileButton.Component.gameObject, minHeight: 45, minWidth: 80, flexibleHeight: 0); - compileButton.ButtonText.fontSize = 18; - compileButton.OnClick += OnCompileClicked; - - #endregion } } diff --git a/src/UI/Panels/InspectorPanel.cs b/src/UI/Panels/InspectorPanel.cs index befdc97..e51627f 100644 --- a/src/UI/Panels/InspectorPanel.cs +++ b/src/UI/Panels/InspectorPanel.cs @@ -19,7 +19,7 @@ namespace UnityExplorer.UI.Panels public override string Name => "Inspector"; public override UIManager.Panels PanelType => UIManager.Panels.Inspector; public override bool ShouldSaveActiveState => false; - public override int MinWidth => 625; + public override int MinWidth => 800; public override int MinHeight => 350; public GameObject NavbarHolder; diff --git a/src/UI/Panels/LogPanel.cs b/src/UI/Panels/LogPanel.cs index c9acb58..66b7a7c 100644 --- a/src/UI/Panels/LogPanel.cs +++ b/src/UI/Panels/LogPanel.cs @@ -11,6 +11,8 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Panels { + // TODO move the logic out of this class into a LogUtil class (also move ExplorerCore.Log into that) + public class LogPanel : UIPanel, ICellPoolDataSource { public struct LogInfo @@ -29,6 +31,8 @@ namespace UnityExplorer.UI.Panels public override int MinWidth => 300; public override int MinHeight => 75; + public override bool ShouldSaveActiveState => true; + public override bool ShowByDefault => true; public int ItemCount => Logs.Count; @@ -156,8 +160,8 @@ namespace UnityExplorer.UI.Panels { mainPanelRect.localPosition = Vector2.zero; mainPanelRect.pivot = new Vector2(0f, 1f); - mainPanelRect.anchorMin = new Vector2(0.5f, 0.1f); - mainPanelRect.anchorMax = new Vector2(0.9f, 0.25f); + mainPanelRect.anchorMin = new Vector2(0.5f, 0.03f); + mainPanelRect.anchorMax = new Vector2(0.9f, 0.2f); } // UI Construction diff --git a/src/UI/Panels/OptionsPanel.cs b/src/UI/Panels/OptionsPanel.cs index 2b9ab64..c813abc 100644 --- a/src/UI/Panels/OptionsPanel.cs +++ b/src/UI/Panels/OptionsPanel.cs @@ -11,12 +11,14 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Panels { + // TODO move the logic out of this class into ConfigManager + public class OptionsPanel : UIPanel, ICacheObjectController, ICellPoolDataSource { public override string Name => "Options"; public override UIManager.Panels PanelType => UIManager.Panels.Options; - public override int MinWidth => 550; + public override int MinWidth => 600; public override int MinHeight => 200; public override bool ShouldSaveActiveState => false;