various improvements to reflection inspector and C# console

This commit is contained in:
sinaioutlander 2020-11-12 16:15:41 +11:00
parent 2077601464
commit a7f86227fb
28 changed files with 656 additions and 420 deletions

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

After

Width:  |  Height:  |  Size: 435 KiB

View File

@ -17,7 +17,7 @@ namespace UnityExplorer.Config
// Actual configs // Actual configs
public KeyCode Main_Menu_Toggle = KeyCode.F7; public KeyCode Main_Menu_Toggle = KeyCode.F7;
public bool Force_Unlock_Mouse = true; public bool Force_Unlock_Mouse = true;
public int Default_Page_Limit = 20; public int Default_Page_Limit = 25;
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER; public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER;
public bool Log_Unity_Debug = false; public bool Log_Unity_Debug = false;

View File

@ -44,7 +44,7 @@ namespace UnityExplorer.Console
return; return;
} }
if (!ConsolePage.EnableAutocompletes) if (!CodeEditor.EnableAutocompletes)
{ {
if (m_mainObj.activeSelf) if (m_mainObj.activeSelf)
{ {
@ -187,9 +187,9 @@ namespace UnityExplorer.Console
public static void ClearAutocompletes() public static void ClearAutocompletes()
{ {
if (ConsolePage.AutoCompletes.Any()) if (CodeEditor.AutoCompletes.Any())
{ {
ConsolePage.AutoCompletes.Clear(); CodeEditor.AutoCompletes.Clear();
} }
} }
@ -198,7 +198,7 @@ namespace UnityExplorer.Console
try try
{ {
// Credit ManylMarco // Credit ManylMarco
ConsolePage.AutoCompletes.Clear(); CodeEditor.AutoCompletes.Clear();
string[] completions = ConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix); string[] completions = ConsolePage.Instance.m_evaluator.GetCompletions(input, out string prefix);
if (completions != null) if (completions != null)
{ {
@ -207,7 +207,7 @@ namespace UnityExplorer.Console
prefix = input; prefix = input;
} }
ConsolePage.AutoCompletes.AddRange(completions CodeEditor.AutoCompletes.AddRange(completions
.Where(x => !string.IsNullOrEmpty(x)) .Where(x => !string.IsNullOrEmpty(x))
.Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other)) .Select(x => new Suggestion(x, prefix, Suggestion.Contexts.Other))
); );
@ -226,7 +226,7 @@ namespace UnityExplorer.Console
x.Substring(0, trimmed.Length), x.Substring(0, trimmed.Length),
Suggestion.Contexts.Namespace)); Suggestion.Contexts.Namespace));
ConsolePage.AutoCompletes.AddRange(namespaces); CodeEditor.AutoCompletes.AddRange(namespaces);
IEnumerable<Suggestion> keywords = Suggestion.Keywords IEnumerable<Suggestion> keywords = Suggestion.Keywords
.Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length) .Where(x => x.StartsWith(trimmed) && x.Length > trimmed.Length)
@ -235,7 +235,7 @@ namespace UnityExplorer.Console
x.Substring(0, trimmed.Length), x.Substring(0, trimmed.Length),
Suggestion.Contexts.Keyword)); Suggestion.Contexts.Keyword));
ConsolePage.AutoCompletes.AddRange(keywords); CodeEditor.AutoCompletes.AddRange(keywords);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -290,7 +290,7 @@ namespace UnityExplorer.Console
var hiddenChild = UIFactory.CreateUIObject("HiddenText", buttonObj); var hiddenChild = UIFactory.CreateUIObject("HiddenText", buttonObj);
hiddenChild.SetActive(false); hiddenChild.SetActive(false);
var hiddenText = hiddenChild.AddGraphic<Text>(); var hiddenText = hiddenChild.AddComponent<Text>();
m_hiddenSuggestionTexts.Add(hiddenText); m_hiddenSuggestionTexts.Add(hiddenText);
#if CPP #if CPP
@ -301,9 +301,7 @@ namespace UnityExplorer.Console
void UseAutocompleteButton() void UseAutocompleteButton()
{ {
ConsolePage.Instance.UseAutocomplete(hiddenText.text); ConsolePage.Instance.m_codeEditor.UseAutocomplete(hiddenText.text);
EventSystem.current.SetSelectedGameObject(ConsolePage.Instance.m_codeEditor.InputField.gameObject,
null);
} }
m_suggestionButtons.Add(buttonObj); m_suggestionButtons.Add(buttonObj);

View File

