* Created a TMP AssetBundle for games which don't have the default TextMeshPro Resources package. This also allows us to use a custom monospace font for the Console and Debug window.
* Unstripped the AssetBundle class (just the stuff we need)
* Finished Search Page
* Finished Options Page (very simple)
* Various refactoring and restructuring of the project
* cleanups
This commit is contained in:
sinaioutlander 2020-11-08 21:04:41 +11:00
parent 2efc3f6578
commit d038d13867
25 changed files with 1604 additions and 947 deletions

View File

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;
@ -8,24 +9,27 @@ namespace UnityExplorer.Config
{
[XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig));
[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\Explorer";
[XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml";
//[XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
[XmlIgnore] private const string SETTINGS_PATH = ExplorerCore.EXPLORER_FOLDER + @"\config.xml";
[XmlIgnore] public static ModConfig Instance;
// Actual configs
public KeyCode Main_Menu_Toggle = KeyCode.F7;
public Vector2 Default_Window_Size = new Vector2(550, 700);
public int Default_Page_Limit = 20;
public bool Bitwise_Support = false;
public bool Tab_View = true;
public string Default_Output_Path = @"Mods\Explorer";
public KeyCode Main_Menu_Toggle = KeyCode.F7;
public bool Force_Unlock_Mouse = true;
public int Default_Page_Limit = 20;
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER;
public bool Log_Unity_Debug = false;
public static event Action OnConfigChanged;
internal static void InvokeConfigChanged()
{
OnConfigChanged?.Invoke();
}
public static void OnLoad()
{
if (!Directory.Exists(EXPLORER_FOLDER))
Directory.CreateDirectory(EXPLORER_FOLDER);
if (LoadSettings())
return;
@ -33,20 +37,15 @@ namespace UnityExplorer.Config
SaveSettings();
}
// returns true if settings successfully loaded
public static bool LoadSettings()
{
if (!File.Exists(SETTINGS_PATH))
{
return false;
}
try
{
using (var file = File.OpenRead(SETTINGS_PATH))
{
Instance = (ModConfig)Serializer.Deserialize(file);
}
}
catch
{
@ -59,14 +58,10 @@ namespace UnityExplorer.Config
public static void SaveSettings()
{
if (File.Exists(SETTINGS_PATH))
{
File.Delete(SETTINGS_PATH);
}
using (var file = File.Create(SETTINGS_PATH))
{
Serializer.Serialize(file, Instance);
}
}
}
}

View File

@ -44,7 +44,7 @@ namespace UnityExplorer.Console
return;
}
if (!ConsolePage.EnableSuggestions)
if (!ConsolePage.EnableAutocompletes)
{
if (m_mainObj.activeSelf)
{
@ -267,7 +267,7 @@ namespace UnityExplorer.Console
{
var parent = UIManager.CanvasRoot;
var obj = UIFactory.CreateScrollView(parent, out GameObject content, new Color(0.1f, 0.1f, 0.1f, 0.95f));
var obj = UIFactory.CreateScrollView(parent, out GameObject content, out _, new Color(0.1f, 0.1f, 0.1f, 0.95f));
m_mainObj = obj;

View File

@ -9,6 +9,13 @@ using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.UI;
using UnityExplorer.UI.PageModel;
using System.Collections.Generic;
using System.Reflection;
#if CPP
using UnityExplorer.Unstrip.Resources;
using UnityExplorer.Helpers;
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.Console
{
@ -16,19 +23,19 @@ namespace UnityExplorer.Console
{
private readonly InputLexer inputLexer = new InputLexer();
public TMP_InputField InputField { get; }
public TMP_InputField InputField { get; internal set; }
public readonly TextMeshProUGUI inputText;
private readonly TextMeshProUGUI inputHighlightText;
private readonly TextMeshProUGUI lineText;
private readonly Image background;
private readonly Image lineHighlight;
private readonly Image lineNumberBackground;
private readonly Image scrollbar;
public TextMeshProUGUI inputText;
private TextMeshProUGUI inputHighlightText;
private TextMeshProUGUI lineText;
private Image background;
private Image lineNumberBackground;
private Image scrollbar;
private bool lineHighlightLocked;
private readonly RectTransform inputTextTransform;
private readonly RectTransform lineHighlightTransform;
//private readonly RectTransform inputTextTransform;
//private readonly RectTransform lineHighlightTransform;
//private bool lineHighlightLocked;
//private Image lineHighlight;
public int LineCount { get; private set; }
public int CurrentLine { get; private set; }
@ -66,27 +73,38 @@ namespace UnityExplorer.Console
}
}
public CodeEditor(TMP_InputField inputField, TextMeshProUGUI inputText, TextMeshProUGUI inputHighlightText, TextMeshProUGUI lineText,
Image background, Image lineHighlight, Image lineNumberBackground, Image scrollbar)
internal const string STARTUP_TEXT = @"Welcome to the UnityExplorer C# Console.
The following helper methods are available:
* <color=#add490>Log(""message"")</color> logs a message to the debug console
* <color=#add490>CurrentTarget()</color> returns the currently inspected target on the Home page
* <color=#add490>AllTargets()</color> returns an object[] array containing all inspected instances
* <color=#add490>Inspect(someObject)</color> to inspect an instance, eg. Inspect(Camera.main);
* <color=#add490>Inspect(typeof(SomeClass))</color> to inspect a Class with static reflection
* <color=#add490>AddUsing(""SomeNamespace"")</color> adds a using directive to the C# console
* <color=#add490>GetUsing()</color> logs the current using directives to the debug console
* <color=#add490>Reset()</color> resets all using directives and variables
";
public CodeEditor()
{
InputField = inputField;
this.inputText = inputText;
this.inputHighlightText = inputHighlightText;
this.lineText = lineText;
this.background = background;
this.lineHighlight = lineHighlight;
this.lineNumberBackground = lineNumberBackground;
this.scrollbar = scrollbar;
ConstructUI();
if (!AllReferencesAssigned())
{
throw new Exception("References are missing!");
}
InputField.restoreOriginalTextOnEscape = false;
inputTextTransform = inputText.GetComponent<RectTransform>();
lineHighlightTransform = lineHighlight.GetComponent<RectTransform>();
//inputTextTransform = inputText.GetComponent<RectTransform>();
//lineHighlightTransform = lineHighlight.GetComponent<RectTransform>();
ApplyTheme();
inputLexer.UseMatchers(CSharpLexer.DelimiterSymbols, CSharpLexer.Matchers);
@ -124,7 +142,7 @@ namespace UnityExplorer.Console
// Update line highlight
if (focusKeyPressed || InputManager.GetMouseButton(0))
{
UpdateHighlight();
//UpdateHighlight();
ConsolePage.Instance.OnInputChanged();
}
}
@ -146,25 +164,26 @@ namespace UnityExplorer.Console
}
UpdateLineNumbers();
UpdateHighlight();
//UpdateHighlight();
ConsolePage.Instance.OnInputChanged();
}
public void SetLineHighlight(int lineNumber, bool lockLineHighlight)
{
if (lineNumber < 1 || lineNumber > LineCount)
{
return;
}
//public void SetLineHighlight(int lineNumber, bool lockLineHighlight)
//{
// if (lineNumber < 1 || lineNumber > LineCount)
// {
// return;
// }
lineHighlightTransform.anchoredPosition = new Vector2(5,
(inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight *
-(lineNumber - 1)) - 4f +
inputTextTransform.anchoredPosition.y);
// lineHighlightTransform.anchoredPosition = new Vector2(5,
// (inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight *
// //-(lineNumber - 1)) - 4f +
// -(lineNumber - 1)) +
// inputTextTransform.anchoredPosition.y);
lineHighlightLocked = lockLineHighlight;
}
// lineHighlightLocked = lockLineHighlight;
//}
private void UpdateLineNumbers()
{
@ -268,28 +287,28 @@ namespace UnityExplorer.Console
}
}
private void UpdateHighlight()
{
if (lineHighlightLocked)
{
return;
}
//private void UpdateHighlight()
//{
// if (lineHighlightLocked)
// {
// return;
// }
try
{
int caret = InputField.caretPosition - 1;
// try
// {
// int caret = InputField.caretPosition - 1;
float lineHeight = inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight;
int lineNumber = inputText.textInfo.characterInfo[caret].lineNumber;
float offset = lineNumber + inputTextTransform.anchoredPosition.y;
// float lineHeight = inputText.textInfo.lineInfo[inputText.textInfo.characterInfo[0].lineNumber].lineHeight;
// int lineNumber = inputText.textInfo.characterInfo[caret].lineNumber;
// float offset = lineNumber + inputTextTransform.anchoredPosition.y;
lineHighlightTransform.anchoredPosition = new Vector2(5, -(offset * lineHeight));
}
catch //(Exception e)
{
//ExplorerCore.LogWarning("Exception on Update Line Highlight: " + e);
}
}
// lineHighlightTransform.anchoredPosition = new Vector2(5, -(offset * lineHeight));
// }
// catch //(Exception e)
// {
// //ExplorerCore.LogWarning("Exception on Update Line Highlight: " + e);
// }
//}
private const string CLOSE_COLOR_TAG = "</color>";
@ -397,6 +416,8 @@ namespace UnityExplorer.Console
return tab;
}
// ============== Theme ============== //
private static Color caretColor = new Color32(255, 255, 255, 255);
private static Color textColor = new Color32(255, 255, 255, 255);
private static Color backgroundColor = new Color32(37, 37, 37, 255);
@ -417,7 +438,7 @@ namespace UnityExplorer.Console
inputText.color = textColor;
inputHighlightText.color = textColor;
background.color = backgroundColor;
lineHighlight.color = lineHighlightColor;
//lineHighlight.color = lineHighlightColor;
lineNumberBackground.color = lineNumberBackgroundColor;
lineText.color = lineNumberTextColor;
scrollbar.color = scrollbarColor;
@ -430,7 +451,7 @@ namespace UnityExplorer.Console
!inputHighlightText ||
!lineText ||
!background ||
!lineHighlight ||
//!lineHighlight ||
!lineNumberBackground ||
!scrollbar)
{
@ -439,5 +460,341 @@ namespace UnityExplorer.Console
}
return true;
}
// ========== UI CONSTRUCTION =========== //
public void ConstructUI()
{
ConsolePage.Instance.Content = UIFactory.CreateUIObject("C# Console", MainMenu.Instance.PageViewport);
var mainLayout = ConsolePage.Instance.Content.AddComponent<LayoutElement>();
mainLayout.preferredHeight = 9900;
mainLayout.flexibleHeight = 9000;
var mainGroup = ConsolePage.Instance.Content.AddComponent<VerticalLayoutGroup>();
mainGroup.childControlHeight = true;
mainGroup.childControlWidth = true;
mainGroup.childForceExpandHeight = true;
mainGroup.childForceExpandWidth = true;
#region TOP BAR
// Main group object
var topBarObj = UIFactory.CreateHorizontalGroup(ConsolePage.Instance.Content);
LayoutElement topBarLayout = topBarObj.AddComponent<LayoutElement>();
topBarLayout.minHeight = 50;
topBarLayout.flexibleHeight = 0;
var topBarGroup = topBarObj.GetComponent<HorizontalLayoutGroup>();
topBarGroup.padding.left = 30;
topBarGroup.padding.right = 30;
topBarGroup.padding.top = 8;
topBarGroup.padding.bottom = 8;
topBarGroup.spacing = 10;
topBarGroup.childForceExpandHeight = true;
topBarGroup.childForceExpandWidth = true;
topBarGroup.childControlWidth = true;
topBarGroup.childControlHeight = true;
topBarGroup.childAlignment = TextAnchor.LowerCenter;
var topBarLabel = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft);
var topBarLabelLayout = topBarLabel.AddComponent<LayoutElement>();
topBarLabelLayout.preferredWidth = 800;
topBarLabelLayout.flexibleWidth = 10;
var topBarText = topBarLabel.GetComponent<Text>();
topBarText.text = "C# Console";
topBarText.fontSize = 20;
// Enable Suggestions toggle
var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText);
#if CPP
suggestToggle.onValueChanged.AddListener(new Action<bool>(SuggestToggleCallback));
#else
suggestToggle.onValueChanged.AddListener(SuggestToggleCallback);
#endif
void SuggestToggleCallback(bool val)
{
ConsolePage.EnableAutocompletes = val;
AutoCompleter.Update();
}
suggestToggleText.text = "Suggestions";
suggestToggleText.alignment = TextAnchor.UpperLeft;
var suggestTextPos = suggestToggleText.transform.localPosition;
suggestTextPos.y = -14;
suggestToggleText.transform.localPosition = suggestTextPos;
var suggestLayout = suggestToggleObj.AddComponent<LayoutElement>();
suggestLayout.minWidth = 120;
suggestLayout.flexibleWidth = 0;
var suggestRect = suggestToggleObj.transform.Find("Background");
var suggestPos = suggestRect.localPosition;
suggestPos.y = -14;
suggestRect.localPosition = suggestPos;
// Enable Auto-indent toggle
var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle autoIndentToggle, out Text autoIndentToggleText);
#if CPP
autoIndentToggle.onValueChanged.AddListener(new Action<bool>(OnIndentChanged));
#else
autoIndentToggle.onValueChanged.AddListener(OnIndentChanged);
#endif
void OnIndentChanged(bool val) => ConsolePage.EnableAutoIndent = val;
autoIndentToggleText.text = "Auto-indent";
autoIndentToggleText.alignment = TextAnchor.UpperLeft;
var autoIndentTextPos = autoIndentToggleText.transform.localPosition;
autoIndentTextPos.y = -14;
autoIndentToggleText.transform.localPosition = autoIndentTextPos;
var autoIndentLayout = autoIndentToggleObj.AddComponent<LayoutElement>();
autoIndentLayout.minWidth = 120;
autoIndentLayout.flexibleWidth = 0;
var autoIndentRect = autoIndentToggleObj.transform.Find("Background");
suggestPos = autoIndentRect.localPosition;
suggestPos.y = -14;
autoIndentRect.localPosition = suggestPos;
#endregion
#region CONSOLE INPUT
var consoleBase = UIFactory.CreateUIObject("CodeEditor", ConsolePage.Instance.Content);
var consoleLayout = consoleBase.AddComponent<LayoutElement>();
consoleLayout.preferredHeight = 500;
consoleLayout.flexibleHeight = 50;
consoleBase.AddComponent<RectMask2D>();
var mainRect = consoleBase.GetComponent<RectTransform>();
mainRect.pivot = Vector2.one * 0.5f;
mainRect.anchorMin = Vector2.zero;
mainRect.anchorMax = Vector2.one;
mainRect.offsetMin = Vector2.zero;
mainRect.offsetMax = Vector2.zero;
var mainBg = UIFactory.CreateUIObject("MainBackground", consoleBase);
var mainBgRect = mainBg.GetComponent<RectTransform>();
mainBgRect.pivot = new Vector2(0, 1);
mainBgRect.anchorMin = Vector2.zero;
mainBgRect.anchorMax = Vector2.one;
mainBgRect.offsetMin = Vector2.zero;
mainBgRect.offsetMax = Vector2.zero;
var mainBgImage = mainBg.AddComponent<Image>();
//var lineHighlight = UIFactory.CreateUIObject("LineHighlight", consoleBase);
//var lineHighlightRect = lineHighlight.GetComponent<RectTransform>();
//lineHighlightRect.pivot = new Vector2(0.5f, 1);
//lineHighlightRect.anchorMin = new Vector2(0, 1);
//lineHighlightRect.anchorMax = new Vector2(1, 1);
//lineHighlightRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 21);
//var lineHighlightImage = lineHighlight.GetComponent<Image>();
//if (!lineHighlightImage)
//{
// lineHighlightImage = lineHighlight.AddComponent<Image>();
//}
var linesBg = UIFactory.CreateUIObject("LinesBackground", consoleBase);
var linesBgRect = linesBg.GetComponent<RectTransform>();
linesBgRect.anchorMin = Vector2.zero;
linesBgRect.anchorMax = new Vector2(0, 1);
linesBgRect.offsetMin = new Vector2(-17.5f, 0);
linesBgRect.offsetMax = new Vector2(17.5f, 0);
linesBgRect.sizeDelta = new Vector2(65, 0);
var linesBgImage = linesBg.AddComponent<Image>();
var inputObj = UIFactory.CreateTMPInput(consoleBase);
var inputField = inputObj.GetComponent<TMP_InputField>();
inputField.richText = false;
inputField.restoreOriginalTextOnEscape = false;
var inputRect = inputObj.GetComponent<RectTransform>();
inputRect.pivot = new Vector2(0.5f, 0.5f);
inputRect.anchorMin = Vector2.zero;
inputRect.anchorMax = new Vector2(0.92f, 1);
inputRect.offsetMin = new Vector2(20, 0);
inputRect.offsetMax = new Vector2(14, 0);
inputRect.anchoredPosition = new Vector2(40, 0);
var textAreaObj = inputObj.transform.Find("TextArea");
var textAreaRect = textAreaObj.GetComponent<RectTransform>();
textAreaRect.pivot = new Vector2(0.5f, 0.5f);
textAreaRect.anchorMin = Vector2.zero;
textAreaRect.anchorMax = Vector2.one;
var mainTextObj = textAreaObj.transform.Find("Text");
var mainTextRect = mainTextObj.GetComponent<RectTransform>();
mainTextRect.pivot = new Vector2(0.5f, 0.5f);
mainTextRect.anchorMin = Vector2.zero;
mainTextRect.anchorMax = Vector2.one;
mainTextRect.offsetMin = Vector2.zero;
mainTextRect.offsetMax = Vector2.zero;
var mainTextInput = mainTextObj.GetComponent<TextMeshProUGUI>();
//mainTextInput.fontSize = 18;
var placeHolderText = textAreaObj.transform.Find("Placeholder").GetComponent<TextMeshProUGUI>();
placeHolderText.text = CodeEditor.STARTUP_TEXT;
var linesTextObj = UIFactory.CreateUIObject("LinesText", mainTextObj.gameObject);
var linesTextRect = linesTextObj.GetComponent<RectTransform>();
var linesTextInput = linesTextObj.AddComponent<TextMeshProUGUI>();
linesTextInput.fontSize = 18;
var highlightTextObj = UIFactory.CreateUIObject("HighlightText", mainTextObj.gameObject);
var highlightTextRect = highlightTextObj.GetComponent<RectTransform>();
highlightTextRect.anchorMin = Vector2.zero;
highlightTextRect.anchorMax = Vector2.one;
highlightTextRect.offsetMin = Vector2.zero;
highlightTextRect.offsetMax = Vector2.zero;
var highlightTextInput = highlightTextObj.AddComponent<TextMeshProUGUI>();
//highlightTextInput.fontSize = 18;
var scroll = UIFactory.CreateScrollbar(consoleBase);
var scrollRect = scroll.GetComponent<RectTransform>();
scrollRect.anchorMin = new Vector2(1, 0);
scrollRect.anchorMax = new Vector2(1, 1);
scrollRect.pivot = new Vector2(0.5f, 1);
scrollRect.offsetMin = new Vector2(-25f, 0);
var scroller = scroll.GetComponent<Scrollbar>();
scroller.direction = Scrollbar.Direction.TopToBottom;
var scrollColors = scroller.colors;
scrollColors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
scroller.colors = scrollColors;
var scrollImage = scroll.GetComponent<Image>();
var tmpInput = inputObj.GetComponent<TMP_InputField>();
tmpInput.scrollSensitivity = 15;
tmpInput.verticalScrollbar = scroller;
// set lines text anchors here after UI is fleshed out
linesTextRect.pivot = Vector2.zero;
linesTextRect.anchorMin = new Vector2(0, 0);
linesTextRect.anchorMax = new Vector2(1, 1);
linesTextRect.offsetMin = Vector2.zero;
linesTextRect.offsetMax = Vector2.zero;
linesTextRect.anchoredPosition = new Vector2(-40, 0);
tmpInput.GetComponentInChildren<RectMask2D>().enabled = false;
inputObj.GetComponent<Image>().enabled = false;
#endregion
#region COMPILE BUTTON
var compileBtnObj = UIFactory.CreateButton(ConsolePage.Instance.Content);
var compileBtnLayout = compileBtnObj.AddComponent<LayoutElement>();
compileBtnLayout.preferredWidth = 80;
compileBtnLayout.flexibleWidth = 0;
compileBtnLayout.minHeight = 45;
compileBtnLayout.flexibleHeight = 0;
var compileButton = compileBtnObj.GetComponent<Button>();
var compileBtnColors = compileButton.colors;
compileBtnColors.normalColor = new Color(14f / 255f, 80f / 255f, 14f / 255f);
compileButton.colors = compileBtnColors;
var btnText = compileBtnObj.GetComponentInChildren<Text>();
btnText.text = "Run";
btnText.fontSize = 18;
btnText.color = Color.white;
// Set compile button callback now that we have the Input Field reference
#if CPP
compileButton.onClick.AddListener(new Action(CompileCallback));
#else
compileButton.onClick.AddListener(CompileCallback);
#endif
void CompileCallback()
{
if (!string.IsNullOrEmpty(tmpInput.text))
{
ConsolePage.Instance.Evaluate(tmpInput.text.Trim());
}
}
#endregion
#region FONT
TMP_FontAsset fontToUse = UIManager.ConsoleFont;
if (fontToUse == null)
{
#if CPP
UnityEngine.Object[] fonts = ResourcesUnstrip.FindObjectsOfTypeAll(Il2CppType.Of<TMP_FontAsset>());
foreach (UnityEngine.Object font in fonts)
{
TMP_FontAsset fontCast = font.Il2CppCast(typeof(TMP_FontAsset)) as TMP_FontAsset;
if (fontCast.name.Contains("LiberationSans"))
{
fontToUse = fontCast;
break;
}
}
#else
var fonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (var font in fonts)
{
if (font.name.Contains("LiberationSans"))
{
fontToUse = font;
break;
}
}
#endif
}
if (fontToUse != null)
{
UnityEngine.TextCore.FaceInfo faceInfo = fontToUse.faceInfo;
fontToUse.tabSize = 10;
faceInfo.tabWidth = 10;
#if CPP
fontToUse.faceInfo = faceInfo;
#else
typeof(TMP_FontAsset)
.GetField("m_FaceInfo", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(fontToUse, faceInfo);
#endif
tmpInput.fontAsset = fontToUse;
mainTextInput.font = fontToUse;
mainTextInput.fontSize = 18;
highlightTextInput.font = fontToUse;
highlightTextInput.fontSize = 18;
}
#endregion
// assign references
this.InputField = inputField;
this.inputText = mainTextInput;
this.inputHighlightText = highlightTextInput;
this.lineText = linesTextInput;
this.background = mainBgImage;
//this.lineHighlight = lineHighlightImage;
this.lineNumberBackground = linesBgImage;
this.scrollbar = scrollImage;
}
}
}