@ -11,11 +11,6 @@ using UnityExplorer.UI.Modules;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using UnityExplorer.UI.Shared; using UnityExplorer.UI.Shared;
#if CPP
using UnityExplorer.Unstrip;
using UnityExplorer.Helpers;
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.Console namespace UnityExplorer.Console
{ {
@ -27,12 +22,22 @@ namespace UnityExplorer.Console
public Text InputText { get; internal set; } public Text InputText { get; internal set; }
public int CurrentIndent { get; private set; } public int CurrentIndent { get; private set; }
public static bool EnableCtrlRShortcut { get; set; } = true;
public static bool EnableAutoIndent { get; set; } = true;
public static bool EnableAutocompletes { get; set; } = true;
public static List<Suggestion> AutoCompletes = new List<Suggestion>();
public string HighlightedText => inputHighlightText.text; public string HighlightedText => inputHighlightText.text;
private Text inputHighlightText; private Text inputHighlightText;
private readonly CSharpLexer highlightLexer; private readonly CSharpLexer highlightLexer;
private readonly StringBuilder sbHighlight; private readonly StringBuilder sbHighlight;
internal int m_lastCaretPos;
internal int m_fixCaretPos;
internal bool m_fixwanted;
internal float m_lastSelectAlpha;
private static readonly KeyCode[] onFocusKeys = private static readonly KeyCode[] onFocusKeys =
{ {
KeyCode.Return, KeyCode.Backspace, KeyCode.UpArrow, KeyCode.Return, KeyCode.Backspace, KeyCode.UpArrow,
@ -76,31 +81,74 @@ The following helper methods are available:
public void Update() public void Update()
{ {
// Check for new line if (EnableCtrlRShortcut)
if (ConsolePage.EnableAutoIndent && InputManager.GetKeyDown(KeyCode.Return))
{ {
if ((InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
&& InputManager.GetKeyDown(KeyCode.R))
{
var text = InputField.text.Trim();
if (!string.IsNullOrEmpty(text))
{
ConsolePage.Instance.Evaluate(text);
return;
}
}
}
if (EnableAutoIndent && InputManager.GetKeyDown(KeyCode.Return))
AutoIndentCaret(); AutoIndentCaret();
if (EnableAutocompletes && InputField.isFocused)
{
if (InputManager.GetMouseButton(0) || onFocusKeys.Any(it => InputManager.GetKeyDown(it)))
UpdateAutocompletes();
} }
if (EventSystem.current?.currentSelectedGameObject?.name == "InputField") if (m_fixCaretPos > 0)
{ {
bool focusKeyPressed = false; if (!m_fixwanted)
m_fixwanted = true;
else
{
InputField.caretPosition = m_fixCaretPos;
InputField.selectionFocusPosition = m_fixCaretPos;
// Check for any focus key pressed m_fixwanted = false;
foreach (KeyCode key in onFocusKeys) m_fixCaretPos = -1;
var color = InputField.selectionColor;
color.a = m_lastSelectAlpha;
InputField.selectionColor = color;
}
}
else if (InputField.caretPosition > 0)
{ {
if (InputManager.GetKeyDown(key)) m_lastCaretPos = InputField.caretPosition;
{
focusKeyPressed = true;
break;
} }
} }
if (focusKeyPressed || InputManager.GetMouseButton(0)) internal void UpdateAutocompletes()
{ {
ConsolePage.Instance.OnInputChanged(); AutoCompleter.CheckAutocomplete();
} AutoCompleter.SetSuggestions(AutoCompletes.ToArray());
} }
public void UseAutocomplete(string suggestion)
{
EventSystem.current.SetSelectedGameObject(ConsolePage.Instance.m_codeEditor.InputField.gameObject, null);
string input = InputField.text;
input = input.Insert(m_lastCaretPos, suggestion);
InputField.text = input;
m_fixCaretPos = m_lastCaretPos += suggestion.Length;
var color = InputField.selectionColor;
m_lastSelectAlpha = color.a;
color.a = 0f;
InputField.selectionColor = color;
AutoCompleter.ClearAutocompletes();
} }
public void OnInputChanged(string newInput, bool forceUpdate = false) public void OnInputChanged(string newInput, bool forceUpdate = false)
@ -110,15 +158,11 @@ The following helper methods are available:
UpdateIndent(newInput); UpdateIndent(newInput);
if (!forceUpdate && string.IsNullOrEmpty(newText)) if (!forceUpdate && string.IsNullOrEmpty(newText))
{
inputHighlightText.text = string.Empty; inputHighlightText.text = string.Empty;
}
else else
{
inputHighlightText.text = SyntaxHighlightContent(newText); inputHighlightText.text = SyntaxHighlightContent(newText);
}
ConsolePage.Instance.OnInputChanged(); UpdateAutocompletes();
} }
private void UpdateIndent(string newText) private void UpdateIndent(string newText)
@ -298,12 +342,32 @@ The following helper methods are available:
var topBarLabel = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft); var topBarLabel = UIFactory.CreateLabel(topBarObj, TextAnchor.MiddleLeft);
var topBarLabelLayout = topBarLabel.AddComponent<LayoutElement>(); var topBarLabelLayout = topBarLabel.AddComponent<LayoutElement>();
topBarLabelLayout.preferredWidth = 800; topBarLabelLayout.preferredWidth = 150;
topBarLabelLayout.flexibleWidth = 10; topBarLabelLayout.flexibleWidth = 5000;
var topBarText = topBarLabel.GetComponent<Text>(); var topBarText = topBarLabel.GetComponent<Text>();
topBarText.text = "C# Console"; topBarText.text = "C# Console";
topBarText.fontSize = 20; topBarText.fontSize = 20;
// Enable Ctrl+R toggle
var ctrlRToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle ctrlRToggle, out Text ctrlRToggleText);
#if CPP
ctrlRToggle.onValueChanged.AddListener(new Action<bool>(CtrlRToggleCallback));
#else
ctrlRToggle.onValueChanged.AddListener(CtrlRToggleCallback);
#endif
void CtrlRToggleCallback(bool val)
{
EnableCtrlRShortcut = val;
}
ctrlRToggleText.text = "Run on Ctrl+R";
ctrlRToggleText.alignment = TextAnchor.UpperLeft;
var ctrlRLayout = ctrlRToggleObj.AddComponent<LayoutElement>();
ctrlRLayout.minWidth = 140;
ctrlRLayout.flexibleWidth = 0;
ctrlRLayout.minHeight = 25;
// Enable Suggestions toggle // Enable Suggestions toggle
var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText); var suggestToggleObj = UIFactory.CreateToggle(topBarObj, out Toggle suggestToggle, out Text suggestToggleText);
@ -314,24 +378,16 @@ The following helper methods are available:
#endif #endif
void SuggestToggleCallback(bool val) void SuggestToggleCallback(bool val)
{ {
ConsolePage.EnableAutocompletes = val; EnableAutocompletes = val;
AutoCompleter.Update(); AutoCompleter.Update();
} }
suggestToggleText.text = "Suggestions"; suggestToggleText.text = "Suggestions";
suggestToggleText.alignment = TextAnchor.UpperLeft; suggestToggleText.alignment = TextAnchor.UpperLeft;
var suggestTextPos = suggestToggleText.transform.localPosition;
suggestTextPos.y = -14;
suggestToggleText.transform.localPosition = suggestTextPos;
var suggestLayout = suggestToggleObj.AddComponent<LayoutElement>(); var suggestLayout = suggestToggleObj.AddComponent<LayoutElement>();
suggestLayout.minWidth = 120; suggestLayout.minWidth = 120;
suggestLayout.flexibleWidth = 0; suggestLayout.flexibleWidth = 0;
suggestLayout.minHeight = 25;
var suggestRect = suggestToggleObj.transform.Find("Background");
var suggestPos = suggestRect.localPosition;
suggestPos.y = -14;
suggestRect.localPosition = suggestPos;
// Enable Auto-indent toggle // Enable Auto-indent toggle
@ -341,22 +397,15 @@ The following helper methods are available:
#else #else
autoIndentToggle.onValueChanged.AddListener(OnIndentChanged); autoIndentToggle.onValueChanged.AddListener(OnIndentChanged);
#endif #endif
void OnIndentChanged(bool val) => ConsolePage.EnableAutoIndent = val; void OnIndentChanged(bool val) => EnableAutoIndent = val;
autoIndentToggleText.text = "Auto-indent"; autoIndentToggleText.text = "Auto-indent";
autoIndentToggleText.alignment = TextAnchor.UpperLeft; autoIndentToggleText.alignment = TextAnchor.UpperLeft;
var autoIndentTextPos = autoIndentToggleText.transform.localPosition;
autoIndentTextPos.y = -14;
autoIndentToggleText.transform.localPosition = autoIndentTextPos;
var autoIndentLayout = autoIndentToggleObj.AddComponent<LayoutElement>(); var autoIndentLayout = autoIndentToggleObj.AddComponent<LayoutElement>();
autoIndentLayout.minWidth = 120; autoIndentLayout.minWidth = 120;
autoIndentLayout.flexibleWidth = 0; autoIndentLayout.flexibleWidth = 0;
autoIndentLayout.minHeight = 25;
var autoIndentRect = autoIndentToggleObj.transform.Find("Background");
suggestPos = autoIndentRect.localPosition;
suggestPos.y = -14;
autoIndentRect.localPosition = suggestPos;
#endregion #endregion
@ -385,7 +434,7 @@ The following helper methods are available:
highlightTextRect.offsetMin = new Vector2(20, 0); highlightTextRect.offsetMin = new Vector2(20, 0);
highlightTextRect.offsetMax = new Vector2(14, 0); highlightTextRect.offsetMax = new Vector2(14, 0);
var highlightTextInput = highlightTextObj.AddGraphic<Text>(); var highlightTextInput = highlightTextObj.AddComponent<Text>();
highlightTextInput.supportRichText = true; highlightTextInput.supportRichText = true;
highlightTextInput.fontSize = fontSize; highlightTextInput.fontSize = fontSize;

View File

@ -15,11 +15,11 @@ namespace UnityExplorer.Console
"mscorlib", "System.Core", "System", "System.Xml" "mscorlib", "System.Core", "System", "System.Xml"
}; };
private readonly TextWriter _logger; private readonly TextWriter tw;
public ScriptEvaluator(TextWriter logger) : base(BuildContext(logger)) public ScriptEvaluator(TextWriter tw) : base(BuildContext(tw))
{ {
_logger = logger; this.tw = tw;
ImportAppdomainAssemblies(ReferenceAssembly); ImportAppdomainAssemblies(ReferenceAssembly);
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad; AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
@ -28,7 +28,7 @@ namespace UnityExplorer.Console
public void Dispose() public void Dispose()
{ {
AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad; AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoad;
_logger.Dispose(); tw.Dispose();
} }
private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args) private void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)

View File

@ -123,6 +123,9 @@ namespace UnityExplorer
{ {
UIManager.Init(); UIManager.Init();
Log("Initialized UnityExplorer UI."); Log("Initialized UnityExplorer UI.");
// temp debug
InspectorManager.Instance.Inspect(Tests.TestClass.Instance);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -237,8 +237,11 @@ namespace UnityExplorer.Helpers
#endif #endif
} }
public static string ExceptionToString(Exception e) public static string ExceptionToString(Exception e, bool innerMost = false)
{ {
while (innerMost && e.InnerException != null)
e = e.InnerException;
return e.GetType() + ", " + e.Message; return e.GetType() + ", " + e.Message;
} }
} }

View File

@ -77,7 +77,7 @@ namespace UnityExplorer.Inspectors.GameObjects
var text = s_compListTexts[i]; var text = s_compListTexts[i];
text.text = ReflectionHelpers.GetActualType(comp).FullName; text.text = UISyntaxHighlight.GetHighlight(ReflectionHelpers.GetActualType(comp), true);
var toggle = s_compToggles[i]; var toggle = s_compToggles[i];
if (comp is Behaviour behaviour) if (comp is Behaviour behaviour)
@ -192,7 +192,7 @@ namespace UnityExplorer.Inspectors.GameObjects
toggleLayout.minHeight = 25; toggleLayout.minHeight = 25;
toggleLayout.flexibleHeight = 0; toggleLayout.flexibleHeight = 0;
var checkImg = toggleObj.transform.Find("Background/Checkmark").GetComponent<Image>(); var checkImg = toggleObj.transform.Find("Background/Checkmark").GetComponent<Image>();
checkImg.color = SyntaxColors.Class_Instance.ToColor(); checkImg.color = UISyntaxHighlight.Class_Instance.ToColor();
checkImg.color *= 0.66f; checkImg.color *= 0.66f;
#if CPP #if CPP
toggle.onValueChanged.AddListener(new Action<bool>((bool val) => { OnCompToggleClicked(thisIndex, val); })); toggle.onValueChanged.AddListener(new Action<bool>((bool val) => { OnCompToggleClicked(thisIndex, val); }));
@ -226,7 +226,7 @@ namespace UnityExplorer.Inspectors.GameObjects
Text mainText = mainButtonObj.GetComponentInChildren<Text>(); Text mainText = mainButtonObj.GetComponentInChildren<Text>();
mainText.alignment = TextAnchor.MiddleLeft; mainText.alignment = TextAnchor.MiddleLeft;
mainText.horizontalOverflow = HorizontalWrapMode.Overflow; mainText.horizontalOverflow = HorizontalWrapMode.Overflow;
mainText.color = SyntaxColors.Class_Instance.ToColor(); //mainText.color = SyntaxColors.Class_Instance.ToColor();
mainText.resizeTextForBestFit = true; mainText.resizeTextForBestFit = true;
mainText.resizeTextMaxSize = 14; mainText.resizeTextMaxSize = 14;
mainText.resizeTextMinSize = 8; mainText.resizeTextMinSize = 8;

View File

@ -7,7 +7,6 @@ using UnityExplorer.UI.Modules;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
//using TMPro;
using UnityExplorer.Inspectors.Reflection; using UnityExplorer.Inspectors.Reflection;
namespace UnityExplorer.Inspectors namespace UnityExplorer.Inspectors
@ -28,8 +27,6 @@ namespace UnityExplorer.Inspectors
public GameObject m_tabBarContent; public GameObject m_tabBarContent;
public GameObject m_inspectorContent; public GameObject m_inspectorContent;
private readonly List<Text> testTexts = new List<Text>();
public void Update() public void Update()
{ {
for (int i = 0; i < m_currentInspectors.Count; i++) for (int i = 0; i < m_currentInspectors.Count; i++)
@ -39,12 +36,6 @@ namespace UnityExplorer.Inspectors
m_currentInspectors[i].Update(); m_currentInspectors[i].Update();
} }
// ======= test ======== //
foreach (var text in testTexts)
{
text.text = Time.time.ToString();
}
} }
public void Inspect(object obj) public void Inspect(object obj)

View File

@ -20,22 +20,13 @@ namespace UnityExplorer.Inspectors.Reflection
} }
public override void UpdateReflection() public override void UpdateReflection()
{
try
{ {
var fi = MemInfo as FieldInfo; var fi = MemInfo as FieldInfo;
IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance); IValue.Value = fi.GetValue(fi.IsStatic ? null : DeclaringInstance);
//base.UpdateValue();
m_evaluated = true; m_evaluated = true;
ReflectionException = null; ReflectionException = null;
} }
catch (Exception e)
{
ReflectionException = ReflectionHelpers.ExceptionToString(e);
}
}
public override void SetValue() public override void SetValue()
{ {

View File

@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityExplorer.UI; using UnityExplorer.UI;
using UnityExplorer.UI.Shared; using UnityExplorer.UI.Shared;
using UnityExplorer.Helpers;
#if CPP #if CPP
using UnhollowerBaseLib; using UnhollowerBaseLib;
#endif #endif
@ -46,14 +47,29 @@ namespace UnityExplorer.Inspectors.Reflection
public override void UpdateValue() public override void UpdateValue()
{ {
if (HasParameters && !m_isEvaluating)
{
// need to enter args first
return;
}
try
{
#if CPP #if CPP
if (!IsReflectionSupported()) if (!IsReflectionSupported())
this.ReflectionException = "Type not supported with Reflection!"; throw new Exception("Type not supported with Reflection");
else
UpdateReflection();
#else
UpdateReflection();
#endif #endif
UpdateReflection();
#if CPP
if (IValue.Value != null)
IValue.Value = IValue.Value.Il2CppCast(ReflectionHelpers.GetActualType(IValue.Value));
#endif
}
catch (Exception e)
{
ReflectionException = ReflectionHelpers.ExceptionToString(e, true);
}
base.UpdateValue(); base.UpdateValue();
} }
@ -137,76 +153,7 @@ namespace UnityExplorer.Inspectors.Reflection
private string GetRichTextName() private string GetRichTextName()
{ {
string memberColor = ""; return m_richTextName = UISyntaxHighlight.GetHighlight(MemInfo.DeclaringType, false, MemInfo);
bool isStatic = false;
if (MemInfo is FieldInfo fi)
{
if (fi.IsStatic)
{
isStatic = true;
memberColor = SyntaxColors.Field_Static;
}
else
memberColor = SyntaxColors.Field_Instance;
}
else if (MemInfo is MethodInfo mi)
{
if (mi.IsStatic)
{
isStatic = true;
memberColor = SyntaxColors.Method_Static;
}
else
memberColor = SyntaxColors.Method_Instance;
}
else if (MemInfo is PropertyInfo pi)
{
if (pi.GetAccessors(true)[0].IsStatic)
{
isStatic = true;
memberColor = SyntaxColors.Prop_Static;
}
else
memberColor = SyntaxColors.Prop_Instance;
}
string classColor;
if (MemInfo.DeclaringType.IsValueType)
{
classColor = SyntaxColors.StructGreen;
}
else if (MemInfo.DeclaringType.IsAbstract && MemInfo.DeclaringType.IsSealed)
{
classColor = SyntaxColors.Class_Static;
}
else
{
classColor = SyntaxColors.Class_Instance;
}
m_richTextName = $"<color={classColor}>{MemInfo.DeclaringType.Name}</color>.";
if (isStatic) m_richTextName += "<i>";
m_richTextName += $"<color={memberColor}>{MemInfo.Name}</color>";
if (isStatic) m_richTextName += "</i>";
// generic method args
if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
{
m_richTextName += "<";
var args = "";
for (int i = 0; i < cm.GenericArgs.Length; i++)
{
if (args != "") args += ", ";
args += $"<color={SyntaxColors.StructGreen}>{cm.GenericArgs[i].Name}</color>";
}
m_richTextName += args;
m_richTextName += ">";
}
return m_richTextName;
} }
#if CPP #if CPP
@ -251,14 +198,109 @@ namespace UnityExplorer.Inspectors.Reflection
} }
#endif #endif
#region UI CONSTRUCTION #region UI
internal float GetMemberLabelWidth(RectTransform scrollRect)
{
var textGenSettings = m_memLabelText.GetGenerationSettings(m_topRowRect.rect.size);
textGenSettings.scaleFactor = InputFieldScroller.canvasScaler.scaleFactor;
var textGen = m_memLabelText.cachedTextGeneratorForLayout;
float preferredWidth = textGen.GetPreferredWidth(RichTextName, textGenSettings);
float max = scrollRect.rect.width * 0.5f;
if (preferredWidth > max) preferredWidth = max;
return preferredWidth < 125f ? 125f : preferredWidth;
}
internal void SetWidths(float labelWidth, float valueWidth)
{
m_leftLayout.preferredWidth = labelWidth;
m_rightLayout.preferredWidth = valueWidth;
}
internal GameObject m_leftGroup;
internal GameObject m_rightGroup;
internal Text m_memLabelText;
internal RectTransform m_topRowRect;
internal LayoutElement m_leftLayout;
internal LayoutElement m_rightLayout;
//internal GameObject m_subGroup;
internal override void ConstructUI() internal override void ConstructUI()
{ {
base.ConstructUI(); base.ConstructUI();
var topGroupObj = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
m_topRowRect = topGroupObj.GetComponent<RectTransform>();
var topLayout = topGroupObj.AddComponent<LayoutElement>();
topLayout.minHeight = 25;
topLayout.flexibleHeight = 0;
topLayout.minWidth = 300;
topLayout.flexibleWidth = 5000;
var topGroup = topGroupObj.GetComponent<HorizontalLayoutGroup>();
topGroup.childForceExpandHeight = false;
topGroup.childForceExpandWidth = false;
topGroup.childControlHeight = true;
topGroup.childControlWidth = true;
topGroup.spacing = 10;
// left group
m_leftGroup = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
var leftLayout = m_leftGroup.AddComponent<LayoutElement>();
leftLayout.minHeight = 25;
leftLayout.flexibleHeight = 0;
leftLayout.minWidth = 125;
leftLayout.flexibleWidth = 200;
var leftGroup = m_leftGroup.GetComponent<HorizontalLayoutGroup>();
leftGroup.childForceExpandHeight = true;
leftGroup.childForceExpandWidth = false;
leftGroup.childControlHeight = true;
leftGroup.childControlWidth = true;
leftGroup.spacing = 4;
// member label
var labelObj = UIFactory.CreateLabel(m_leftGroup, TextAnchor.MiddleLeft);
var leftRect = labelObj.GetComponent<RectTransform>();
leftRect.anchorMin = Vector2.zero;
leftRect.anchorMax = Vector2.one;
leftRect.offsetMin = Vector2.zero;
leftRect.offsetMax = Vector2.zero;
leftRect.sizeDelta = Vector2.zero;
m_leftLayout = labelObj.AddComponent<LayoutElement>();
m_leftLayout.preferredWidth = 225;
m_leftLayout.minHeight = 25;
m_leftLayout.flexibleHeight = 100;
var labelFitter = labelObj.AddComponent<ContentSizeFitter>();
labelFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
labelFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
m_memLabelText = labelObj.GetComponent<Text>();
m_memLabelText.horizontalOverflow = HorizontalWrapMode.Wrap;
m_memLabelText.text = this.RichTextName;
// right group
m_rightGroup = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
m_rightLayout = m_rightGroup.AddComponent<LayoutElement>();
m_rightLayout.minHeight = 25;
m_rightLayout.flexibleHeight = 480;
m_rightLayout.minWidth = 300;
m_rightLayout.flexibleWidth = 5000;
var rightGroup = m_rightGroup.GetComponent<HorizontalLayoutGroup>();
rightGroup.childForceExpandHeight = false;
rightGroup.childForceExpandWidth = true;
rightGroup.childControlHeight = true;
rightGroup.childControlWidth = true;
rightGroup.spacing = 4;
// todo check for HasParameters, etc
if (!HasParameters && IsMember)
{
//var refreshBtnObj = UIFactory.CreateButton(topRowObj, new Color(0.3f, 0.3f, 0.3f)); //var refreshBtnObj = UIFactory.CreateButton(topRowObj, new Color(0.3f, 0.3f, 0.3f));
//var btnLayout = refreshBtnObj.AddComponent<LayoutElement>(); //var btnLayout = refreshBtnObj.AddComponent<LayoutElement>();
//btnLayout.minWidth = 30; //btnLayout.minWidth = 30;
@ -269,15 +311,23 @@ namespace UnityExplorer.Inspectors.Reflection
//refreshTxt.fontSize = 16; //refreshTxt.fontSize = 16;
//var refreshBtn = refreshBtnObj.GetComponent<Button>(); //var refreshBtn = refreshBtnObj.GetComponent<Button>();
//refreshBtn.onClick.AddListener(() => { ExplorerCore.Log("todo Update!"); }); //refreshBtn.onClick.AddListener(() => { ExplorerCore.Log("todo Update!"); });
}
var labelObj = UIFactory.CreateLabel(m_topContent, TextAnchor.MiddleLeft); IValue.ConstructUI(m_rightGroup);
var labellayout = labelObj.AddComponent<LayoutElement>();
labellayout.minWidth = 225;
labellayout.flexibleWidth = 0;
var label = labelObj.GetComponent<Text>(); // todo subcontent
label.horizontalOverflow = HorizontalWrapMode.Wrap;
label.text = this.RichTextName; //m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
//var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
//subGroup.childForceExpandWidth = true;
//subGroup.childControlWidth = true;
//var subLayout = m_subContent.AddComponent<LayoutElement>();
//subLayout.minHeight = 25;
//subLayout.flexibleHeight = 500;
//subLayout.minWidth = 125;
//subLayout.flexibleWidth = 9000;
//m_subContent.SetActive(false);
} }
#endregion #endregion