View File

@ -5,6 +5,7 @@ using UnityExplorer.UI;
using UnityExplorer.UI.PageModel;
using UnityEngine;
using UnityExplorer.Inspectors;
using System.IO;
namespace UnityExplorer
{
@ -28,6 +29,8 @@ namespace UnityExplorer
"BepInEx";
#endif
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
public static ExplorerCore Instance { get; private set; }
public static bool ShowMenu
@ -50,6 +53,9 @@ namespace UnityExplorer
Instance = this;
if (!Directory.Exists(EXPLORER_FOLDER))
Directory.CreateDirectory(EXPLORER_FOLDER);
ModConfig.OnLoad();
InputManager.Init();
@ -99,7 +105,7 @@ namespace UnityExplorer
if (ShowMenu)
{
ForceUnlockCursor.Update();
//ForceUnlockCursor.Update();
UIManager.Update();
}
}
@ -140,14 +146,14 @@ namespace UnityExplorer
{
case LogType.Assert:
case LogType.Log:
Log(message);
Log(message, true);
break;
case LogType.Warning:
LogWarning(message);
LogWarning(message, true);
break;
case LogType.Exception:
case LogType.Error:
LogError(message);
LogError(message, true);
break;
}
}

View File

@ -28,7 +28,7 @@ namespace UnityExplorer.Helpers
public static string ToStringLong(this Vector3 vec)
{
return $"X: {vec.x:F3}, Y: {vec.y:F3}, Z: {vec.z:F3}";
return $"{vec.x:F3}, {vec.y:F3}, {vec.z:F3}";
}
public static string GetTransformPath(this Transform t, bool includeThisName = false)

View File

@ -141,20 +141,20 @@ namespace UnityExplorer.Inspectors.GOInspector
var childTitleLayout = childTitleObj.AddComponent<LayoutElement>();
childTitleLayout.minHeight = 30;
s_childListPageHandler = new PageHandler();
s_childListPageHandler.ConstructUI(vertGroupObj);
s_childListPageHandler.OnPageChanged += OnChildListPageTurn;
var childrenScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_childListContent, new Color(0.07f, 0.07f, 0.07f));
var childrenScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_childListContent, out SliderScrollbar scroller, new Color(0.07f, 0.07f, 0.07f));
var contentLayout = childrenScrollObj.GetComponent<LayoutElement>();
contentLayout.minHeight = 50;
s_childListPageHandler = new PageHandler(scroller);
s_childListPageHandler.ConstructUI(vertGroupObj);
s_childListPageHandler.OnPageChanged += OnChildListPageTurn;
}
internal void AddChildListButton()
{
int thisIndex = s_childListTexts.Count;
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_childListContent, new Color(0.1f, 0.1f, 0.1f));
GameObject btnGroupObj = UIFactory.CreateHorizontalGroup(s_childListContent, new Color(0.07f, 0.07f, 0.07f));
HorizontalLayoutGroup btnGroup = btnGroupObj.GetComponent<HorizontalLayoutGroup>();
btnGroup.childForceExpandWidth = true;
btnGroup.childControlWidth = true;
@ -170,8 +170,8 @@ namespace UnityExplorer.Inspectors.GOInspector
LayoutElement mainBtnLayout = mainButtonObj.AddComponent<LayoutElement>();
mainBtnLayout.minHeight = 25;
mainBtnLayout.flexibleHeight = 0;
mainBtnLayout.minWidth = 240;
mainBtnLayout.flexibleWidth = 0;
mainBtnLayout.minWidth = 25;
mainBtnLayout.flexibleWidth = 999;
Button mainBtn = mainButtonObj.GetComponent<Button>();
ColorBlock mainColors = mainBtn.colors;
mainColors.normalColor = new Color(0.07f, 0.07f, 0.07f);

View File

@ -155,13 +155,13 @@ namespace UnityExplorer.Inspectors.GOInspector
var childTitleLayout = compTitleObj.AddComponent<LayoutElement>();
childTitleLayout.minHeight = 30;
s_compListPageHandler = new PageHandler();
s_compListPageHandler.ConstructUI(vertGroupObj);
s_compListPageHandler.OnPageChanged += OnCompListPageTurn;
var compScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_compListContent, new Color(0.07f, 0.07f, 0.07f));
var compScrollObj = UIFactory.CreateScrollView(vertGroupObj, out s_compListContent, out SliderScrollbar scroller, new Color(0.07f, 0.07f, 0.07f));
var contentLayout = compScrollObj.AddComponent<LayoutElement>();
contentLayout.minHeight = 50;
s_compListPageHandler = new PageHandler(scroller);
s_compListPageHandler.ConstructUI(vertGroupObj);
s_compListPageHandler.OnPageChanged += OnCompListPageTurn;
}
internal void AddCompListButton()

View File

@ -424,6 +424,8 @@ namespace UnityExplorer.Inspectors.GOInspector
var valueInputObj = UIFactory.CreateTMPInput(topBarObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
var valueInput = valueInputObj.GetComponent<TMP_InputField>();
valueInput.readOnly = true;
valueInput.richText = true;
valueInput.isRichTextEditingAllowed = true;
var valueInputLayout = valueInputObj.AddComponent<LayoutElement>();
valueInputLayout.minHeight = 25;
valueInputLayout.flexibleHeight = 0;
@ -509,12 +511,16 @@ namespace UnityExplorer.Inspectors.GOInspector
// Slider
var sliderObj = UIFactory.CreateSlider(rowObject);
sliderObj.transform.Find("Fill Area").gameObject.SetActive(false);
var sliderLayout = sliderObj.AddComponent<LayoutElement>();
sliderLayout.minHeight = 20;
sliderLayout.flexibleHeight = 0;
sliderLayout.minWidth = 200;
sliderLayout.flexibleWidth = 9000;
var slider = sliderObj.GetComponent<Slider>();
var sliderColors = slider.colors;
sliderColors.normalColor = new Color(0.65f, 0.65f, 0.65f);
slider.colors = sliderColors;
slider.minValue = -2;
slider.maxValue = 2;
slider.value = 0;
@ -578,7 +584,11 @@ namespace UnityExplorer.Inspectors.GOInspector
var instantiateBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var instantiateBtn = instantiateBtnObj.GetComponent<Button>();
#if MONO
instantiateBtn.onClick.AddListener(InstantiateBtn);
#else
instantiateBtn.onClick.AddListener(new Action(InstantiateBtn));
#endif
var instantiateText = instantiateBtnObj.GetComponentInChildren<Text>();
instantiateText.text = "Instantiate";
instantiateText.fontSize = 14;
@ -597,7 +607,11 @@ namespace UnityExplorer.Inspectors.GOInspector
var dontDestroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var dontDestroyBtn = dontDestroyBtnObj.GetComponent<Button>();
#if MONO
dontDestroyBtn.onClick.AddListener(DontDestroyOnLoadBtn);
#else
dontDestroyBtn.onClick.AddListener(new Action(DontDestroyOnLoadBtn));
#endif
var dontDestroyText = dontDestroyBtnObj.GetComponentInChildren<Text>();
dontDestroyText.text = "Set DontDestroyOnLoad";
dontDestroyText.fontSize = 14;
@ -615,7 +629,11 @@ namespace UnityExplorer.Inspectors.GOInspector
var destroyBtnObj = UIFactory.CreateButton(bottomRow, new Color(0.2f, 0.2f, 0.2f));
var destroyBtn = destroyBtnObj.GetComponent<Button>();
#if MONO
destroyBtn.onClick.AddListener(DestroyBtn);
#else
destroyBtn.onClick.AddListener(new Action(DestroyBtn));
#endif
var destroyText = destroyBtnObj.GetComponentInChildren<Text>();
destroyText.text = "Destroy";
destroyText.fontSize = 14;
@ -633,6 +651,6 @@ namespace UnityExplorer.Inspectors.GOInspector
}
}
#endregion
#endregion
}
}