View File

@ -19,7 +19,7 @@ namespace UnityExplorer.Inspectors.Reflection
public Type[] GenericArgs { get; private set; } public Type[] GenericArgs { get; private set; }
public Type[][] GenericConstraints { get; private set; } public Type[][] GenericConstraints { get; private set; }
public string[] GenericArgInput = new string[0]; public string[] m_genericArgInput = new string[0];
public CacheMethod(MethodInfo methodInfo, object declaringInstance) : base(methodInfo, declaringInstance) public CacheMethod(MethodInfo methodInfo, object declaringInstance) : base(methodInfo, declaringInstance)
{ {
@ -28,7 +28,7 @@ namespace UnityExplorer.Inspectors.Reflection
GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints()) GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
.ToArray(); .ToArray();
GenericArgInput = new string[GenericArgs.Length]; m_genericArgInput = new string[GenericArgs.Length];
m_arguments = methodInfo.GetParameters(); m_arguments = methodInfo.GetParameters();
m_argumentInput = new string[m_arguments.Length]; m_argumentInput = new string[m_arguments.Length];
@ -94,7 +94,7 @@ namespace UnityExplorer.Inspectors.Reflection
var list = new List<Type>(); var list = new List<Type>();
for (int i = 0; i < GenericArgs.Length; i++) for (int i = 0; i < GenericArgs.Length; i++)
{ {
var input = GenericArgInput[i]; var input = m_genericArgInput[i];
if (ReflectionHelpers.GetTypeByName(input) is Type t) if (ReflectionHelpers.GetTypeByName(input) is Type t)
{ {
if (GenericConstraints[i].Length == 0) if (GenericConstraints[i].Length == 0)
@ -118,7 +118,7 @@ namespace UnityExplorer.Inspectors.Reflection
else else
{ {
ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" + ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" +
$" Make sure you use the full name, including the NameSpace."); $" Make sure you use the full name including the namespace.");
return null; return null;
} }
} }

View File

@ -41,7 +41,6 @@ namespace UnityExplorer.Inspectors.Reflection
if (!m_constructedUI) if (!m_constructedUI)
{ {
ConstructUI(); ConstructUI();
IValue.ConstructUI(m_topContent);
UpdateValue(); UpdateValue();
} }
@ -65,8 +64,6 @@ namespace UnityExplorer.Inspectors.Reflection
internal bool m_constructedUI; internal bool m_constructedUI;
internal GameObject m_parentContent; internal GameObject m_parentContent;
internal GameObject m_mainContent; internal GameObject m_mainContent;
internal GameObject m_topContent;
//internal GameObject m_subContent;
// Make base UI holder for CacheObject, this doesnt actually display anything. // Make base UI holder for CacheObject, this doesnt actually display anything.
internal virtual void ConstructUI() internal virtual void ConstructUI()
@ -81,32 +78,9 @@ namespace UnityExplorer.Inspectors.Reflection
rowGroup.childControlHeight = true; rowGroup.childControlHeight = true;
var rowLayout = m_mainContent.AddComponent<LayoutElement>(); var rowLayout = m_mainContent.AddComponent<LayoutElement>();
rowLayout.minHeight = 25; rowLayout.minHeight = 25;
rowLayout.flexibleHeight = 0; rowLayout.flexibleHeight = 500;
rowLayout.minWidth = 200; rowLayout.minWidth = 200;
rowLayout.flexibleWidth = 5000; rowLayout.flexibleWidth = 5000;
m_topContent = UIFactory.CreateHorizontalGroup(m_mainContent, new Color(1, 1, 1, 0));
var topLayout = m_topContent.AddComponent<LayoutElement>();
topLayout.minHeight = 25;
topLayout.flexibleHeight = 0;
var topGroup = m_topContent.GetComponent<HorizontalLayoutGroup>();
topGroup.childForceExpandHeight = false;
topGroup.childForceExpandWidth = true;
topGroup.childControlHeight = true;
topGroup.childControlWidth = true;
topGroup.spacing = 4;
//m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
//var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
//subGroup.childForceExpandWidth = true;
//subGroup.childControlWidth = true;
//var subLayout = m_subContent.AddComponent<LayoutElement>();
//subLayout.minHeight = 25;
//subLayout.flexibleHeight = 500;
//subLayout.minWidth = 125;
//subLayout.flexibleWidth = 9000;
//m_subContent.SetActive(false);
} }
#endregion #endregion

View File

@ -30,18 +30,14 @@ namespace UnityExplorer.Inspectors.Reflection
return; return;
} }
try
{
var pi = MemInfo as PropertyInfo; var pi = MemInfo as PropertyInfo;
if (pi.CanRead) if (pi.CanRead)
{ {
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance; var target = pi.GetAccessors(true)[0].IsStatic ? null : DeclaringInstance;
IValue.Value = pi.GetValue(target, ParseArguments()); IValue.Value = pi.GetValue(target, ParseArguments());
//base.UpdateValue();
m_evaluated = true; m_evaluated = true;
ReflectionException = null; ReflectionException = null;
} }
@ -53,11 +49,6 @@ namespace UnityExplorer.Inspectors.Reflection
IValue.Value = Activator.CreateInstance(IValue.ValueType); IValue.Value = Activator.CreateInstance(IValue.ValueType);
} }
} }
catch (Exception e)
{
ReflectionException = ReflectionHelpers.ExceptionToString(e);
}
}
public override void SetValue() public override void SetValue()
{ {

View File

@ -3,10 +3,12 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using UnityExplorer.Helpers; using UnityExplorer.Helpers;
using UnityExplorer.UI; using UnityExplorer.UI;
using UnityExplorer.UI.Shared; using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip;
namespace UnityExplorer.Inspectors.Reflection namespace UnityExplorer.Inspectors.Reflection
{ {
@ -17,11 +19,12 @@ namespace UnityExplorer.Inspectors.Reflection
public object Value { get; set; } public object Value { get; set; }
public Type ValueType; public Type ValueType;
public string ButtonLabel => m_btnLabel ?? GetButtonLabel(); public string RichTextValue => m_richValue ?? GetRichTextValue();
private string m_btnLabel; internal string m_richValue;
internal string m_richValueType;
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod(); public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
private MethodInfo m_toStringMethod; internal MethodInfo m_toStringMethod;
public virtual void Init() public virtual void Init()
{ {
@ -39,15 +42,14 @@ namespace UnityExplorer.Inspectors.Reflection
return; return;
} }
if (Value == null) GetRichTextValue();
{
m_text.text = "<color=red>null</color>"; m_text.text = RichTextValue;
}
else //if (Value == null)
{ // m_text.text = $"<color=red>null</color> {m_richValueType}";
GetButtonLabel(); //else
m_text.text = ButtonLabel; // m_text.text = RichTextValue;
}
} }
private MethodInfo GetToStringMethod() private MethodInfo GetToStringMethod()
@ -67,85 +69,79 @@ namespace UnityExplorer.Inspectors.Reflection
return m_toStringMethod; return m_toStringMethod;
} }
public string GetButtonLabel()
{
if (Value == null) return "";
var valueType = ReflectionHelpers.GetActualType(Value); public string GetRichTextValue()
{
if (Value != null)
ValueType = Value.GetType();
m_richValueType = UISyntaxHighlight.GetHighlight(ValueType, true);
if (Value == null) return $"<color=grey>null</color> ({m_richValueType})";
string label; string label;
if (valueType == typeof(TextAsset)) if (ValueType == typeof(TextAsset))
{ {
var textAsset = Value as TextAsset; var textAsset = Value as TextAsset;
label = textAsset.text; label = textAsset.text;
if (label.Length > 10) if (label.Length > 10)
{
label = $"{label.Substring(0, 10)}..."; label = $"{label.Substring(0, 10)}...";
}
label = $"\"{label}\" {textAsset.name} (<color={SyntaxColors.Class_Instance}>UnityEngine.TextAsset</color>)"; label = $"\"{label}\" {textAsset.name} ({m_richValueType})";
}
else if (ValueType == typeof(EventSystem))
{
label = m_richValueType;
} }
else else
{ {
label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString(); var toString = (string)ToStringMethod.Invoke(Value, null);
var classColor = valueType.IsAbstract && valueType.IsSealed var temp = toString.Replace(ValueType.FullName, "").Trim();
? SyntaxColors.Class_Static
: SyntaxColors.Class_Instance;
string typeLabel = $"<color={classColor}>{valueType.FullName}</color>"; if (string.IsNullOrEmpty(temp))
if (Value is UnityEngine.Object)
{ {
label = label.Replace($"({valueType.FullName})", $"({typeLabel})"); label = m_richValueType;
} }
else else
{ {
if (!label.Contains(valueType.FullName)) if (toString.Length > 200)
{ toString = toString.Substring(0, 200) + "...";
label += $" ({typeLabel})";
} label = toString;
var unityType = $"({ValueType.FullName})";
if (Value is UnityEngine.Object && label.Contains(unityType))
label = label.Replace(unityType, $"({m_richValueType})");
else else
{ label += $" ({m_richValueType})";
label = label.Replace(valueType.FullName, typeLabel);
}
} }
} }
return m_btnLabel = label; return m_richValue = label;
} }
#region UI CONSTRUCTION #region UI CONSTRUCTION
internal GameObject m_UIContent; internal GameObject m_UIContent;
internal Text m_text; internal Text m_text;
public void ConstructUI(GameObject parent) public void ConstructUI(GameObject parent)
{ {
// TEMPORARY
m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft); m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
var mainLayout = m_UIContent.AddComponent<LayoutElement>(); var mainLayout = m_UIContent.AddComponent<LayoutElement>();
mainLayout.minWidth = 100; mainLayout.minWidth = 200;
mainLayout.flexibleWidth = 5000; mainLayout.flexibleWidth = 5000;
mainLayout.minHeight = 25; mainLayout.minHeight = 25;
m_text = m_UIContent.GetComponent<Text>(); m_text = m_UIContent.GetComponent<Text>();
if (OwnerCacheObject != null) GetRichTextValue();
{ m_text.text = $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
if (!OwnerCacheObject.HasEvaluated)
{
m_text.text = "Not yet evaluated";
}
else
{
m_text.text = ButtonLabel;
}
}
} }
#endregion #endregion
} }
} }

View File

@ -19,8 +19,48 @@ namespace UnityExplorer.Inspectors
public class ReflectionInspector : InspectorBase public class ReflectionInspector : InspectorBase
{ {
#region STATIC
public static ReflectionInspector ActiveInstance { get; private set; }
static ReflectionInspector()
{
PanelDragger.OnFinishResize += OnContainerResized;
SceneExplorer.OnToggleShow += OnContainerResized;
}
private static void OnContainerResized()
{
if (ActiveInstance == null)
return;
ActiveInstance.m_widthUpdateWanted = true;
}
// Blacklists
private static readonly HashSet<string> s_typeAndMemberBlacklist = new HashSet<string>
{
// these cause a crash
"Type.DeclaringMethod",
"Rigidbody2D.Cast",
"Collider2D.Cast",
"Collider2D.Raycast",
};
private static readonly HashSet<string> s_methodStartsWithBlacklist = new HashSet<string>
{
// these are redundant
"get_",
"set_",
};
#endregion
#region INSTANCE
public override string TabLabel => m_targetTypeShortName; public override string TabLabel => m_targetTypeShortName;
public bool AutoUpdate { get; set; }
internal readonly Type m_targetType; internal readonly Type m_targetType;
internal readonly string m_targetTypeShortName; internal readonly string m_targetTypeShortName;
@ -43,22 +83,10 @@ namespace UnityExplorer.Inspectors
internal PageHandler m_pageHandler; internal PageHandler m_pageHandler;
internal SliderScrollbar m_sliderScroller; internal SliderScrollbar m_sliderScroller;
internal GameObject m_scrollContent; internal GameObject m_scrollContent;
internal RectTransform m_scrollContentRect;
// Blacklists internal bool m_widthUpdateWanted;
private static readonly HashSet<string> s_typeAndMemberBlacklist = new HashSet<string> internal bool m_widthUpdateWaiting;
{
// these cause a crash
"Type.DeclaringMethod",
"Rigidbody2D.Cast",
"Collider2D.Cast",
"Collider2D.Raycast",
};
private static readonly HashSet<string> s_methodStartsWithBlacklist = new HashSet<string>
{
// these are redundant
"get_",
"set_",
};
// Ctor // Ctor
@ -80,11 +108,41 @@ namespace UnityExplorer.Inspectors
// Methods // Methods
public override void SetActive()
{
base.SetActive();
ActiveInstance = this;
}
public override void SetInactive()
{
base.SetInactive();
ActiveInstance = null;
}
public override void Update() public override void Update()
{ {
base.Update(); base.Update();
// todo if (AutoUpdate)
{
foreach (var member in m_displayedMembers)
{
member.UpdateValue();
}
}
if (m_widthUpdateWanted)
{
if (!m_widthUpdateWaiting)
m_widthUpdateWaiting = true;
else
{
UpdateWidths();
m_widthUpdateWaiting = false;
m_widthUpdateWanted = false;
}
}
} }
public override void Destroy() public override void Destroy()
@ -100,42 +158,66 @@ namespace UnityExplorer.Inspectors
RefreshDisplay(); RefreshDisplay();
} }
public void RefreshDisplay() public void RefreshDisplay(bool fast = false)
{ {
// TODO TEMP // temp because not doing filtering yet
m_membersFiltered = m_allMembers; m_membersFiltered = m_allMembers;
var members = m_membersFiltered; var members = m_membersFiltered;
m_pageHandler.ListCount = members.Length; m_pageHandler.ListCount = members.Length;
int newCount = 0; if (!fast)
{
// disable current members // disable current members
for (int i = 0; i < m_displayedMembers.Length; i++) for (int i = 0; i < m_displayedMembers.Length; i++)
{ {
var mem = m_displayedMembers[i]; var mem = m_displayedMembers[i];
if (mem != null) if (mem != null)
mem.Disable(); mem.Disable();
else
break;
} }
}
if (members.Length < 1)
return;
foreach (var itemIndex in m_pageHandler) foreach (var itemIndex in m_pageHandler)
{ {
newCount++;
// normalized index starting from 0
var i = itemIndex - m_pageHandler.StartIndex;
if (itemIndex >= members.Length) if (itemIndex >= members.Length)
{
break; break;
}
CacheMember member = members[itemIndex]; CacheMember member = members[itemIndex];
m_displayedMembers[itemIndex - m_pageHandler.StartIndex] = member;
member.Enable(); member.Enable();
}
m_displayedMembers[i] = member; m_widthUpdateWanted = true;
}
internal void UpdateWidths()
{
float labelWidth = 125;
foreach (var cache in m_displayedMembers)
{
if (cache == null)
break;
var width = cache.GetMemberLabelWidth(m_scrollContentRect);
if (width > labelWidth)
labelWidth = width;
}
float valueWidth = m_scrollContentRect.rect.width - labelWidth - 10;
foreach (var cache in m_displayedMembers)
{
if (cache == null)
break;
cache.SetWidths(labelWidth, valueWidth);
} }
} }
@ -249,7 +331,12 @@ namespace UnityExplorer.Inspectors
} }
} }
m_allMembers = list.ToArray(); var sorted = new List<CacheMember>();
sorted.AddRange(list.Where(x => x is CacheMethod));
sorted.AddRange(list.Where(x => x is CacheProperty));
sorted.AddRange(list.Where(x => x is CacheField));
m_allMembers = sorted.ToArray();
// ExplorerCore.Log("Cached " + m_allMembers.Length + " members"); // ExplorerCore.Log("Cached " + m_allMembers.Length + " members");
} }
@ -307,24 +394,24 @@ namespace UnityExplorer.Inspectors
typeLabelLayout.minWidth = 150; typeLabelLayout.minWidth = 150;
typeLabelLayout.flexibleWidth = 5000; typeLabelLayout.flexibleWidth = 5000;
string classColor = SyntaxColors.Class_Instance; typeLabelInput.text = UISyntaxHighlight.GetHighlight(m_targetType, true);
if (m_targetType.IsSealed && m_targetType.IsAbstract)
classColor = SyntaxColors.Class_Static;
else if (m_targetType.IsValueType)
classColor = SyntaxColors.StructGreen;
typeLabelInput.text = $"<color=grey>{m_targetType.Namespace}.</color><color={classColor}>{m_targetType.Name}</color>";
} }
internal void ConstructFilterArea() internal void ConstructFilterArea()
{ {
// todo instance inspector has extra filters
// todo instance inspector "helper tools"
} }
internal void ConstructMemberList() internal void ConstructMemberList()
{ {
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.12f, 0.12f, 0.12f)); var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.12f, 0.12f, 0.12f));
m_scrollContentRect = m_scrollContent.GetComponent<RectTransform>();
var scrollGroup = m_scrollContent.GetComponent<VerticalLayoutGroup>(); var scrollGroup = m_scrollContent.GetComponent<VerticalLayoutGroup>();
scrollGroup.spacing = 3; scrollGroup.spacing = 3;
@ -334,5 +421,7 @@ namespace UnityExplorer.Inspectors
} }
#endregion #endregion
#endregion
} }
} }