View File

@ -210,7 +210,7 @@ namespace UnityExplorer.Inspectors
{
var parent = InspectorManager.Instance.m_inspectorContent;
s_content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, new Color(0.1f, 0.1f, 0.1f));
s_content = UIFactory.CreateScrollView(parent, out GameObject scrollContent, out _, new Color(0.1f, 0.1f, 0.1f));
var scrollGroup = scrollContent.GetComponent<VerticalLayoutGroup>();
scrollGroup.childForceExpandHeight = true;
@ -388,8 +388,8 @@ namespace UnityExplorer.Inspectors
var layer = LayerMaskUnstrip.LayerToName(i);
m_layerDropdown.options.Add(new Dropdown.OptionData { text = $"{i}: {layer}" });
}
var itemText = layerDropdownObj.transform.Find("Label").GetComponent<Text>();
itemText.resizeTextForBestFit = true;
//var itemText = layerDropdownObj.transform.Find("Label").GetComponent<Text>();
//itemText.resizeTextForBestFit = true;
var layerDropdownLayout = layerDropdownObj.AddComponent<LayoutElement>();
layerDropdownLayout.minWidth = 120;
layerDropdownLayout.flexibleWidth = 2000;

View File

@ -55,7 +55,7 @@ namespace UnityExplorer.Inspectors
var inversePos = UIManager.CanvasRoot.transform.InverseTransformPoint(mousePos);
s_mousePosLabel.text = $"Mouse Position: {((Vector2)InputManager.MousePosition).ToString()}";
s_mousePosLabel.text = $"<color=grey>Mouse Position:</color> {((Vector2)InputManager.MousePosition).ToString()}";
float yFix = mousePos.y < 120 ? 80 : -80;
@ -75,7 +75,7 @@ namespace UnityExplorer.Inspectors
if (obj != s_lastHit)
{
s_lastHit = obj;
s_objNameLabel.text = $"<b>Hit:</b> <color=cyan>{obj.name}</color>";
s_objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
s_objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
}
@ -116,11 +116,11 @@ namespace UnityExplorer.Inspectors
// Title text
var titleObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
var titleObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
var titleText = titleObj.GetComponent<Text>();
titleText.text = "<b>Mouse Inspector</b> (press <b>ESC</b> to cancel)";
var mousePosObj = UIFactory.CreateLabel(content, TextAnchor.MiddleLeft);
var mousePosObj = UIFactory.CreateLabel(content, TextAnchor.MiddleCenter);
s_mousePosLabel = mousePosObj.GetComponent<Text>();
s_mousePosLabel.text = "Mouse Position:";

View File

@ -137,7 +137,8 @@ namespace UnityExplorer.Inspectors
if (!handles.Contains(m_currentSceneHandle))
{
m_sceneDropdown.transform.Find("Label").GetComponent<Text>().text = names[0];
//m_sceneDropdown.transform.Find("Label").GetComponent<Text>().text = names[0];
m_sceneDropdown.itemText.text = names[0];
SetTargetScene(handles[0]);
}
}
@ -406,9 +407,9 @@ namespace UnityExplorer.Inspectors
#else
inspectButton.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_selectedSceneObject); });
#endif
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, new Color(0.1f, 0.1f, 0.1f));
GameObject scrollObj = UIFactory.CreateScrollView(leftPane, out m_sceneListContent, out SliderScrollbar scroller, new Color(0.1f, 0.1f, 0.1f));
m_sceneListPageHandler = new PageHandler();
m_sceneListPageHandler = new PageHandler(scroller);
m_sceneListPageHandler.ConstructUI(leftPane);
m_sceneListPageHandler.OnPageChanged += OnSceneListPageTurn;

View File

@ -59,7 +59,7 @@ namespace UnityExplorer.Tests
GameObject.DontDestroyOnLoad(TestSprite);
//// test loading a tex from file
//var dataToLoad = System.IO.File.ReadAllBytes(@"Mods\Explorer\Tex_Nemundis_Nebula.png");
//var dataToLoad = System.IO.File.ReadAllBytes(@"Mods\UnityExplorer\Tex_Nemundis_Nebula.png");
//ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}");
ILHashSetTest = new Il2CppSystem.Collections.Generic.HashSet<string>();

View File

@ -4,6 +4,7 @@ using UnityExplorer.Helpers;
using UnityEngine.EventSystems;
using UnityExplorer.Input;
using BF = System.Reflection.BindingFlags;
using UnityExplorer.Config;
#if ML
using Harmony;
#else
@ -40,6 +41,20 @@ namespace UnityExplorer.UI
private static Type m_cursorType;
public static void Init()
{
ModConfig.OnConfigChanged += ModConfig_OnConfigChanged;
SetupPatches();
Unlock = true;
}
internal static void ModConfig_OnConfigChanged()
{
Unlock = ModConfig.Instance.Force_Unlock_Mouse;
}
private static void SetupPatches()
{
try
{
@ -62,20 +77,25 @@ namespace UnityExplorer.UI
catch { }
// Setup Harmony Patches
TryPatch(typeof(EventSystem), "current", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_EventSystem_set_current))), true);
TryPatch(typeof(EventSystem),
"current",
new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_EventSystem_set_current))),
true);
TryPatch(typeof(Cursor), "lockState", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_lockState))), true);
//TryPatch(typeof(Cursor), "lockState", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Postfix_get_lockState))), false);
TryPatch(typeof(Cursor),
"lockState",
new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_lockState))),
true);
TryPatch(typeof(Cursor), "visible", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_visible))), true);
//TryPatch(typeof(Cursor), "visible", new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Postfix_get_visible))), false);
TryPatch(typeof(Cursor),
"visible",
new HarmonyMethod(typeof(ForceUnlockCursor).GetMethod(nameof(Prefix_set_visible))),
true);
}
catch (Exception e)
{
ExplorerCore.Log($"Exception on CursorControl.Init! {e.GetType()}, {e.Message}");
}
Unlock = true;
}
private static void TryPatch(Type type, string property, HarmonyMethod patch, bool setter)
@ -88,18 +108,15 @@ namespace UnityExplorer.UI
#else
ExplorerBepInPlugin.HarmonyInstance;
#endif
;
System.Reflection.PropertyInfo prop = type.GetProperty(property);
if (setter)
if (setter) // setter is prefix
{
// setter is prefix
harmony.Patch(prop.GetSetMethod(), prefix: patch);
}
else
else // getter is postfix
{
// getter is postfix
harmony.Patch(prop.GetGetMethod(), postfix: patch);
}
}
@ -110,15 +127,6 @@ namespace UnityExplorer.UI
}
}
public static void Update()
{
// Check Force-Unlock input
if (InputManager.GetKeyDown(KeyCode.LeftAlt))
{
Unlock = !Unlock;
}
}
public static void UpdateCursorControl()
{
try
@ -142,7 +150,7 @@ namespace UnityExplorer.UI
}
}
// Event system
// Event system overrides
private static bool m_settingEventSystem;
private static EventSystem m_lastEventSystem;
@ -212,23 +220,5 @@ namespace UnityExplorer.UI
}
}
}
//[HarmonyPrefix]
//public static void Postfix_get_lockState(ref CursorLockMode __result)
//{
// if (ShouldForceMouse)
// {
// __result = m_lastLockMode;
// }
//}
//[HarmonyPrefix]
//public static void Postfix_get_visible(ref bool __result)
//{
// if (ShouldForceMouse)
// {
// __result = m_lastVisibleState;
// }
//}
}
}

View File

@ -4,6 +4,7 @@ using UnityExplorer.Console;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.UI.PageModel;
using UnityExplorer.Config;
namespace UnityExplorer.UI
{
@ -120,6 +121,8 @@ namespace UnityExplorer.UI
panelRect.anchorMin = new Vector2(0.25f, 0.1f);
panelRect.anchorMax = new Vector2(0.78f, 0.95f);
MainPanel.AddComponent<Mask>();
ConstructTitleBar(content);
ConstructNavbar(content);
@ -187,12 +190,18 @@ namespace UnityExplorer.UI
btnLayout.flexibleWidth = 2;
Text hideText = hideBtnObj.GetComponentInChildren<Text>();
// Todo use actual keycode from mod config, update on OnSettingsChanged or whatever
hideText.text = "Hide (F7)";
hideText.color = Color.white;
hideText.resizeTextForBestFit = true;
hideText.resizeTextMinSize = 8;
hideText.resizeTextMaxSize = 16;
hideText.text = $"Hide ({ModConfig.Instance.Main_Menu_Toggle})";
ModConfig.OnConfigChanged += ModConfig_OnConfigChanged;
void ModConfig_OnConfigChanged()
{
hideText.text = $"Hide ({ModConfig.Instance.Main_Menu_Toggle})";
}
}
private void ConstructNavbar(GameObject content)

View File