View File

@ -15,6 +15,8 @@ namespace UnityExplorer.Inspectors
{ {
public static SceneExplorer Instance; public static SceneExplorer Instance;
internal static Action OnToggleShow;
public SceneExplorer() public SceneExplorer()
{ {
Instance = this; Instance = this;
@ -55,6 +57,7 @@ namespace UnityExplorer.Inspectors
return m_dontDestroyObject; return m_dontDestroyObject;
} }
} }
internal static GameObject m_dontDestroyObject; internal static GameObject m_dontDestroyObject;
public void Init() public void Init()
@ -459,6 +462,8 @@ namespace UnityExplorer.Inspectors
scrollObj.SetActive(true); scrollObj.SetActive(true);
Update(); Update();
} }
OnToggleShow?.Invoke();
} }
} }

View File

@ -16,10 +16,6 @@ namespace UnityExplorer.UI.Modules
public CodeEditor m_codeEditor; public CodeEditor m_codeEditor;
public ScriptEvaluator m_evaluator; 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; public static List<string> UsingDirectives;
public static readonly string[] DefaultUsing = new string[] public static readonly string[] DefaultUsing = new string[]
@ -115,26 +111,6 @@ namespace UnityExplorer.UI.Modules
UsingDirectives = new List<string>(); UsingDirectives = new List<string>();
} }
internal void OnInputChanged()
{
if (!EnableAutocompletes)
return;
AutoCompleter.CheckAutocomplete();
AutoCompleter.SetSuggestions(AutoCompletes.ToArray());
}
public void UseAutocomplete(string suggestion)
{
int cursorIndex = m_codeEditor.InputField.caretPosition;
string input = m_codeEditor.InputField.text;
input = input.Insert(cursorIndex, suggestion);
m_codeEditor.InputField.text = input;
m_codeEditor.InputField.caretPosition += suggestion.Length;
AutoCompleter.ClearAutocompletes();
}
private class VoidType private class VoidType
{ {
public static readonly VoidType Value = new VoidType(); public static readonly VoidType Value = new VoidType();

View File

@ -150,7 +150,7 @@ namespace UnityExplorer.UI.Modules
var text = m_resultListTexts[i]; var text = m_resultListTexts[i];
var name = $"<color={SyntaxColors.Class_Instance}>{ReflectionHelpers.GetActualType(obj).Name}</color>"; var name = $"<color={UISyntaxHighlight.Class_Instance}>{ReflectionHelpers.GetActualType(obj).Name}</color>";
if (m_context != SearchContext.Instance && m_context != SearchContext.StaticClass) if (m_context != SearchContext.Instance && m_context != SearchContext.StaticClass)
{ {

View File

@ -18,6 +18,8 @@ namespace UnityExplorer.UI
public RectTransform Panel { get; set; } public RectTransform Panel { get; set; }
public static event Action OnFinishResize;
private static bool s_loadedCursorImage; private static bool s_loadedCursorImage;
public PanelDragger(RectTransform dragArea, RectTransform panelToDrag) public PanelDragger(RectTransform dragArea, RectTransform panelToDrag)
@ -330,6 +332,7 @@ namespace UnityExplorer.UI
{ {
WasResizing = false; WasResizing = false;
UpdateResizeCache(); UpdateResizeCache();
OnFinishResize?.Invoke();
} }
private void LoadCursorImage() private void LoadCursorImage()
@ -351,7 +354,7 @@ namespace UnityExplorer.UI
m_resizeCursorImage = new GameObject("ResizeCursorImage"); m_resizeCursorImage = new GameObject("ResizeCursorImage");
m_resizeCursorImage.transform.SetParent(UIManager.CanvasRoot.transform); m_resizeCursorImage.transform.SetParent(UIManager.CanvasRoot.transform);
Image image = m_resizeCursorImage.AddGraphic<Image>(); Image image = m_resizeCursorImage.AddComponent<Image>();
image.sprite = sprite; image.sprite = sprite;
RectTransform rect = image.transform.GetComponent<RectTransform>(); RectTransform rect = image.transform.GetComponent<RectTransform>();
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 32); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 32);

View File

@ -90,7 +90,7 @@ namespace UnityExplorer.UI.Shared
// Preferred text rect height // Preferred text rect height
var textGen = inputField.textComponent.cachedTextGeneratorForLayout; var textGen = inputField.textComponent.cachedTextGeneratorForLayout;
float preferredHeight = (textGen.GetPreferredHeight(m_lastText, texGenSettings) / scaleFactor) + 10; float preferredHeight = textGen.GetPreferredHeight(m_lastText, texGenSettings) + 10;
// Default text rect height (fit to scroll parent or expand to fit text) // Default text rect height (fit to scroll parent or expand to fit text)
float minHeight = Mathf.Max(preferredHeight, sliderScroller.m_scrollRect.rect.height - 25); float minHeight = Mathf.Max(preferredHeight, sliderScroller.m_scrollRect.rect.height - 25);

View File

@ -95,7 +95,7 @@ public class SliderScrollbar
GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj); GameObject handleSlideAreaObj = UIFactory.CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj); GameObject handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddGraphic<Image>(); Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced; bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f); bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
@ -111,7 +111,7 @@ public class SliderScrollbar
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f); fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f); fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddGraphic<Image>(); Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced; fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear; fillImage.color = Color.clear;
@ -124,7 +124,7 @@ public class SliderScrollbar
handleSlideRect.offsetMax = new Vector2(-15f, 0f); handleSlideRect.offsetMax = new Vector2(-15f, 0f);
handleSlideRect.sizeDelta = new Vector2(-30f, -30f); handleSlideRect.sizeDelta = new Vector2(-30f, -30f);
Image handleImage = handleObj.AddGraphic<Image>(); Image handleImage = handleObj.AddComponent<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f); handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
var handleRect = handleObj.GetComponent<RectTransform>(); var handleRect = handleObj.GetComponent<RectTransform>();

View File

@ -1,21 +0,0 @@
namespace UnityExplorer.UI.Shared
{
public class SyntaxColors
{
public const string Field_Static = "#8d8dc6";
public const string Field_Instance = "#c266ff";
public const string Method_Static = "#b55b02";
public const string Method_Instance = "#ff8000";
public const string Prop_Static = "#588075";
public const string Prop_Instance = "#55a38e";
public const string Class_Static = "#3a8d71";
public const string Class_Instance = "#2df7b2";
public const string Local = "#a6e9e9";
public const string StructGreen = "#92c470";
}
}

View File