@ -4,14 +4,6 @@ using System.IO;
using System.Reflection;
using System.Text;
using UnityExplorer.Console;
using UnityExplorer.Unstrip.Resources;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Helpers;
#if CPP
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.UI.PageModel
{
@ -21,12 +13,12 @@ namespace UnityExplorer.UI.PageModel
public static ConsolePage Instance { get; private set; }
public static bool EnableSuggestions { get; set; } = true;
public static bool EnableAutoIndent { get; set; } = true;
public CodeEditor m_codeEditor;
public ScriptEvaluator m_evaluator;
public static bool EnableAutocompletes { get; set; } = true;
public static bool EnableAutoIndent { get; set; } = true;
public static List<Suggestion> AutoCompletes = new List<Suggestion>();
public static List<string> UsingDirectives;
@ -46,21 +38,31 @@ namespace UnityExplorer.UI.PageModel
try
{
ResetConsole();
foreach (string use in DefaultUsing)
{
AddUsing(use);
}
ConstructUI();
m_codeEditor = new CodeEditor();
AutoCompleter.Init();
try
{
ResetConsole();
// Make sure compiler is supported on this platform
m_evaluator.Compile("");
foreach (string use in DefaultUsing)
{
AddUsing(use);
}
}
catch (Exception e)
{
ExplorerCore.LogWarning($"Exception setting up Console: {e.GetType()}, {e.Message}\r\n{e.StackTrace}");
}
}
catch (Exception e)
{
// TODO remove page button from menu?
ExplorerCore.LogWarning($"Error setting up console!\r\nMessage: {e.Message}");
// TODO remove page button from menu
}
}
@ -75,21 +77,19 @@ namespace UnityExplorer.UI.PageModel
{
if (!UsingDirectives.Contains(asm))
{
UsingDirectives.Add(asm);
Evaluate($"using {asm};", true);
UsingDirectives.Add(asm);
}
}
public void Evaluate(string str, bool suppressWarning = false)
public void Evaluate(string code, bool suppressWarning = false)
{
m_evaluator.Compile(str, out Mono.CSharp.CompiledMethod compiled);
m_evaluator.Compile(code, out Mono.CSharp.CompiledMethod compiled);
if (compiled == null)
{
if (!suppressWarning)
{
ExplorerCore.LogWarning("Unable to compile the code!");
}
}
else
{
@ -100,7 +100,8 @@ namespace UnityExplorer.UI.PageModel
}
catch (Exception e)
{
ExplorerCore.LogWarning($"Exception executing code: {e.GetType()}, {e.Message}\r\n{e.StackTrace}");
if (!suppressWarning)
ExplorerCore.LogWarning($"Exception executing code: {e.GetType()}, {e.Message}\r\n{e.StackTrace}");
}
}
}
@ -119,8 +120,10 @@ namespace UnityExplorer.UI.PageModel
internal void OnInputChanged()
{
AutoCompleter.CheckAutocomplete();
if (!EnableAutocompletes)
return;
AutoCompleter.CheckAutocomplete();
AutoCompleter.SetSuggestions(AutoCompletes.ToArray());
}
@ -135,362 +138,6 @@ namespace UnityExplorer.UI.PageModel
AutoCompleter.ClearAutocompletes();
}
#region UI Construction
public void ConstructUI()
{
Content = UIFactory.CreateUIObject("C# Console", MainMenu.Instance.PageViewport);
var mainLayout = Content.AddComponent<LayoutElement>();
mainLayout.preferredHeight = 9900;
mainLayout.flexibleHeight = 9000;
var mainGroup = Content.AddComponent<VerticalLayoutGroup>();
mainGroup.childControlHeight = true;
mainGroup.childControlWidth = true;
mainGroup.childForceExpandHeight = true;
mainGroup.childForceExpandWidth = true;
#region TOP BAR
// Main group object
var topBarObj = UIFactory.CreateHorizontalGroup(Content);
LayoutElement topBarLayout = topBarObj.AddComponent<LayoutElement>();
topBarLayout.minHeight = 50;
topBarLayout.flexibleHeight = 0;
var topBarGroup = topBarObj.GetComponent<HorizontalLayoutGroup>();
topBarGroup.padding.left = 30;
topBarGroup.padding.right = 30;
topBarGroup.padding.top = 8;
topBarGroup.padding.bottom = 8;
topBarGroup.spacing = 10;
topBarGroup.childForceExpandHeight = true;
topBarGroup.childForceExpandWidth = true;
topBarGroup.childControlWidth = true;
topBarGroup.childControlHeight = true;
topBarGroup.childAlignment = TextAnchor.LowerCenter;
var topBarLabel = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft);
var topBarLabelLayout = topBarLabel.AddComponent<LayoutElement>();
topBarLabelLayout.preferredWidth = 800;
topBarLabelLayout.flexibleWidth = 10;
var topBarText = topBarLabel.GetComponent<Text>();
topBarText.text = "C# Console";
topBarText.fontSize = 20;
// Enable Suggestions toggle
var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText);
#if CPP
suggestToggle.onValueChanged.AddListener(new Action<bool>(SuggestToggleCallback));
#else
suggestToggle.onValueChanged.AddListener(SuggestToggleCallback);
#endif
void SuggestToggleCallback(bool val)
{
EnableSuggestions = val;
AutoCompleter.Update();
}
suggestToggleText.text = "Suggestions";
suggestToggleText.alignment = TextAnchor.UpperLeft;
var suggestTextPos = suggestToggleText.transform.localPosition;
suggestTextPos.y = -14;
suggestToggleText.transform.localPosition = suggestTextPos;
var suggestLayout = suggestToggleObj.AddComponent<LayoutElement>();
suggestLayout.minWidth = 120;
suggestLayout.flexibleWidth = 0;
var suggestRect = suggestToggleObj.transform.Find("Background");
var suggestPos = suggestRect.localPosition;
suggestPos.y = -14;
suggestRect.localPosition = suggestPos;
// Enable Auto-indent toggle
var autoIndentToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle autoIndentToggle, out Text autoIndentToggleText);
#if CPP
autoIndentToggle.onValueChanged.AddListener(new Action<bool>((bool val) =>
{
EnableAutoIndent = val;
}));
#else
autoIndentToggle.onValueChanged.AddListener(OnIndentChanged);
void OnIndentChanged(bool val) => EnableAutoIndent = val;
#endif
autoIndentToggleText.text = "Auto-indent";
autoIndentToggleText.alignment = TextAnchor.UpperLeft;
var autoIndentTextPos = autoIndentToggleText.transform.localPosition;
autoIndentTextPos.y = -14;
autoIndentToggleText.transform.localPosition = autoIndentTextPos;
var autoIndentLayout = autoIndentToggleObj.AddComponent<LayoutElement>();
autoIndentLayout.minWidth = 120;
autoIndentLayout.flexibleWidth = 0;
var autoIndentRect = autoIndentToggleObj.transform.Find("Background");
suggestPos = autoIndentRect.localPosition;
suggestPos.y = -14;
autoIndentRect.localPosition = suggestPos;
#endregion
#region CONSOLE INPUT
var consoleBase = UIFactory.CreateUIObject("CodeEditor", Content);
var consoleLayout = consoleBase.AddComponent<LayoutElement>();
consoleLayout.preferredHeight = 500;
consoleLayout.flexibleHeight = 50;
consoleBase.AddComponent<RectMask2D>();
var mainRect = consoleBase.GetComponent<RectTransform>();
mainRect.pivot = Vector2.one * 0.5f;
mainRect.anchorMin = Vector2.zero;
mainRect.anchorMax = Vector2.one;
mainRect.offsetMin = Vector2.zero;
mainRect.offsetMax = Vector2.zero;
var mainBg = UIFactory.CreateUIObject("MainBackground", consoleBase);
var mainBgRect = mainBg.GetComponent<RectTransform>();
mainBgRect.pivot = new Vector2(0, 1);
mainBgRect.anchorMin = Vector2.zero;
mainBgRect.anchorMax = Vector2.one;
mainBgRect.offsetMin = Vector2.zero;
mainBgRect.offsetMax = Vector2.zero;
var mainBgImage = mainBg.AddComponent<Image>();
var lineHighlight = UIFactory.CreateUIObject("LineHighlight", consoleBase);
var lineHighlightRect = lineHighlight.GetComponent<RectTransform>();
lineHighlightRect.pivot = new Vector2(0.5f, 1);
lineHighlightRect.anchorMin = new Vector2(0, 1);
lineHighlightRect.anchorMax = new Vector2(1, 1);
lineHighlightRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 21);
var lineHighlightImage = lineHighlight.GetComponent<Image>();
if (!lineHighlightImage)
{
lineHighlightImage = lineHighlight.AddComponent<Image>();
}
var linesBg = UIFactory.CreateUIObject("LinesBackground", consoleBase);
var linesBgRect = linesBg.GetComponent<RectTransform>();
linesBgRect.anchorMin = Vector2.zero;
linesBgRect.anchorMax = new Vector2(0, 1);
linesBgRect.offsetMin = new Vector2(-17.5f, 0);
linesBgRect.offsetMax = new Vector2(17.5f, 0);
linesBgRect.sizeDelta = new Vector2(65, 0);
var linesBgImage = linesBg.AddComponent<Image>();
var inputObj = UIFactory.CreateTMPInput(consoleBase);
var inputField = inputObj.GetComponent<TMP_InputField>();
inputField.richText = false;
var inputRect = inputObj.GetComponent<RectTransform>();
inputRect.pivot = new Vector2(0.5f, 0.5f);
inputRect.anchorMin = Vector2.zero;
inputRect.anchorMax = new Vector2(0.92f, 1);
inputRect.offsetMin = new Vector2(20, 0);
inputRect.offsetMax = new Vector2(14, 0);
inputRect.anchoredPosition = new Vector2(40, 0);
var textAreaObj = inputObj.transform.Find("TextArea");
var textAreaRect = textAreaObj.GetComponent<RectTransform>();
textAreaRect.pivot = new Vector2(0.5f, 0.5f);
textAreaRect.anchorMin = Vector2.zero;
textAreaRect.anchorMax = Vector2.one;
var mainTextObj = textAreaObj.transform.Find("Text");
var mainTextRect = mainTextObj.GetComponent<RectTransform>();
mainTextRect.pivot = new Vector2(0.5f, 0.5f);
mainTextRect.anchorMin = Vector2.zero;
mainTextRect.anchorMax = Vector2.one;
mainTextRect.offsetMin = Vector2.zero;
mainTextRect.offsetMax = Vector2.zero;
var mainTextInput = mainTextObj.GetComponent<TextMeshProUGUI>();
mainTextInput.fontSize = 18;
var placeHolderText = textAreaObj.transform.Find("Placeholder").GetComponent<TextMeshProUGUI>();
placeHolderText.text = @"Welcome to the UnityExplorer C# Console.
The following helper methods are available:
* <color=#add490>Log(""message"");</color> logs a message to the debug console
* <color=#add490>CurrentTarget();</color> returns the currently inspected target on the Home page
* <color=#add490>AllTargets();</color> returns an object[] array containing all inspected instances
* <color=#add490>Inspect(someObject)</color> to inspect an instance, eg. Inspect(Camera.main);
* <color=#add490>Inspect(typeof(SomeClass))</color> to inspect a Class with static reflection
* <color=#add490>AddUsing(""SomeNamespace"");</color> adds a using directive to the C# console
* <color=#add490>GetUsing();</color> logs the current using directives to the debug console
* <color=#add490>Reset();</color> resets all using directives and variables
";
var linesTextObj = UIFactory.CreateUIObject("LinesText", mainTextObj.gameObject);
var linesTextRect = linesTextObj.GetComponent<RectTransform>();
var linesTextInput = linesTextObj.AddComponent<TextMeshProUGUI>();
linesTextInput.fontSize = 18;
var highlightTextObj = UIFactory.CreateUIObject("HighlightText", mainTextObj.gameObject);
var highlightTextRect = highlightTextObj.GetComponent<RectTransform>();
highlightTextRect.anchorMin = Vector2.zero;
highlightTextRect.anchorMax = Vector2.one;
highlightTextRect.offsetMin = Vector2.zero;
highlightTextRect.offsetMax = Vector2.zero;
var highlightTextInput = highlightTextObj.AddComponent<TextMeshProUGUI>();
highlightTextInput.fontSize = 18;
var scroll = UIFactory.CreateScrollbar(consoleBase);
var scrollRect = scroll.GetComponent<RectTransform>();
scrollRect.anchorMin = new Vector2(1, 0);
scrollRect.anchorMax = new Vector2(1, 1);
scrollRect.pivot = new Vector2(0.5f, 1);
scrollRect.offsetMin = new Vector2(-25f, 0);
var scroller = scroll.GetComponent<Scrollbar>();
scroller.direction = Scrollbar.Direction.TopToBottom;
var scrollColors = scroller.colors;
scrollColors.normalColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
scroller.colors = scrollColors;
var scrollImage = scroll.GetComponent<Image>();
var tmpInput = inputObj.GetComponent<TMP_InputField>();
tmpInput.scrollSensitivity = 15;
tmpInput.verticalScrollbar = scroller;
// set lines text anchors here after UI is fleshed out
linesTextRect.pivot = Vector2.zero;
linesTextRect.anchorMin = new Vector2(0, 0);
linesTextRect.anchorMax = new Vector2(1, 1);
linesTextRect.offsetMin = Vector2.zero;
linesTextRect.offsetMax = Vector2.zero;
linesTextRect.anchoredPosition = new Vector2(-40, 0);
tmpInput.GetComponentInChildren<RectMask2D>().enabled = false;
inputObj.GetComponent<Image>().enabled = false;
#endregion
#region COMPILE BUTTON
var compileBtnObj = UIFactory.CreateButton(Content);
var compileBtnLayout = compileBtnObj.AddComponent<LayoutElement>();
compileBtnLayout.preferredWidth = 80;
compileBtnLayout.flexibleWidth = 0;
compileBtnLayout.minHeight = 45;
compileBtnLayout.flexibleHeight = 0;
var compileButton = compileBtnObj.GetComponent<Button>();
var compileBtnColors = compileButton.colors;
compileBtnColors.normalColor = new Color(14f / 255f, 80f / 255f, 14f / 255f);
compileButton.colors = compileBtnColors;
var btnText = compileBtnObj.GetComponentInChildren<Text>();
btnText.text = "Run";
btnText.fontSize = 18;
btnText.color = Color.white;
// Set compile button callback now that we have the Input Field reference
#if CPP
compileButton.onClick.AddListener(new Action(() =>
{
if (!string.IsNullOrEmpty(tmpInput.text))
{
Evaluate(tmpInput.text.Trim());
}
}));
#else
compileButton.onClick.AddListener(CompileCallback);
void CompileCallback()
{
if (!string.IsNullOrEmpty(tmpInput.text))
{
Evaluate(tmpInput.text.Trim());
}
}
#endif
#endregion
#region FONT
TMP_FontAsset fontToUse = null;
#if CPP
UnityEngine.Object[] fonts = ResourcesUnstrip.FindObjectsOfTypeAll(Il2CppType.Of<TMP_FontAsset>());
foreach (UnityEngine.Object font in fonts)
{
TMP_FontAsset fontCast = font.Il2CppCast(typeof(TMP_FontAsset)) as TMP_FontAsset;
if (fontCast.name.Contains("LiberationSans"))
{
fontToUse = fontCast;
break;
}
}
#else
var fonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (var font in fonts)
{
if (font.name.Contains("LiberationSans"))
{
fontToUse = font;
break;
}
}
#endif
if (fontToUse != null)
{
UnityEngine.TextCore.FaceInfo faceInfo = fontToUse.faceInfo;
fontToUse.tabSize = 10;
faceInfo.tabWidth = 10;
#if CPP
fontToUse.faceInfo = faceInfo;
#else
typeof(TMP_FontAsset)
.GetField("m_FaceInfo", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(fontToUse, faceInfo);
#endif
tmpInput.fontAsset = fontToUse;
mainTextInput.font = fontToUse;
highlightTextInput.font = fontToUse;
}
#endregion
try
{
m_codeEditor = new CodeEditor(inputField, mainTextInput, highlightTextInput, linesTextInput,
mainBgImage, lineHighlightImage, linesBgImage, scrollImage);
}
catch (Exception e)
{
ExplorerCore.Log(e);
}
}
#endregion
private class VoidType
{
public static readonly VoidType Value = new VoidType();

View File

@ -4,6 +4,7 @@ using UnityExplorer.Unstrip.ColorUtility;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
namespace UnityExplorer.UI.PageModel
{
@ -11,10 +12,12 @@ namespace UnityExplorer.UI.PageModel
{
public static DebugConsole Instance { get; private set; }
public static bool LogUnity { get; set; } = true;
public static bool LogUnity { get; set; } = ModConfig.Instance.Log_Unity_Debug;
public readonly List<string> AllMessages;
public readonly List<Text> MessageHolders;
public static readonly List<string> AllMessages = new List<string>();
public static readonly List<Text> MessageHolders = new List<Text>();
internal static readonly List<string> s_preInitMessages = new List<string>();
private TMP_InputField m_textInput;
@ -22,18 +25,22 @@ namespace UnityExplorer.UI.PageModel
{
Instance = this;
AllMessages = new List<string>();
MessageHolders = new List<Text>();
//AllMessages = new List<string>();
//MessageHolders = new List<Text>();
try
ConstructUI(parent);
string preAppend = "";
for (int i = s_preInitMessages.Count - 1; i >= 0; i--)
{
ConstructUI(parent);
}
catch (Exception e)
{
ExplorerCore.Log(e);
var msg = s_preInitMessages[i];
if (preAppend != "")
preAppend += "\r\n";
preAppend += msg;
}
m_textInput.text = preAppend;
}
public static void Log(string message)
{
Log(message, null);
@ -46,26 +53,19 @@ namespace UnityExplorer.UI.PageModel
public static void Log(string message, string hexColor)
{
if (Instance == null)
{
return;
}
message = $"{AllMessages.Count}: {message}";
Instance.AllMessages.Add(message);
if (Instance.m_textInput)
{
if (hexColor != null)
{
message = $"<color=#{hexColor}>{message}</color>";
}
AllMessages.Add(message);
if (hexColor != null)
message = $"<color=#{hexColor}>{message}</color>";
if (Instance?.m_textInput)
Instance.m_textInput.text = $"{message}\n{Instance.m_textInput.text}";
}
else
s_preInitMessages.Add(message);
}
// todo: get scrollbar working with inputfield somehow
public void ConstructUI(GameObject parent)
{
var mainObj = UIFactory.CreateVerticalGroup(parent, new Color(0.1f, 0.1f, 0.1f, 1.0f));
@ -129,11 +129,21 @@ namespace UnityExplorer.UI.PageModel
tmpInput.scrollSensitivity = 15;
tmpInput.verticalScrollbar = scroller;
if (UIManager.ConsoleFont != null)
{
tmpInput.textComponent.font = UIManager.ConsoleFont;
#if MONO
(tmpInput.placeholder as TextMeshProUGUI).font = UIManager.ConsoleFont;
#else
tmpInput.placeholder.TryCast<TextMeshProUGUI>().font = UIManager.ConsoleFont;
#endif
}
tmpInput.readOnly = true;
m_textInput = inputObj.GetComponent<TMP_InputField>();
#endregion
#endregion
#region BOTTOM BAR
@ -233,13 +243,21 @@ namespace UnityExplorer.UI.PageModel
var unityToggleObj = UIFactory.CreateToggle(bottomBarObj, out Toggle unityToggle, out Text unityToggleText);
#if CPP
unityToggle.onValueChanged.AddListener(new Action<bool>((bool val) => { LogUnity = val; }));
unityToggle.onValueChanged.AddListener(new Action<bool>(ToggleLogUnity));
#else
unityToggle.onValueChanged.AddListener((bool val) => { LogUnity = val; });
unityToggle.onValueChanged.AddListener(ToggleLogUnity);
#endif
unityToggle.isOn = LogUnity;
unityToggleText.text = "Print Unity Debug?";
unityToggleText.alignment = TextAnchor.MiddleLeft;
void ToggleLogUnity(bool val)
{
LogUnity = val;
ModConfig.Instance.Log_Unity_Debug = val;
ModConfig.SaveSettings();
}
var unityToggleLayout = unityToggleObj.AddComponent<LayoutElement>();
unityToggleLayout.minWidth = 200;
unityToggleLayout.flexibleWidth = 0;
@ -249,9 +267,7 @@ namespace UnityExplorer.UI.PageModel
pos.y = -8;
unityToggleRect.localPosition = pos;
#endregion
#endregion
}
}
}

View File

@ -1,29 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip.ColorUtility;
namespace UnityExplorer.UI.PageModel
{
// Probably do this after I've made the CacheObjectBase / InteractiveValue classes.
// Might not use CacheObject, but InteractiveValue would be useful here.
// Maybe InteractiveValue could have an OnSetValue event, which CacheObject and this class can subscribe to separately.
public class OptionsPage : MainMenu.Page
{
public override string Name => "Options";
private TMP_InputField m_keycodeInput;
private Toggle m_unlockMouseToggle;
private TMP_InputField m_pageLimitInput;
private TMP_InputField m_defaultOutputInput;
public override void Init()
{
ConstructUI();
}
public override void Update()
{
// not needed?
}
internal void OnApply()
{
if (!string.IsNullOrEmpty(m_keycodeInput.text) && Enum.Parse(typeof(KeyCode), m_keycodeInput.text) is KeyCode keyCode)
{
ModConfig.Instance.Main_Menu_Toggle = keyCode;
}
ModConfig.Instance.Force_Unlock_Mouse = m_unlockMouseToggle.isOn;
if (!string.IsNullOrEmpty(m_pageLimitInput.text) && int.TryParse(m_pageLimitInput.text, out int lim))
{
ModConfig.Instance.Default_Page_Limit = lim;
}
ModConfig.Instance.Default_Output_Path = m_defaultOutputInput.text;
// todo default output path
ModConfig.SaveSettings();
ModConfig.InvokeConfigChanged();
}
#region UI CONSTRUCTION
@ -32,35 +57,19 @@ namespace UnityExplorer.UI.PageModel
{
GameObject parent = MainMenu.Instance.PageViewport;
Content = UIFactory.CreateHorizontalGroup(parent);
var mainGroup = Content.GetComponent<HorizontalLayoutGroup>();
Content = UIFactory.CreateVerticalGroup(parent, new Color(0.15f, 0.15f, 0.15f));
var mainGroup = Content.GetComponent<VerticalLayoutGroup>();
mainGroup.padding.left = 4;
mainGroup.padding.right = 4;
mainGroup.padding.top = 4;
mainGroup.padding.bottom = 4;
mainGroup.spacing = 5;
mainGroup.childForceExpandHeight = true;
mainGroup.childForceExpandHeight = false;
mainGroup.childForceExpandWidth = true;
mainGroup.childControlHeight = true;
mainGroup.childControlWidth = true;
ConstructTopArea();
}
internal void ConstructTopArea()
{
var topAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.15f, 0.15f, 0.15f));
var topGroup = topAreaObj.GetComponent<VerticalLayoutGroup>();
topGroup.childForceExpandHeight = false;
topGroup.childControlHeight = true;
topGroup.childForceExpandWidth = true;
topGroup.childControlWidth = true;
topGroup.padding.top = 5;
topGroup.padding.left = 5;
topGroup.padding.right = 5;
topGroup.padding.bottom = 5;
topGroup.spacing = 5;
// ~~~~~ Title ~~~~~
GameObject titleObj = UIFactory.CreateLabel(Content, TextAnchor.UpperLeft);
Text titleLabel = titleObj.GetComponent<Text>();
@ -69,10 +78,164 @@ namespace UnityExplorer.UI.PageModel
LayoutElement titleLayout = titleObj.AddComponent<LayoutElement>();
titleLayout.minHeight = 30;
titleLayout.flexibleHeight = 0;
// ~~~~~ Actual options ~~~~~
var optionsGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var optionsGroup = optionsGroupObj.GetComponent<VerticalLayoutGroup>();
optionsGroup.childForceExpandHeight = false;
optionsGroup.childForceExpandWidth = true;
optionsGroup.childControlWidth = true;
optionsGroup.childControlHeight = true;
optionsGroup.spacing = 5;
optionsGroup.padding.top = 5;
optionsGroup.padding.left = 5;
optionsGroup.padding.right = 5;
optionsGroup.padding.bottom = 5;
ConstructKeycodeOpt(optionsGroupObj);
ConstructMouseUnlockOpt(optionsGroupObj);
ConstructPageLimitOpt(optionsGroupObj);
ConstructOutputPathOpt(optionsGroupObj);
var applyBtnObj = UIFactory.CreateButton(Content, new Color(0.2f, 0.2f, 0.2f));
var applyText = applyBtnObj.GetComponentInChildren<Text>();
applyText.text = "Apply and Save";
var applyLayout = applyBtnObj.AddComponent<LayoutElement>();
applyLayout.minHeight = 30;
applyLayout.flexibleWidth = 1000;
var applyBtn = applyBtnObj.GetComponent<Button>();
var applyColors = applyBtn.colors;
applyColors.normalColor = new Color(0.3f, 0.7f, 0.3f);
applyBtn.colors = applyColors;
#if MONO
applyBtn.onClick.AddListener(OnApply);
#else
applyBtn.onClick.AddListener(new Action(OnApply));
#endif
}
internal void ConstructKeycodeOpt(GameObject parent)
{
//public KeyCode Main_Menu_Toggle = KeyCode.F7;
#endregion
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childControlWidth = true;
rowGroup.childForceExpandWidth = false;
rowGroup.childControlHeight = true;
rowGroup.childForceExpandHeight = true;
var groupLayout = rowObj.AddComponent<LayoutElement>();
groupLayout.minHeight = 25;
groupLayout.flexibleHeight = 0;
groupLayout.minWidth = 200;
groupLayout.flexibleWidth = 1000;
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
var labelText = labelObj.GetComponent<Text>();
labelText.text = "Main Menu Toggle:";
var labelLayout = labelObj.AddComponent<LayoutElement>();
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var keycodeInputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
m_keycodeInput = keycodeInputObj.GetComponent<TMP_InputField>();
m_keycodeInput.text = ModConfig.Instance.Main_Menu_Toggle.ToString();
m_keycodeInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "KeyCode, eg. F7";
}
internal void ConstructMouseUnlockOpt(GameObject parent)
{
//public bool Force_Unlock_Mouse = true;
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childControlWidth = true;
rowGroup.childForceExpandWidth = false;
rowGroup.childControlHeight = true;
rowGroup.childForceExpandHeight = true;
var groupLayout = rowObj.AddComponent<LayoutElement>();
groupLayout.minHeight = 25;
groupLayout.flexibleHeight = 0;
groupLayout.minWidth = 200;
groupLayout.flexibleWidth = 1000;
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
var labelText = labelObj.GetComponent<Text>();
labelText.text = "Force Unlock Mouse:";
var labelLayout = labelObj.AddComponent<LayoutElement>();
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var toggleObj = UIFactory.CreateToggle(rowObj, out m_unlockMouseToggle, out Text toggleText);
m_unlockMouseToggle.isOn = ModConfig.Instance.Force_Unlock_Mouse;
toggleText.text = "";
}
internal void ConstructPageLimitOpt(GameObject parent)
{
//public int Default_Page_Limit = 20;
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childControlWidth = true;
rowGroup.childForceExpandWidth = false;
rowGroup.childControlHeight = true;
rowGroup.childForceExpandHeight = true;
var groupLayout = rowObj.AddComponent<LayoutElement>();
groupLayout.minHeight = 25;
groupLayout.flexibleHeight = 0;
groupLayout.minWidth = 200;
groupLayout.flexibleWidth = 1000;
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
var labelText = labelObj.GetComponent<Text>();
labelText.text = "Default Page Limit:";
var labelLayout = labelObj.AddComponent<LayoutElement>();
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var inputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
m_pageLimitInput = inputObj.GetComponent<TMP_InputField>();
m_pageLimitInput.text = ModConfig.Instance.Default_Page_Limit.ToString();
m_pageLimitInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "Integer, eg. 20";
}
internal void ConstructOutputPathOpt(GameObject parent)
{
//public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER;
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childControlWidth = true;
rowGroup.childForceExpandWidth = false;
rowGroup.childControlHeight = true;
rowGroup.childForceExpandHeight = true;
var groupLayout = rowObj.AddComponent<LayoutElement>();
groupLayout.minHeight = 25;
groupLayout.flexibleHeight = 0;
groupLayout.minWidth = 200;
groupLayout.flexibleWidth = 1000;
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
var labelText = labelObj.GetComponent<Text>();
labelText.text = "Default Output Path:";
var labelLayout = labelObj.AddComponent<LayoutElement>();
labelLayout.minWidth = 150;
labelLayout.minHeight = 25;
var inputObj = UIFactory.CreateTMPInput(rowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
m_defaultOutputInput = inputObj.GetComponent<TMP_InputField>();
m_defaultOutputInput.text = ModConfig.Instance.Default_Output_Path.ToString();
m_defaultOutputInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = @"Directory, eg. Mods\UnityExplorer";
}
#endregion
}
}

View File

@ -1,18 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityExplorer.Helpers;
using UnityExplorer.Inspectors;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip.Resources;
#if CPP
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.UI.PageModel
{
internal enum SearchContext
{
UnityObject,
GameObject,
Component,
Custom,
Instance,
StaticClass
}
internal enum SceneFilter
{
Any,
Asset,
DontDestroyOnLoad,
Explicit,
}
internal enum ChildFilter
{
Any,
RootObject,
HasParent
}
public class SearchPage : MainMenu.Page
{
public override string Name => "Search";
public static SearchPage Instance;
// ui elements
private Text m_resultCountText;
internal SearchContext m_context;
private TMP_InputField m_customTypeInput;
private TMP_InputField m_nameInput;
private Button m_selectedContextButton;
private readonly Dictionary<SearchContext, Button> m_contextButtons = new Dictionary<SearchContext, Button>();
private Dropdown m_sceneDropdown;
private int m_lastSceneCount = -1;
private SceneFilter m_sceneFilter;
private ChildFilter m_childFilter;
private GameObject m_extraFilterRow;
// Results
internal object[] m_results;
internal readonly List<object> m_resultShortList = new List<object>();
@ -21,27 +76,32 @@ namespace UnityExplorer.UI.PageModel
private GameObject m_resultListContent;
private readonly List<Text> m_resultListTexts = new List<Text>();
public SearchPage()
{
Instance = this;
}
public override void Init()
{
ConstructUI();
}
public void OnSceneChange()
{
m_results = new object[0];
RefreshResultList();
}
public override void Update()
{
//RefreshResultList();
// todo update scene filter options
if (HaveScenesChanged())
{
RefreshSceneDropdown();
}
}
internal void OnSearchClicked()
{
m_results = Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object));
RefreshResultList();
}
private void OnResultPageTurn()
{
RefreshResultList();
}
// Updating result list content
private void RefreshResultList()
{
@ -69,7 +129,9 @@ namespace UnityExplorer.UI.PageModel
{
var obj = m_results[itemIndex];
if (obj == null || obj is UnityEngine.Object uObj && !uObj)
var uObj = obj as UnityEngine.Object;
if (obj == null || (uObj != null && !uObj))
continue;
if (i >= m_resultShortList.Count)
@ -84,8 +146,15 @@ namespace UnityExplorer.UI.PageModel
var text = m_resultListTexts[i];
var name = $"<color={SyntaxColors.Class_Instance}>{ReflectionHelpers.GetActualType(obj).Name}</color>"
+ $" ({obj.ToString()})";
var name = $"<color={SyntaxColors.Class_Instance}>{ReflectionHelpers.GetActualType(obj).Name}</color>";
if (m_context != SearchContext.Instance && m_context != SearchContext.StaticClass)
{
if (uObj && !string.IsNullOrEmpty(uObj.name))
name += $": {uObj.name}";
else
name += ": <i><color=grey>untitled</color></i>";
}
text.text = name;
@ -98,7 +167,226 @@ namespace UnityExplorer.UI.PageModel
m_lastCount = newCount;
}
#region UI CONSTRUCTION
// scene dropdown update
internal bool HaveScenesChanged()
{
if (m_lastSceneCount != SceneManager.sceneCount)
return true;
for (int i = 0; i < SceneManager.sceneCount; i++)
{
int dropdownIndex = i + 3;
if (dropdownIndex >= m_sceneDropdown.options.Count
|| m_sceneDropdown.options[dropdownIndex].text != SceneManager.GetSceneAt(i).name)
return true;
}
return false;
}
internal void RefreshSceneDropdown()
{
m_sceneDropdown.OnCancel(null);
m_sceneDropdown.options.Clear();
m_sceneDropdown.options.Add(new Dropdown.OptionData
{
text = "Any"
});
m_sceneDropdown.options.Add(new Dropdown.OptionData
{
text = "None (Asset / Resource)"
});
m_sceneDropdown.options.Add(new Dropdown.OptionData
{
text = "DontDestroyOnLoad"
});
m_lastSceneCount = 0;
for (int i = 0; i < SceneManager.sceneCount; i++)
{
m_lastSceneCount++;
var scene = SceneManager.GetSceneAt(i).name;
m_sceneDropdown.options.Add(new Dropdown.OptionData
{
text = scene
});
}
m_sceneDropdown.transform.Find("Label").GetComponent<Text>().text = "Any";
}
// ~~~~~ UI Callbacks ~~~~~
internal void OnUnitySearchClicked()
{
m_resultListPageHandler.CurrentPage = 0;
Type searchType = null;
switch (m_context)
{
case SearchContext.GameObject:
searchType = typeof(GameObject); break;
case SearchContext.Component:
searchType = typeof(Component); break;
case SearchContext.Custom:
if (string.IsNullOrEmpty(m_customTypeInput.text))
{
ExplorerCore.LogWarning("Custom Type input must not be empty!");
return;
}
if (ReflectionHelpers.GetTypeByName(m_customTypeInput.text) is Type customType)
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
searchType = customType;
else
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
else
ExplorerCore.LogWarning($"Could not find a type by the name '{m_customTypeInput.text}'!");
break;
default:
searchType = typeof(UnityEngine.Object); break;
}
if (searchType == null)
return;
#if MONO
var allObjects = ResourcesUnstrip.FindObjectsOfTypeAll(searchType);
#else
var allObjects = ResourcesUnstrip.FindObjectsOfTypeAll(Il2CppType.From(searchType));
#endif
var results = new List<object>();
// prefer filter comparers
string nameFilter = null;
if (!string.IsNullOrEmpty(m_nameInput.text))
nameFilter = m_nameInput.text.ToLower();
bool canFilterScene = (m_sceneFilter != SceneFilter.Any || m_childFilter != ChildFilter.Any)
&& (m_context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType));
string sceneFilter = null;
if (!canFilterScene)
{
if (m_context != SearchContext.UnityObject && (m_sceneFilter != SceneFilter.Any || m_childFilter != ChildFilter.Any))
ExplorerCore.LogWarning($"Type '{searchType}' cannot have Scene or Child filters applied to it");
}
else
{
if (m_sceneFilter == SceneFilter.DontDestroyOnLoad)
sceneFilter = "DontDestroyOnLoad";
else if (m_sceneFilter == SceneFilter.Explicit)
sceneFilter = m_sceneDropdown.options[m_sceneDropdown.value].text;
}
foreach (var obj in allObjects)
{
// name check
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ToLower().Contains(nameFilter))
continue;
if (canFilterScene)
{
#if MONO
var go = m_context == SearchContext.GameObject
? obj as GameObject
: (obj as Component).gameObject;
#else
var go = m_context == SearchContext.GameObject
? obj.TryCast<GameObject>()
: obj.TryCast<Component>().gameObject;
#endif
// scene check
if (m_sceneFilter != SceneFilter.Any)
{
switch (m_context)
{
case SearchContext.GameObject:
if (go.scene.name != sceneFilter)
continue;
break;
case SearchContext.Custom:
case SearchContext.Component:
if (go.scene.name != sceneFilter)
continue;
break;
}
}
// root object check (no parent)
if (m_childFilter == ChildFilter.HasParent && !go.transform.parent)
continue;
else if (m_childFilter == ChildFilter.RootObject && go.transform.parent)
continue;
}
results.Add(obj);
}
m_results = results.ToArray();
if (m_results.Length > 0)
m_resultCountText.text = $"{m_results.Length} Results";
else
m_resultCountText.text = "No results...";
RefreshResultList();
}
private void OnResultPageTurn()
{
RefreshResultList();
}
internal void OnResultClicked(int index)
{
if (m_context == SearchContext.StaticClass)
InspectorManager.Instance.Inspect((Type)m_resultShortList[index]);
else
InspectorManager.Instance.Inspect(m_resultShortList[index]);
}
internal void OnContextButtonClicked(SearchContext context)
{
if (m_selectedContextButton && m_context == context)
return;
if (m_selectedContextButton)
UIFactory.SetDefaultColorTransitionValues(m_selectedContextButton);
var button = m_contextButtons[context];
m_selectedContextButton = button;
var colors = m_selectedContextButton.colors;
colors.normalColor = new Color(0.35f, 0.7f, 0.35f);
colors.highlightedColor = colors.normalColor;
m_selectedContextButton.colors = colors;
m_context = context;
// if extra filters are valid
if (context == SearchContext.Component
|| context == SearchContext.GameObject
|| context == SearchContext.Custom)
{
m_extraFilterRow?.SetActive(true);
}
else
{
m_extraFilterRow?.SetActive(false);
}
}
#region UI CONSTRUCTION
internal void ConstructUI()
{
@ -145,29 +433,222 @@ namespace UnityExplorer.UI.PageModel
// top area options
var tempObj = UIFactory.CreateLabel(topAreaObj, TextAnchor.MiddleLeft);
var tempText = tempObj.GetComponent<Text>();
tempText.text = "TODO Options / Filters";
var optionsGroupObj = UIFactory.CreateVerticalGroup(topAreaObj, new Color(0.1f, 0.1f, 0.1f));
var optionsGroup = optionsGroupObj.GetComponent<VerticalLayoutGroup>();
optionsGroup.childForceExpandHeight = false;
optionsGroup.childControlHeight = true;
optionsGroup.childForceExpandWidth = true;
optionsGroup.childControlWidth = true;
optionsGroup.spacing = 10;
optionsGroup.padding.top = 4;
optionsGroup.padding.right = 4;
optionsGroup.padding.left = 4;
optionsGroup.padding.bottom = 4;
var optionsLayout = optionsGroupObj.AddComponent<LayoutElement>();
optionsLayout.minWidth = 500;
optionsLayout.minHeight = 70;
optionsLayout.flexibleHeight = 100;
var testBtnObj = UIFactory.CreateButton(topAreaObj);
var testText = testBtnObj.GetComponentInChildren<Text>();
testText.text = "Search";
LayoutElement searchBtnLayout = testBtnObj.AddComponent<LayoutElement>();
// search context row
var contextRowObj = UIFactory.CreateHorizontalGroup(optionsGroupObj, new Color(1, 1, 1, 0));
var contextGroup = contextRowObj.GetComponent<HorizontalLayoutGroup>();
contextGroup.childForceExpandWidth = false;
contextGroup.childControlWidth = true;
contextGroup.childForceExpandHeight = false;
contextGroup.childControlHeight = true;
contextGroup.spacing = 3;
var contextLayout = contextRowObj.AddComponent<LayoutElement>();
contextLayout.minHeight = 25;
var contextLabelObj = UIFactory.CreateLabel(contextRowObj, TextAnchor.MiddleLeft);
var contextText = contextLabelObj.GetComponent<Text>();
contextText.text = "Searching for:";
var contextLabelLayout = contextLabelObj.AddComponent<LayoutElement>();
contextLabelLayout.minWidth = 125;
contextLabelLayout.minHeight = 25;
// context buttons
AddContextButton(contextRowObj, "UnityEngine.Object", SearchContext.UnityObject, 140);
AddContextButton(contextRowObj, "GameObject", SearchContext.GameObject);
AddContextButton(contextRowObj, "Component", SearchContext.Component);
AddContextButton(contextRowObj, "Custom...", SearchContext.Custom);
// custom type input
var customTypeObj = UIFactory.CreateTMPInput(contextRowObj, 13, 0, (int)TextAlignmentOptions.MidlineLeft);
var customTypeLayout = customTypeObj.AddComponent<LayoutElement>();
customTypeLayout.minWidth = 250;
customTypeLayout.flexibleWidth = 2000;
customTypeLayout.minHeight = 25;
customTypeLayout.flexibleHeight = 0;
m_customTypeInput = customTypeObj.GetComponent<TMP_InputField>();
m_customTypeInput.placeholder.gameObject.GetComponent<TextMeshProUGUI>().text = "eg. UnityEngine.Camera";
m_customTypeInput.onFocusSelectAll = true;
#if MONO
m_customTypeInput.onSelect.AddListener((string val) => { OnContextButtonClicked(SearchContext.Custom); });
#else
m_customTypeInput.onSelect.AddListener(new Action<string>((string val) => { OnContextButtonClicked(SearchContext.Custom); }));
#endif
// search input
var nameRowObj = UIFactory.CreateHorizontalGroup(optionsGroupObj, new Color(1, 1, 1, 0));
var nameRowGroup = nameRowObj.GetComponent<HorizontalLayoutGroup>();
nameRowGroup.childForceExpandWidth = true;
nameRowGroup.childControlWidth = true;
nameRowGroup.childForceExpandHeight = false;
nameRowGroup.childControlHeight = true;
var nameRowLayout = nameRowObj.AddComponent<LayoutElement>();
nameRowLayout.minHeight = 25;
nameRowLayout.flexibleHeight = 0;
nameRowLayout.flexibleWidth = 5000;
var nameLabelObj = UIFactory.CreateLabel(nameRowObj, TextAnchor.MiddleLeft);
var nameLabelText = nameLabelObj.GetComponent<Text>();
nameLabelText.text = "Search by name:";
var nameLabelLayout = nameLabelObj.AddComponent<LayoutElement>();
nameLabelLayout.minWidth = 125;
nameLabelLayout.minHeight = 25;
var nameInputObj = UIFactory.CreateTMPInput(nameRowObj, 14, 0, (int)TextAlignmentOptions.MidlineLeft);
m_nameInput = nameInputObj.GetComponent<TMP_InputField>();
var nameInputLayout = nameInputObj.AddComponent<LayoutElement>();
nameInputLayout.minWidth = 150;
nameInputLayout.flexibleWidth = 5000;
nameInputLayout.minHeight = 25;
// extra filter row
m_extraFilterRow = UIFactory.CreateHorizontalGroup(optionsGroupObj, new Color(1, 1, 1, 0));
m_extraFilterRow.SetActive(false);
var extraGroup = m_extraFilterRow.GetComponent<HorizontalLayoutGroup>();
extraGroup.childForceExpandHeight = true;
extraGroup.childControlHeight = true;
extraGroup.childForceExpandWidth = false;
extraGroup.childControlWidth = true;
var filterRowLayout = m_extraFilterRow.AddComponent<LayoutElement>();
filterRowLayout.minHeight = 25;
filterRowLayout.flexibleHeight = 0;
filterRowLayout.minWidth = 125;
filterRowLayout.flexibleWidth = 150;
// scene filter
var sceneLabelObj = UIFactory.CreateLabel(m_extraFilterRow, TextAnchor.MiddleLeft);
var sceneLabel = sceneLabelObj.GetComponent<Text>();
sceneLabel.text = "Scene Filter:";
var sceneLayout = sceneLabelObj.AddComponent<LayoutElement>();
sceneLayout.minWidth = 125;
sceneLayout.minHeight = 25;
var sceneDropObj = UIFactory.CreateDropdown(m_extraFilterRow, out m_sceneDropdown);
m_sceneDropdown.itemText.text = "Any";
m_sceneDropdown.itemText.fontSize = 12;
var sceneDropLayout = sceneDropObj.AddComponent<LayoutElement>();
sceneDropLayout.minWidth = 220;
sceneDropLayout.minHeight = 25;
#if MONO
m_sceneDropdown.onValueChanged.AddListener(OnSceneDropdownChanged);
#else
m_sceneDropdown.onValueChanged.AddListener(new Action<int>(OnSceneDropdownChanged));
#endif
void OnSceneDropdownChanged(int value)
{
if (value < 4)
m_sceneFilter = (SceneFilter)value;
else
m_sceneFilter = SceneFilter.Explicit;
}
// invisible space
var invis = UIFactory.CreateUIObject("spacer", m_extraFilterRow);
var invisLayout = invis.AddComponent<LayoutElement>();
invisLayout.minWidth = 25;
invisLayout.flexibleWidth = 0;
// children filter
var childLabelObj = UIFactory.CreateLabel(m_extraFilterRow, TextAnchor.MiddleLeft);
var childLabel = childLabelObj.GetComponent<Text>();
childLabel.text = "Child Filter:";
var childLayout = childLabelObj.AddComponent<LayoutElement>();
childLayout.minWidth = 100;
childLayout.minHeight = 25;
var childDropObj = UIFactory.CreateDropdown(m_extraFilterRow, out Dropdown childDrop);
childDrop.itemText.text = "Any";
childDrop.itemText.fontSize = 12;
var childDropLayout = childDropObj.AddComponent<LayoutElement>();
childDropLayout.minWidth = 180;
childDropLayout.minHeight = 25;
childDrop.options.Add(new Dropdown.OptionData { text = "Any" });
childDrop.options.Add(new Dropdown.OptionData { text = "Root Objects Only" });
childDrop.options.Add(new Dropdown.OptionData { text = "Children Only" });
#if MONO
childDrop.onValueChanged.AddListener(OnChildDropdownChanged);
#else
childDrop.onValueChanged.AddListener(new Action<int>(OnChildDropdownChanged));
#endif
void OnChildDropdownChanged(int value)
{
m_childFilter = (ChildFilter)value;
}
// search button
var searchBtnObj = UIFactory.CreateButton(topAreaObj);
var searchText = searchBtnObj.GetComponentInChildren<Text>();
searchText.text = "Search";
LayoutElement searchBtnLayout = searchBtnObj.AddComponent<LayoutElement>();
searchBtnLayout.minHeight = 30;
searchBtnLayout.flexibleHeight = 0;
var testBtn = testBtnObj.GetComponent<Button>();
var searchBtn = searchBtnObj.GetComponent<Button>();
#if MONO
testBtn.onClick.AddListener(OnSearchClicked);
searchBtn.onClick.AddListener(OnUnitySearchClicked);
#else
testBtn.onClick.AddListener(new Action(OnSearchClicked));
searchBtn.onClick.AddListener(new Action(OnUnitySearchClicked));
#endif
}
internal void AddContextButton(GameObject parent, string label, SearchContext context, float width = 110)
{
var btnObj = UIFactory.CreateButton(parent);
var btn = btnObj.GetComponent<Button>();
m_contextButtons.Add(context, btn);
#if MONO
btn.onClick.AddListener(() => { OnContextButtonClicked(context); });
#else
btn.onClick.AddListener(new Action(() => { OnContextButtonClicked(context); }));
#endif
var btnLayout = btnObj.AddComponent<LayoutElement>();
btnLayout.minHeight = 25;
btnLayout.minWidth = width;
var btnText = btnObj.GetComponentInChildren<Text>();
btnText.text = label;
// if first button
if (!m_selectedContextButton)
{
OnContextButtonClicked(context);
}
}
internal void ConstructResultsArea()
{
// Result group holder (NOT actual result list content)
var resultGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var resultGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(1,1,1,0));
var resultGroup = resultGroupObj.GetComponent<VerticalLayoutGroup>();
resultGroup.childForceExpandHeight = false;
resultGroup.childForceExpandWidth = true;
@ -179,15 +660,24 @@ namespace UnityExplorer.UI.PageModel
resultGroup.padding.left = 5;
resultGroup.padding.bottom = 5;
m_resultListPageHandler = new PageHandler();
var resultCountObj = UIFactory.CreateLabel(resultGroupObj, TextAnchor.MiddleCenter);
m_resultCountText = resultCountObj.GetComponent<Text>();
m_resultCountText.text = "No results...";
GameObject scrollObj = UIFactory.CreateScrollView(resultGroupObj,
out m_resultListContent,
out SliderScrollbar scroller,
new Color(0.07f, 0.07f, 0.07f, 1));
m_resultListPageHandler = new PageHandler(scroller);
m_resultListPageHandler.ConstructUI(resultGroupObj);
m_resultListPageHandler.OnPageChanged += OnResultPageTurn;
GameObject scrollObj = UIFactory.CreateScrollView(resultGroupObj, out m_resultListContent, new Color(0.15f, 0.15f, 0.15f));
// actual result list content
var contentGroup = m_resultListContent.GetComponent<VerticalLayoutGroup>();
contentGroup.spacing = 2;
contentGroup.childForceExpandHeight = false;
contentGroup.childControlHeight = true;
}
internal void AddResultButton()
@ -200,10 +690,10 @@ namespace UnityExplorer.UI.PageModel
btnGroup.childControlWidth = true;
btnGroup.childForceExpandHeight = false;
btnGroup.childControlHeight = true;
btnGroup.padding.top = 3;
btnGroup.padding.left = 3;
btnGroup.padding.right = 3;
btnGroup.padding.bottom = 3;
btnGroup.padding.top = 1;
btnGroup.padding.left = 1;
btnGroup.padding.right = 1;
btnGroup.padding.bottom = 1;
LayoutElement btnLayout = btnGroupObj.AddComponent<LayoutElement>();
btnLayout.flexibleWidth = 320;
btnLayout.minHeight = 25;
@ -222,9 +712,9 @@ namespace UnityExplorer.UI.PageModel
mainColors.highlightedColor = new Color(0.2f, 0.2f, 0.2f, 1);
mainBtn.colors = mainColors;
#if CPP
mainBtn.onClick.AddListener(new Action(() => { SceneListObjectClicked(thisIndex); }));
mainBtn.onClick.AddListener(new Action(() => { OnResultClicked(thisIndex); }));
#else
mainBtn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(m_resultShortList[thisIndex]); });
mainBtn.onClick.AddListener(() => { OnResultClicked(thisIndex); });
#endif
Text mainText = mainButtonObj.GetComponentInChildren<Text>();

View File

@ -336,7 +336,7 @@ namespace UnityExplorer.UI
{
try
{
string path = @"Mods\Explorer\cursor.png";
string path = ExplorerCore.EXPLORER_FOLDER + @"\cursor.png";
byte[] data = File.ReadAllBytes(path);
Texture2D tex = new Texture2D(32, 32);

View File

@ -13,13 +13,21 @@ namespace UnityExplorer.UI.Shared
Right
}
// TODO:
// - Input for setting page directly
public class PageHandler : IEnumerator
{
public PageHandler()
public PageHandler(SliderScrollbar scroll)
{
ItemsPerPage = ModConfig.Instance?.Default_Page_Limit ?? 20;
m_scrollbar = scroll;
}
public event Action OnPageChanged;
private SliderScrollbar m_scrollbar;
// For now this is just set when the PageHandler is created, based on config.
// At some point I might make it possible to change this after creation again.
public int ItemsPerPage { get; }
@ -28,8 +36,16 @@ namespace UnityExplorer.UI.Shared
public object Current => m_currentIndex;
private int m_currentIndex = 0;
public int CurrentPage
{
get => m_currentPage;
set
{
if (value < LastPage)
m_currentPage = value;
}
}
private int m_currentPage;
public event Action OnPageChanged;
// ui
private GameObject m_pageUIHolder;
@ -111,13 +127,13 @@ namespace UnityExplorer.UI.Shared
public void TurnPage(Turn direction)
{
bool didTurn = false;
if (direction == Turn.Left)
{
if (m_currentPage > 0)
{
m_currentPage--;
OnPageChanged?.Invoke();
RefreshUI();
didTurn = true;
}
}
else
@ -125,10 +141,15 @@ namespace UnityExplorer.UI.Shared
if (m_currentPage < LastPage)
{
m_currentPage++;
OnPageChanged?.Invoke();
RefreshUI();
didTurn = true;
}
}
if (didTurn)
{
m_scrollbar.m_scrollbar.value = 1;
OnPageChanged?.Invoke();
RefreshUI();
}
}
#region UI CONSTRUCTION
@ -147,7 +168,7 @@ namespace UnityExplorer.UI.Shared
m_pageUIHolder = UIFactory.CreateHorizontalGroup(parent);
Image image = m_pageUIHolder.GetComponent<Image>();
image.color = new Color(0f, 0f, 0f, 0f);
image.color = new Color(0.2f, 0.2f, 0.2f, 0.5f);
HorizontalLayoutGroup mainGroup = m_pageUIHolder.GetComponent<HorizontalLayoutGroup>();
mainGroup.childForceExpandHeight = true;
@ -156,12 +177,12 @@ namespace UnityExplorer.UI.Shared
mainGroup.childControlHeight = true;
LayoutElement mainLayout = m_pageUIHolder.AddComponent<LayoutElement>();
mainLayout.minHeight = 20;
mainLayout.minHeight = 25;
mainLayout.flexibleHeight = 0;
mainLayout.minWidth = 100;
mainLayout.flexibleWidth = 30;
mainLayout.flexibleWidth = 5000;
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder);
GameObject leftBtnObj = UIFactory.CreateButton(m_pageUIHolder, new Color(0.15f, 0.15f, 0.15f));
Button leftBtn = leftBtnObj.GetComponent<Button>();
#if CPP
leftBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Left); }));
@ -171,19 +192,19 @@ namespace UnityExplorer.UI.Shared
Text leftBtnText = leftBtnObj.GetComponentInChildren<Text>();
leftBtnText.text = "◄";
LayoutElement leftBtnLayout = leftBtnObj.AddComponent<LayoutElement>();
leftBtnLayout.flexibleHeight = 0;
leftBtnLayout.flexibleWidth = 0;
leftBtnLayout.minWidth = 30;
leftBtnLayout.minHeight = 20;
leftBtnLayout.flexibleHeight = 0f;
leftBtnLayout.flexibleWidth = 1500f;
leftBtnLayout.minWidth = 25f;
leftBtnLayout.minHeight = 25f;
GameObject labelObj = UIFactory.CreateLabel(m_pageUIHolder, TextAnchor.MiddleCenter);
m_currentPageLabel = labelObj.GetComponent<Text>();
m_currentPageLabel.text = "Page 1 / TODO";
LayoutElement textLayout = labelObj.AddComponent<LayoutElement>();
textLayout.minWidth = 60f;
textLayout.flexibleWidth = 5000f;
textLayout.minWidth = 100f;
textLayout.flexibleWidth = 40f;
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder);
GameObject rightBtnObj = UIFactory.CreateButton(m_pageUIHolder, new Color(0.15f, 0.15f, 0.15f));
Button rightBtn = rightBtnObj.GetComponent<Button>();
#if CPP
rightBtn.onClick.AddListener(new Action(() => { TurnPage(Turn.Right); }));
@ -194,9 +215,9 @@ namespace UnityExplorer.UI.Shared
rightBtnText.text = "►";
LayoutElement rightBtnLayout = rightBtnObj.AddComponent<LayoutElement>();
rightBtnLayout.flexibleHeight = 0;
rightBtnLayout.flexibleWidth = 0;
rightBtnLayout.minWidth = 30;
rightBtnLayout.minHeight = 20;
rightBtnLayout.flexibleWidth = 1500f;
rightBtnLayout.minWidth = 25f;
rightBtnLayout.minHeight = 25;
ListCount = 0;
}