@ -0,0 +1,145 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityExplorer.Unstrip;
namespace UnityExplorer.UI.Shared
{
public class UISyntaxHighlight
{
public const string Field_Static = "#8d8dc6";
public const string Field_Instance = "#c266ff";
public const string Method_Static = "#b55b02";
public const string Method_Instance = "#ff8000";
public const string Prop_Static = "#588075";
public const string Prop_Instance = "#55a38e";
public const string Class_Static = "#3a8d71";
public const string Class_Instance = "#2df7b2";
public const string Local = "#a6e9e9";
public const string StructGreen = "#0e9931";
public static string Enum = "#92c470";
internal static readonly Color s_silver = new Color(0.66f, 0.66f, 0.66f);
internal static string GetClassColor(Type type)
{
string classColor;
if (type.IsAbstract && type.IsSealed)
classColor = Class_Static;
else if (type.IsEnum)
classColor = Enum;
else if (type.IsValueType)
classColor = StructGreen;
else
classColor = Class_Instance;
return classColor;
}
public static string GetHighlight(Type type, bool includeNamespace, MemberInfo memberInfo = null)
{
string ret = "";
if (type.IsGenericParameter
|| type.GetGenericArguments().Any(it => it.IsGenericParameter)
|| (type.HasElementType && type.GetElementType().IsGenericParameter))
{
ret = $"<color={Enum}>{type.Name}</color>";
}
else
{
string ns = includeNamespace
? $"<color=#{s_silver.ToHex()}>{type.Namespace}</color>."
: "";
ret += ns;
var declaring = type.DeclaringType;
while (declaring != null)
{
ret += $"<color={GetClassColor(declaring)}>{declaring.Name}</color>.";
declaring = declaring.DeclaringType;
}
ret += $"<color={GetClassColor(type)}>{type.Name}</color>";
}
// todo MemberInfo
if (memberInfo != null)
{
ret += ".";
string memberColor = "";
bool isStatic = false;
if (memberInfo is FieldInfo fi)
{
if (fi.IsStatic)
{
isStatic = true;
memberColor = Field_Static;
}
else
memberColor = Field_Instance;
}
else if (memberInfo is MethodInfo mi)
{
if (mi.IsStatic)
{
isStatic = true;
memberColor = Method_Static;
}
else
memberColor = Method_Instance;
}
else if (memberInfo is PropertyInfo pi)
{
if (pi.GetAccessors(true)[0].IsStatic)
{
isStatic = true;
memberColor = Prop_Static;
}
else
memberColor = Prop_Instance;
}
if (isStatic)
ret += "<i>";
ret += $"<color={memberColor}>{memberInfo.Name}</color>";
if (isStatic)
ret += "</i>";
// generic method args
if (memberInfo is MethodInfo method)
{
var gArgs = method.GetGenericArguments();
if (gArgs.Length > 0)
{
ret += "<";
var args = "";
for (int i = 0; i < gArgs.Length; i++)
{
if (i > 0) args += ", ";
args += $"<color={Enum}>{gArgs[i].Name}</color>";
}
ret += args;
ret += ">";
}
}
}
return ret;
}
}
}

View File