View File

@ -6,9 +6,9 @@ using UnityEngine.Events;
using UnityEngine.UI;
using UnityExplorer;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
// Basically just to fix an issue with Scrollbars, instead we use a Slider as the scrollbar.
// This class contains only what is needed to update and manage one after creation.
public class SliderScrollbar
{
internal static readonly List<SliderScrollbar> Instances = new List<SliderScrollbar>();
@ -35,6 +35,11 @@ public class SliderScrollbar
this.m_slider.Set(1f, false);
}
~SliderScrollbar()
{
Instances.Remove(this);
}
internal void Update()
{
this.RefreshVisibility();
@ -75,6 +80,73 @@ public class SliderScrollbar
this.m_scrollbar.value = _value;
}
}
#region UI CONSTRUCTION
public static GameObject CreateSliderScrollbar(GameObject parent, out Slider slider)
{
GameObject sliderObj = UIFactory.CreateUIObject("Slider", parent, UIFactory.thinSize);
GameObject bgObj = UIFactory.CreateUIObject("Background", sliderObj);
GameObject fillAreaObj = UIFactory.CreateUIObject("Fill Area", sliderObj);
GameObject fillObj = UIFactory.CreateUIObject("Fill", fillAreaObj);
GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
bgRect.anchorMin = Vector2.zero;
bgRect.anchorMax = Vector2.one;
bgRect.sizeDelta = Vector2.zero;
bgRect.offsetMax = new Vector2(-10f, 0f);
RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear;
fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
handleSlideRect.anchorMin = new Vector2(0f, 0f);
handleSlideRect.anchorMax = new Vector2(1f, 1f);
handleSlideRect.offsetMin = new Vector2(15f, 30f);
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
handleSlideRect.sizeDelta = new Vector2(-30f, -30f);
Image handleImage = handleObj.AddComponent<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
var handleRect = handleObj.GetComponent<RectTransform>();
handleRect.sizeDelta = new Vector2(15f, 30f);
handleRect.offsetMin = new Vector2(-13f, -28f);
handleRect.offsetMax = new Vector2(3f, -2f);
var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
sliderBarLayout.minWidth = 25;
sliderBarLayout.flexibleWidth = 0;
sliderBarLayout.minHeight = 30;
sliderBarLayout.flexibleHeight = 5000;
slider = sliderObj.AddComponent<Slider>();
slider.fillRect = fillObj.GetComponent<RectTransform>();
slider.handleRect = handleObj.GetComponent<RectTransform>();
slider.targetGraphic = handleImage;
slider.direction = Slider.Direction.BottomToTop;
UIFactory.SetDefaultColorTransitionValues(slider);
return sliderObj;
}
#endregion
}
#if MONO

View File

@ -7,10 +7,10 @@ namespace UnityExplorer.UI
{
public static class UIFactory
{
private static Vector2 thickSize = new Vector2(160f, 30f);
private static Vector2 thinSize = new Vector2(160f, 20f);
private static Color defaultTextColor = new Color(0.95f, 0.95f, 0.95f, 1f);
private static Font m_defaultFont;
internal static Vector2 thickSize = new Vector2(160f, 30f);
internal static Vector2 thinSize = new Vector2(160f, 20f);
internal static Color defaultTextColor = new Color(0.95f, 0.95f, 0.95f, 1f);
internal static Font m_defaultFont;
public static GameObject CreateUIObject(string name, GameObject parent, Vector2 size = default)
{
@ -27,6 +27,26 @@ namespace UnityExplorer.UI
return obj;
}
private static void SetParentAndAlign(GameObject child, GameObject parent)
{
if (parent == null)
{
return;
}
child.transform.SetParent(parent.transform, false);
SetLayerRecursively(child);
}
public static void SetLayerRecursively(GameObject go)
{
go.layer = 5;
Transform transform = go.transform;
for (int i = 0; i < transform.childCount; i++)
{
SetLayerRecursively(transform.GetChild(i).gameObject);
}
}
private static void SetDefaultTextValues(Text lbl)
{
lbl.color = defaultTextColor;
@ -42,10 +62,10 @@ namespace UnityExplorer.UI
public static void SetDefaultColorTransitionValues(Selectable selectable)
{
ColorBlock colors = selectable.colors;
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
colors.normalColor = new Color(0.35f, 0.35f, 0.35f);
colors.highlightedColor = new Color(0.45f, 0.45f, 0.45f);
colors.pressedColor = new Color(0.1f, 0.1f, 0.1f);
colors.disabledColor = new Color(0.7f, 0.7f, 0.7f);
colors.pressedColor = new Color(0.25f, 0.25f, 0.25f);
//colors.disabledColor = new Color(0.6f, 0.6f, 0.6f);
// fix to make all buttons become de-selected after being clicked.
// this is because i'm not setting any ColorBlock.selectedColor, because it is commonly stripped.
@ -69,26 +89,6 @@ namespace UnityExplorer.UI
selectable.colors = colors;
}
private static void SetParentAndAlign(GameObject child, GameObject parent)
{
if (parent == null)
{
return;
}
child.transform.SetParent(parent.transform, false);
SetLayerRecursively(child);
}
public static void SetLayerRecursively(GameObject go)
{
go.layer = 5;
Transform transform = go.transform;
for (int i = 0; i < transform.childCount; i++)
{
SetLayerRecursively(transform.GetChild(i).gameObject);
}
}
public static GameObject CreatePanel(GameObject parent, string name, out GameObject content)
{
GameObject panelObj = CreateUIObject($"Panel_{name}", parent, thickSize);
@ -232,7 +232,7 @@ namespace UnityExplorer.UI
Image image = buttonObj.AddComponent<Image>();
image.type = Image.Type.Sliced;
image.color = new Color(1, 1, 1, 1);
image.color = new Color(1, 1, 1, 0.75f);
SetDefaultColorTransitionValues(buttonObj.AddComponent<Button>());
@ -257,74 +257,6 @@ namespace UnityExplorer.UI
return buttonObj;
}
//public static GameObject CreateSlider(GameObject parent)
//{
// GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
// GameObject bgObj = CreateUIObject("Background", sliderObj);
// GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
// GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
// GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
// GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
// Image bgImage = bgObj.AddComponent<Image>();
// bgImage.type = Image.Type.Sliced;
// bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
// RectTransform bgRect = bgObj.GetComponent<RectTransform>();
// bgRect.anchorMin = new Vector2(0f, dynamic ? 0f : 0.25f);
// bgRect.anchorMax = new Vector2(1f, dynamic ? 1f : 0.75f);
// bgRect.sizeDelta = new Vector2(0f, 0f);
// RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
// fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
// fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
// fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
// fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
// Image fillImage = fillObj.AddComponent<Image>();
// fillImage.type = Image.Type.Sliced;
// fillImage.color = dynamic ? Color.clear : new Color(0.3f, 0.3f, 0.3f, 1.0f);
// fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
// RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
// handleSlideRect.anchorMin = new Vector2(0f, 0f);
// handleSlideRect.anchorMax = new Vector2(1f, 1f);
// handleSlideRect.offsetMin = new Vector2(15f, 20f);
// handleSlideRect.offsetMax = new Vector2(-15f, 0f);
// handleSlideRect.sizeDelta = new Vector2(dynamic ? -30f : -20f, 0f);
// Image handleImage = handleObj.AddComponent<Image>();
// handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
// var handleRect = handleObj.GetComponent<RectTransform>();
// handleRect.sizeDelta = new Vector2(dynamic ? 25f : 20f, dynamic ? 25f : 0f);
// if (dynamic)
// {
// handleRect.offsetMin = new Vector2(-15f, -20f);
// handleRect.offsetMax = Vector2.zero;
// var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
// sliderBarLayout.minWidth = 25;
// sliderBarLayout.flexibleWidth = 0;
// sliderBarLayout.minHeight = 25;
// sliderBarLayout.flexibleHeight = 5000;
// bgRect.offsetMax = new Vector2(-15f, 0f);
// }
// Slider slider = sliderObj.AddComponent<Slider>();
// slider.fillRect = fillObj.GetComponent<RectTransform>();
// slider.handleRect = handleObj.GetComponent<RectTransform>();
// slider.targetGraphic = handleImage;
// slider.direction = dynamic ? Slider.Direction.BottomToTop : Slider.Direction.LeftToRight;
// SetDefaultColorTransitionValues(slider);
// return sliderObj;
//}
public static GameObject CreateSlider(GameObject parent)
{
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
@ -686,23 +618,15 @@ namespace UnityExplorer.UI
dropdown.template = templateObj.GetComponent<RectTransform>();
dropdown.captionText = labelText;
dropdown.itemText = itemLabelText;
itemLabelText.text = "1";
//dropdown.options.Add(new Dropdown.OptionData
//{
// text = "2"
//});
//dropdown.options.Add(new Dropdown.OptionData
//{
// text = "3"
//});
itemLabelText.text = "DEFAULT";
dropdown.RefreshShownValue();
RectTransform labelRect = labelObj.GetComponent<RectTransform>();
labelRect.anchorMin = Vector2.zero;
labelRect.anchorMax = Vector2.one;
labelRect.offsetMin = new Vector2(10f, 6f);
labelRect.offsetMax = new Vector2(-28f, -7f);
labelRect.offsetMin = new Vector2(10f, 2f);
labelRect.offsetMax = new Vector2(-28f, -2f);
RectTransform templateRect = templateObj.GetComponent<RectTransform>();
templateRect.anchorMin = new Vector2(0f, 0f);
@ -744,7 +668,7 @@ namespace UnityExplorer.UI
return dropdownObj;
}
public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
public static GameObject CreateScrollView(GameObject parent, out GameObject content, out SliderScrollbar scroller, Color color = default)
{
GameObject mainObj = CreateUIObject("DynamicScrollView", parent);
@ -814,7 +738,7 @@ namespace UnityExplorer.UI
child.gameObject.SetActive(false);
}
CreateScrollSlider(scrollBar, out Slider scrollSlider);
SliderScrollbar.CreateSliderScrollbar(scrollBar, out Slider scrollSlider);
// Back to the main scrollview ScrollRect, setting it up now that we have all references.
@ -831,160 +755,9 @@ namespace UnityExplorer.UI
scrollRect.content = contentRect;
// Create a custom DynamicScrollbar module
new SliderScrollbar(hiddenScroll, scrollSlider);
scroller = new SliderScrollbar(hiddenScroll, scrollSlider);
return mainObj;
}
public static GameObject CreateScrollSlider(GameObject parent, out Slider slider)
{
GameObject sliderObj = CreateUIObject("Slider", parent, thinSize);
GameObject bgObj = CreateUIObject("Background", sliderObj);
GameObject fillAreaObj = CreateUIObject("Fill Area", sliderObj);
GameObject fillObj = CreateUIObject("Fill", fillAreaObj);
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
RectTransform bgRect = bgObj.GetComponent<RectTransform>();
bgRect.anchorMin = Vector2.zero;
bgRect.anchorMax = Vector2.one;
bgRect.sizeDelta = Vector2.zero;
bgRect.offsetMax = new Vector2(-10f, 0f);
RectTransform fillAreaRect = fillAreaObj.GetComponent<RectTransform>();
fillAreaRect.anchorMin = new Vector2(0f, 0.25f);
fillAreaRect.anchorMax = new Vector2(1f, 0.75f);
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear;
fillObj.GetComponent<RectTransform>().sizeDelta = new Vector2(10f, 0f);
RectTransform handleSlideRect = handleSlideAreaObj.GetComponent<RectTransform>();
handleSlideRect.anchorMin = new Vector2(0f, 0f);
handleSlideRect.anchorMax = new Vector2(1f, 1f);
handleSlideRect.offsetMin = new Vector2(15f, 25f);
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
handleSlideRect.sizeDelta = new Vector2(-30f, -25f);
Image handleImage = handleObj.AddComponent<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
var handleRect = handleObj.GetComponent<RectTransform>();
handleRect.sizeDelta = new Vector2(15f, 25f);
handleRect.offsetMin = new Vector2(-13f, -23f);
handleRect.offsetMax = new Vector2(3f, -2f);
var sliderBarLayout = sliderObj.AddComponent<LayoutElement>();
sliderBarLayout.minWidth = 25;
sliderBarLayout.flexibleWidth = 0;
sliderBarLayout.minHeight = 25;
sliderBarLayout.flexibleHeight = 5000;
slider = sliderObj.AddComponent<Slider>();
slider.fillRect = fillObj.GetComponent<RectTransform>();
slider.handleRect = handleObj.GetComponent<RectTransform>();
slider.targetGraphic = handleImage;
slider.direction = Slider.Direction.BottomToTop;
SetDefaultColorTransitionValues(slider);
return sliderObj;
}
//public static GameObject CreateScrollView(GameObject parent, out GameObject content, Color color = default)
//{
// GameObject scrollObj = CreateUIObject("Scroll View", parent);
// LayoutElement mainLayout = scrollObj.AddComponent<LayoutElement>();
// mainLayout.flexibleWidth = 999;
// mainLayout.flexibleHeight = 999;
// mainLayout.preferredHeight = 200;
// mainLayout.preferredWidth = 200;
// GameObject viewportObj = CreateUIObject("Viewport", scrollObj);
// VerticalLayoutGroup viewportGroup = viewportObj.AddComponent<VerticalLayoutGroup>();
// viewportGroup.childControlHeight = true;
// viewportGroup.childControlWidth = true;
// viewportGroup.childForceExpandHeight = true;
// viewportGroup.childForceExpandWidth = true;
// content = CreateUIObject("Content", viewportObj);
// VerticalLayoutGroup contentGroup = content.AddComponent<VerticalLayoutGroup>();
// contentGroup.padding.left = 5;
// contentGroup.padding.right = 5;
// contentGroup.padding.top = 5;
// contentGroup.padding.bottom = 5;
// contentGroup.childControlHeight = false;
// contentGroup.childControlWidth = true;
// contentGroup.childForceExpandHeight = false;
// contentGroup.childForceExpandWidth = true;
// GameObject horiScroll = CreateScrollbar(scrollObj);
// horiScroll.name = "Scrollbar Horizontal";
// SetParentAndAlign(horiScroll, scrollObj);
// RectTransform horiRect = horiScroll.GetComponent<RectTransform>();
// horiRect.anchorMin = Vector2.zero;
// horiRect.anchorMax = Vector2.right;
// horiRect.pivot = Vector2.zero;
// horiRect.sizeDelta = new Vector2(0f, horiRect.sizeDelta.y);
// GameObject vertScroll = CreateScrollbar(scrollObj);
// vertScroll.name = "Scrollbar Vertical";
// SetParentAndAlign(vertScroll, scrollObj);
// vertScroll.GetComponent<Scrollbar>().SetDirection(Scrollbar.Direction.BottomToTop, true);
// RectTransform vertRect = vertScroll.GetComponent<RectTransform>();
// vertRect.anchorMin = Vector2.right;
// vertRect.anchorMax = Vector2.one;
// vertRect.pivot = Vector2.one;
// vertRect.sizeDelta = new Vector2(vertRect.sizeDelta.x, 0f);
// RectTransform viewportRect = viewportObj.GetComponent<RectTransform>();
// viewportRect.anchorMin = Vector2.zero;
// viewportRect.anchorMax = Vector2.one;
// viewportRect.sizeDelta = Vector2.zero;
// viewportRect.pivot = Vector2.up;
// RectTransform contentRect = content.GetComponent<RectTransform>();
// contentRect.anchorMin = Vector2.up;
// contentRect.anchorMax = Vector2.one;
// contentRect.pivot = Vector2.up;
// ScrollRect scrollRect = scrollObj.AddComponent<ScrollRect>();
// scrollRect.content = contentRect;
// scrollRect.viewport = viewportRect;
// scrollRect.horizontalScrollbar = horiScroll.GetComponent<Scrollbar>();
// scrollRect.verticalScrollbar = vertScroll.GetComponent<Scrollbar>();
// scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
// scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
// scrollRect.horizontalScrollbarSpacing = -3f;
// scrollRect.verticalScrollbarSpacing = -3f;
// scrollRect.scrollSensitivity = 25;
// Image scrollImage = scrollObj.AddComponent<Image>();
// scrollImage.type = Image.Type.Filled;
// scrollImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
// Image viewportImage = viewportObj.AddComponent<Image>();
// //viewportImage.sprite = Theme.mask;
// viewportImage.type = Image.Type.Sliced;
// viewportImage.color = new Color(1, 1, 1, 1);
// Mask mask = viewportObj.AddComponent<Mask>();
// mask.showMaskGraphic = false;
// return scrollObj;
//}
}
}