@ -48,13 +48,6 @@ namespace UnityExplorer.UI
} }
} }
public static T AddGraphic<T>(this GameObject obj) where T : Graphic
{
var ret = obj.AddComponent<T>();
ret.material = UIManager.UIMaterial;
return ret;
}
private static void SetDefaultTextValues(Text lbl) private static void SetDefaultTextValues(Text lbl)
{ {
lbl.color = defaultTextColor; lbl.color = defaultTextColor;
@ -103,7 +96,7 @@ namespace UnityExplorer.UI
rect.anchoredPosition = Vector2.zero; rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero; rect.sizeDelta = Vector2.zero;
Image image = panelObj.AddGraphic<Image>(); Image image = panelObj.AddComponent<Image>();
image.type = Image.Type.Filled; image.type = Image.Type.Filled;
image.color = new Color(0.05f, 0.05f, 0.05f); image.color = new Color(0.05f, 0.05f, 0.05f);
@ -120,7 +113,7 @@ namespace UnityExplorer.UI
content = new GameObject("Content"); content = new GameObject("Content");
content.transform.parent = panelObj.transform; content.transform.parent = panelObj.transform;
Image image2 = content.AddGraphic<Image>(); Image image2 = content.AddComponent<Image>();
image2.type = Image.Type.Filled; image2.type = Image.Type.Filled;
image2.color = new Color(0.1f, 0.1f, 0.1f); image2.color = new Color(0.1f, 0.1f, 0.1f);
@ -147,7 +140,7 @@ namespace UnityExplorer.UI
gridGroup.cellSize = cellSize; gridGroup.cellSize = cellSize;
gridGroup.spacing = spacing; gridGroup.spacing = spacing;
Image image = groupObj.AddGraphic<Image>(); Image image = groupObj.AddComponent<Image>();
if (color != default) if (color != default)
{ {
image.color = color; image.color = color;
@ -168,7 +161,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft; horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false; horiGroup.childControlWidth = false;
Image image = groupObj.AddGraphic<Image>(); Image image = groupObj.AddComponent<Image>();
if (color != default) if (color != default)
{ {
image.color = color; image.color = color;
@ -189,7 +182,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft; horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false; horiGroup.childControlWidth = false;
Image image = groupObj.AddGraphic<Image>(); Image image = groupObj.AddComponent<Image>();
if (color != default) if (color != default)
{ {
image.color = color; image.color = color;
@ -206,7 +199,7 @@ namespace UnityExplorer.UI
//{ //{
// GameObject labelObj = CreateUIObject("Label", parent, thinSize); // GameObject labelObj = CreateUIObject("Label", parent, thinSize);
// TextMeshProUGUI text = labelObj.AddGraphic<TextMeshProUGUI>(); // TextMeshProUGUI text = labelObj.AddComponent<TextMeshProUGUI>();
// text.alignment = alignment; // text.alignment = alignment;
// text.richText = true; // text.richText = true;
@ -218,7 +211,7 @@ namespace UnityExplorer.UI
{ {
GameObject labelObj = CreateUIObject("Label", parent, thinSize); GameObject labelObj = CreateUIObject("Label", parent, thinSize);
Text text = labelObj.AddGraphic<Text>(); Text text = labelObj.AddComponent<Text>();
SetDefaultTextValues(text); SetDefaultTextValues(text);
text.alignment = alignment; text.alignment = alignment;
text.supportRichText = true; text.supportRichText = true;
@ -234,7 +227,7 @@ namespace UnityExplorer.UI
textObj.AddComponent<RectTransform>(); textObj.AddComponent<RectTransform>();
SetParentAndAlign(textObj, buttonObj); SetParentAndAlign(textObj, buttonObj);
Image image = buttonObj.AddGraphic<Image>(); Image image = buttonObj.AddComponent<Image>();
image.type = Image.Type.Sliced; image.type = Image.Type.Sliced;
image.color = new Color(1, 1, 1, 0.75f); image.color = new Color(1, 1, 1, 0.75f);
@ -248,7 +241,7 @@ namespace UnityExplorer.UI
btn.colors = colors; btn.colors = colors;
} }
Text text = textObj.AddGraphic<Text>(); Text text = textObj.AddComponent<Text>();
text.text = "Button"; text.text = "Button";
SetDefaultTextValues(text); SetDefaultTextValues(text);
text.alignment = TextAnchor.MiddleCenter; text.alignment = TextAnchor.MiddleCenter;
@ -271,7 +264,7 @@ namespace UnityExplorer.UI
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj); GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj); GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddGraphic<Image>(); Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced; bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f); bgImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
@ -286,7 +279,7 @@ namespace UnityExplorer.UI
fillAreaRect.anchoredPosition = new Vector2(-5f, 0f); fillAreaRect.anchoredPosition = new Vector2(-5f, 0f);
fillAreaRect.sizeDelta = new Vector2(-20f, 0f); fillAreaRect.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddGraphic<Image>(); Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced; fillImage.type = Image.Type.Sliced;
fillImage.color = new Color(0.3f, 0.3f, 0.3f, 1.0f); fillImage.color = new Color(0.3f, 0.3f, 0.3f, 1.0f);
@ -297,7 +290,7 @@ namespace UnityExplorer.UI
handleSlideRect.anchorMin = new Vector2(0f, 0f); handleSlideRect.anchorMin = new Vector2(0f, 0f);
handleSlideRect.anchorMax = new Vector2(1f, 1f); handleSlideRect.anchorMax = new Vector2(1f, 1f);
Image handleImage = handleObj.AddGraphic<Image>(); Image handleImage = handleObj.AddComponent<Image>();
handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f); handleImage.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
handleObj.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 0f); handleObj.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 0f);
@ -319,11 +312,11 @@ namespace UnityExplorer.UI
GameObject slideAreaObj = CreateUIObject("Sliding Area", scrollObj); GameObject slideAreaObj = CreateUIObject("Sliding Area", scrollObj);
GameObject handleObj = CreateUIObject("Handle", slideAreaObj); GameObject handleObj = CreateUIObject("Handle", slideAreaObj);
Image scrollImage = scrollObj.AddGraphic<Image>(); Image scrollImage = scrollObj.AddComponent<Image>();
scrollImage.type = Image.Type.Sliced; scrollImage.type = Image.Type.Sliced;
scrollImage.color = new Color(0.1f, 0.1f, 0.1f); scrollImage.color = new Color(0.1f, 0.1f, 0.1f);
Image handleImage = handleObj.AddGraphic<Image>(); Image handleImage = handleObj.AddComponent<Image>();
handleImage.type = Image.Type.Sliced; handleImage.type = Image.Type.Sliced;
handleImage.color = new Color(0.4f, 0.4f, 0.4f); handleImage.color = new Color(0.4f, 0.4f, 0.4f);
@ -368,14 +361,14 @@ namespace UnityExplorer.UI
} }
#endif #endif
Image bgImage = bgObj.AddGraphic<Image>(); Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced; bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f); bgImage.color = new Color(0.1f, 0.1f, 0.1f, 1.0f);
Image checkImage = checkObj.AddGraphic<Image>(); Image checkImage = checkObj.AddComponent<Image>();
checkImage.color = new Color(90f / 255f, 115f / 255f, 90f / 255f, 1.0f); checkImage.color = new Color(90f / 255f, 115f / 255f, 90f / 255f, 1.0f);
text = labelObj.AddGraphic<Text>(); text = labelObj.AddComponent<Text>();
text.text = "Toggle"; text.text = "Toggle";
SetDefaultTextValues(text); SetDefaultTextValues(text);
@ -425,7 +418,7 @@ namespace UnityExplorer.UI
{ {
GameObject mainObj = CreateUIObject("InputField", parent); GameObject mainObj = CreateUIObject("InputField", parent);
Image mainImage = mainObj.AddGraphic<Image>(); Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Sliced; mainImage.type = Image.Type.Sliced;
mainImage.color = new Color(0.15f, 0.15f, 0.15f); mainImage.color = new Color(0.15f, 0.15f, 0.15f);
@ -463,7 +456,7 @@ namespace UnityExplorer.UI
// mainInput.textViewport = textArea.GetComponent<RectTransform>(); // mainInput.textViewport = textArea.GetComponent<RectTransform>();
GameObject placeHolderObj = CreateUIObject("Placeholder", textArea); GameObject placeHolderObj = CreateUIObject("Placeholder", textArea);
Text placeholderText = placeHolderObj.AddGraphic<Text>(); Text placeholderText = placeHolderObj.AddComponent<Text>();
SetDefaultTextValues(placeholderText); SetDefaultTextValues(placeholderText);
placeholderText.text = "..."; placeholderText.text = "...";
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f); placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
@ -484,7 +477,7 @@ namespace UnityExplorer.UI
mainInput.placeholder = placeholderText; mainInput.placeholder = placeholderText;
GameObject inputTextObj = CreateUIObject("Text", textArea); GameObject inputTextObj = CreateUIObject("Text", textArea);
Text inputText = inputTextObj.AddGraphic<Text>(); Text inputText = inputTextObj.AddComponent<Text>();
SetDefaultTextValues(inputText); SetDefaultTextValues(inputText);
inputText.text = ""; inputText.text = "";
inputText.color = new Color(1f, 1f, 1f, 1f); inputText.color = new Color(1f, 1f, 1f, 1f);
@ -532,11 +525,11 @@ namespace UnityExplorer.UI
scrollRectTransform.pivot = Vector2.one; scrollRectTransform.pivot = Vector2.one;
scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, 0f); scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, 0f);
Text itemLabelText = itemLabelObj.AddGraphic<Text>(); Text itemLabelText = itemLabelObj.AddComponent<Text>();
SetDefaultTextValues(itemLabelText); SetDefaultTextValues(itemLabelText);
itemLabelText.alignment = TextAnchor.MiddleLeft; itemLabelText.alignment = TextAnchor.MiddleLeft;
var arrowText = arrowObj.AddGraphic<Text>(); var arrowText = arrowObj.AddComponent<Text>();
SetDefaultTextValues(arrowText); SetDefaultTextValues(arrowText);
arrowText.text = "▼"; arrowText.text = "▼";
var arrowRect = arrowObj.GetComponent<RectTransform>(); var arrowRect = arrowObj.GetComponent<RectTransform>();
@ -545,7 +538,7 @@ namespace UnityExplorer.UI
arrowRect.sizeDelta = new Vector2(20f, 20f); arrowRect.sizeDelta = new Vector2(20f, 20f);
arrowRect.anchoredPosition = new Vector2(-15f, 0f); arrowRect.anchoredPosition = new Vector2(-15f, 0f);
Image itemBgImage = itemBgObj.AddGraphic<Image>(); Image itemBgImage = itemBgObj.AddComponent<Image>();
itemBgImage.color = new Color(0.25f, 0.45f, 0.25f, 1.0f); itemBgImage.color = new Color(0.25f, 0.45f, 0.25f, 1.0f);
Toggle itemToggle = itemObj.AddComponent<Toggle>(); Toggle itemToggle = itemObj.AddComponent<Toggle>();
@ -561,7 +554,7 @@ namespace UnityExplorer.UI
#else #else
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); }); itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
#endif #endif
Image templateImage = templateObj.AddGraphic<Image>(); Image templateImage = templateObj.AddComponent<Image>();
templateImage.type = Image.Type.Sliced; templateImage.type = Image.Type.Sliced;
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f); templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
@ -577,14 +570,14 @@ namespace UnityExplorer.UI
viewportObj.AddComponent<Mask>().showMaskGraphic = false; viewportObj.AddComponent<Mask>().showMaskGraphic = false;
Image viewportImage = viewportObj.AddGraphic<Image>(); Image viewportImage = viewportObj.AddComponent<Image>();
viewportImage.type = Image.Type.Sliced; viewportImage.type = Image.Type.Sliced;
Text labelText = labelObj.AddGraphic<Text>(); Text labelText = labelObj.AddComponent<Text>();
SetDefaultTextValues(labelText); SetDefaultTextValues(labelText);
labelText.alignment = TextAnchor.MiddleLeft; labelText.alignment = TextAnchor.MiddleLeft;
Image dropdownImage = dropdownObj.AddGraphic<Image>(); Image dropdownImage = dropdownObj.AddComponent<Image>();
dropdownImage.color = new Color(0.2f, 0.2f, 0.2f, 1); dropdownImage.color = new Color(0.2f, 0.2f, 0.2f, 1);
dropdownImage.type = Image.Type.Sliced; dropdownImage.type = Image.Type.Sliced;
@ -653,7 +646,7 @@ namespace UnityExplorer.UI
mainLayout.flexibleWidth = 5000; mainLayout.flexibleWidth = 5000;
mainLayout.flexibleHeight = 5000; mainLayout.flexibleHeight = 5000;
Image mainImage = mainObj.AddGraphic<Image>(); Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Filled; mainImage.type = Image.Type.Filled;
mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color; mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
@ -666,7 +659,7 @@ namespace UnityExplorer.UI
viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f); viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f);
viewportRect.offsetMax = new Vector2(-20.0f, 0.0f); viewportRect.offsetMax = new Vector2(-20.0f, 0.0f);
viewportObj.AddGraphic<Image>().color = Color.white; viewportObj.AddComponent<Image>().color = Color.white;
viewportObj.AddComponent<Mask>().showMaskGraphic = false; viewportObj.AddComponent<Mask>().showMaskGraphic = false;
content = CreateUIObject("Content", viewportObj); content = CreateUIObject("Content", viewportObj);

View File

@ -20,7 +20,7 @@ namespace UnityExplorer.UI
public static EventSystem EventSys { get; private set; } public static EventSystem EventSys { get; private set; }
public static StandaloneInputModule InputModule { get; private set; } public static StandaloneInputModule InputModule { get; private set; }
internal static Material UIMaterial { get; private set; } //internal static Material UIMaterial { get; private set; }
internal static Sprite ResizeCursor { get; private set; } internal static Sprite ResizeCursor { get; private set; }
internal static Font ConsoleFont { get; private set; } internal static Font ConsoleFont { get; private set; }

View File

@ -378,7 +378,7 @@
<Compile Include="UI\Shared\InputFieldScroller.cs" /> <Compile Include="UI\Shared\InputFieldScroller.cs" />
<Compile Include="UI\Shared\SliderScrollbar.cs" /> <Compile Include="UI\Shared\SliderScrollbar.cs" />
<Compile Include="UI\Shared\PageHandler.cs" /> <Compile Include="UI\Shared\PageHandler.cs" />
<Compile Include="UI\Shared\SyntaxColors.cs" /> <Compile Include="UI\Shared\UISyntaxHighlight.cs" />
<Compile Include="UI\UIManager.cs" /> <Compile Include="UI\UIManager.cs" />
<Compile Include="Unstrip\AssetBundleUnstrip.cs" /> <Compile Include="Unstrip\AssetBundleUnstrip.cs" />
<Compile Include="Unstrip\ColorUtilityUnstrip.cs" /> <Compile Include="Unstrip\ColorUtilityUnstrip.cs" />