View File

@ -2,6 +2,14 @@
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.Inspectors;
using UnityExplorer.UI.PageModel;
using System.IO;
using TMPro;
using System.Reflection;
using UnityExplorer.Helpers;
#if CPP
using UnityExplorer.Unstrip.AssetBundle;
#endif
namespace UnityExplorer.UI
{
@ -11,19 +19,48 @@ namespace UnityExplorer.UI
public static EventSystem EventSys { get; private set; }
public static StandaloneInputModule InputModule { get; private set; }
public static TMP_FontAsset ConsoleFont { get; private set; }
public static void Init()
{
var bundlePath = ExplorerCore.EXPLORER_FOLDER + @"\tmp.bundle";
if (File.Exists(bundlePath))
{
var bundle = AssetBundle.LoadFromFile(bundlePath);
bundle.LoadAllAssets();
ExplorerCore.Log("Loaded TMP bundle");
if (TMP_Settings.instance == null)
{
var settings = bundle.LoadAsset<TMP_Settings>("TMP Settings");
#if MONO
typeof(TMP_Settings)
.GetField("s_Instance", ReflectionHelpers.CommonFlags)
.SetValue(null, settings);
#else
TMP_Settings.s_Instance = settings;
#endif
}
ConsoleFont = bundle.LoadAsset<TMP_FontAsset>("CONSOLA SDF");
}
else if (TMP_Settings.instance == null)
{
ExplorerCore.LogWarning(@"This game does not seem to have the TMP Resources package, and the TMP AssetBundle was not found at 'Mods\UnityExplorer\tmp.bundle\'!");
return;
}
// Create core UI Canvas and Event System handler
CreateRootCanvas();
// Create submodules
new MainMenu();
MouseInspector.ConstructUI();
// Force refresh of anchors
Canvas.ForceUpdateCanvases();
CanvasRoot.SetActive(false);
CanvasRoot.SetActive(true);
}
@ -34,32 +71,10 @@ namespace UnityExplorer.UI
InputModule.ActivateModule();
}
private static GameObject CreateRootCanvas()
public static void OnSceneChange()
{
GameObject rootObj = new GameObject("ExplorerCanvas");
UnityEngine.Object.DontDestroyOnLoad(rootObj);
rootObj.layer = 5;
CanvasRoot = rootObj;
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
EventSys = rootObj.AddComponent<EventSystem>();
InputModule = rootObj.AddComponent<StandaloneInputModule>();
InputModule.ActivateModule();
Canvas canvas = rootObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.referencePixelsPerUnit = 100;
canvas.sortingOrder = 999;
canvas.pixelPerfect = false;
CanvasScaler scaler = rootObj.AddComponent<CanvasScaler>();
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
rootObj.AddComponent<GraphicRaycaster>();
return rootObj;
SceneExplorer.Instance?.OnSceneChange();
SearchPage.Instance?.OnSceneChange();
}
public static void Update()
@ -101,10 +116,32 @@ namespace UnityExplorer.UI
}
}
public static void OnSceneChange()
private static GameObject CreateRootCanvas()
{
// todo
SceneExplorer.Instance?.OnSceneChange();
GameObject rootObj = new GameObject("ExplorerCanvas");
UnityEngine.Object.DontDestroyOnLoad(rootObj);
rootObj.layer = 5;
CanvasRoot = rootObj;
CanvasRoot.transform.position = new Vector3(0f, 0f, 1f);
EventSys = rootObj.AddComponent<EventSystem>();
InputModule = rootObj.AddComponent<StandaloneInputModule>();
InputModule.ActivateModule();
Canvas canvas = rootObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.referencePixelsPerUnit = 100;
canvas.sortingOrder = 999;
canvas.pixelPerfect = false;
CanvasScaler scaler = rootObj.AddComponent<CanvasScaler>();
scaler.referenceResolution = new Vector2(1920, 1080);
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
rootObj.AddComponent<GraphicRaycaster>();
return rootObj;
}
public static Sprite CreateSprite(Texture2D tex, Rect size = default)

View File

@ -171,6 +171,10 @@
<HintPath>$(BIEMonoManagedFolder)\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>$(BIEMonoManagedFolder)\UnityEngine.AssetBundleModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BIEMonoManagedFolder)\UnityEngine.dll</HintPath>
<Private>False</Private>
@ -384,6 +388,7 @@
<Compile Include="UI\Shared\PageHandler.cs" />
<Compile Include="UI\Shared\SyntaxColors.cs" />
<Compile Include="UI\UIManager.cs" />
<Compile Include="Unstrip\AssetBundle\AssetBundleUnstrip.cs" />
<Compile Include="Unstrip\ColorUtility\ColorUtilityUnstrip.cs" />
<Compile Include="Unstrip\ImageConversion\ImageConversionUnstrip.cs" />
<Compile Include="Helpers\ICallHelper.cs" />

View File

@ -0,0 +1,57 @@
#if CPP
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityExplorer.Helpers;
namespace UnityExplorer.Unstrip.AssetBundle
{
public class AssetBundle
{
// ~~~~~~~~~~~~ Static ~~~~~~~~~~~~
internal delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset);
public static AssetBundle LoadFromFile(string path)
{
var iCall = ICallHelper.GetICall<d_LoadFromFile>("UnityEngine.AssetBundle::LoadFromFile_Internal");
var ptr = iCall.Invoke(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0UL);
return new AssetBundle(ptr);
}
// ~~~~~~~~~~~~ Instance ~~~~~~~~~~~~
private readonly IntPtr m_bundlePtr = IntPtr.Zero;
public AssetBundle(IntPtr ptr) { m_bundlePtr = ptr; }
// LoadAllAssets()
internal delegate IntPtr d_LoadAssetWithSubAssets_Internal(IntPtr _this, IntPtr name, IntPtr type);
public UnityEngine.Object[] LoadAllAssets()
{
var iCall = ICallHelper.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal");
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), Il2CppType.Of<UnityEngine.Object>().Pointer);
return new Il2CppReferenceArray<UnityEngine.Object>(ptr);
}
// LoadAsset<T>(string name, Type type)
internal delegate IntPtr d_LoadAsset_Internal(IntPtr _this, IntPtr name, IntPtr type);
public T LoadAsset<T>(string name) where T : UnityEngine.Object
{
var iCall = ICallHelper.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal");
var ptr = iCall.Invoke(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), Il2CppType.Of<T>().Pointer);
return new UnityEngine.Object(ptr).TryCast<T>();
}
}
}
#endif