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

View File

@ -16,10 +16,6 @@ namespace UnityExplorer.UI.Modules
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;
public static readonly string[] DefaultUsing = new string[]
@ -115,26 +111,6 @@ namespace UnityExplorer.UI.Modules
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
{
public static readonly VoidType Value = new VoidType();

View File

@ -150,7 +150,7 @@ namespace UnityExplorer.UI.Modules
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)
{

View File

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

View File

@ -90,7 +90,7 @@ namespace UnityExplorer.UI.Shared
// Preferred text rect height
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)
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 handleObj = UIFactory.CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddGraphic<Image>();
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
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.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddGraphic<Image>();
Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced;
fillImage.color = Color.clear;
@ -124,7 +124,7 @@ public class SliderScrollbar
handleSlideRect.offsetMax = new Vector2(-15f, 0f);
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);
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)
{
lbl.color = defaultTextColor;
@ -103,7 +96,7 @@ namespace UnityExplorer.UI
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
Image image = panelObj.AddGraphic<Image>();
Image image = panelObj.AddComponent<Image>();
image.type = Image.Type.Filled;
image.color = new Color(0.05f, 0.05f, 0.05f);
@ -120,7 +113,7 @@ namespace UnityExplorer.UI
content = new GameObject("Content");
content.transform.parent = panelObj.transform;
Image image2 = content.AddGraphic<Image>();
Image image2 = content.AddComponent<Image>();
image2.type = Image.Type.Filled;
image2.color = new Color(0.1f, 0.1f, 0.1f);
@ -147,7 +140,7 @@ namespace UnityExplorer.UI
gridGroup.cellSize = cellSize;
gridGroup.spacing = spacing;
Image image = groupObj.AddGraphic<Image>();
Image image = groupObj.AddComponent<Image>();
if (color != default)
{
image.color = color;
@ -168,7 +161,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false;
Image image = groupObj.AddGraphic<Image>();
Image image = groupObj.AddComponent<Image>();
if (color != default)
{
image.color = color;
@ -189,7 +182,7 @@ namespace UnityExplorer.UI
horiGroup.childAlignment = TextAnchor.UpperLeft;
horiGroup.childControlWidth = false;
Image image = groupObj.AddGraphic<Image>();
Image image = groupObj.AddComponent<Image>();
if (color != default)
{
image.color = color;
@ -206,7 +199,7 @@ namespace UnityExplorer.UI
//{
// GameObject labelObj = CreateUIObject("Label", parent, thinSize);
// TextMeshProUGUI text = labelObj.AddGraphic<TextMeshProUGUI>();
// TextMeshProUGUI text = labelObj.AddComponent<TextMeshProUGUI>();
// text.alignment = alignment;
// text.richText = true;
@ -218,7 +211,7 @@ namespace UnityExplorer.UI
{
GameObject labelObj = CreateUIObject("Label", parent, thinSize);
Text text = labelObj.AddGraphic<Text>();
Text text = labelObj.AddComponent<Text>();
SetDefaultTextValues(text);
text.alignment = alignment;
text.supportRichText = true;
@ -234,7 +227,7 @@ namespace UnityExplorer.UI
textObj.AddComponent<RectTransform>();
SetParentAndAlign(textObj, buttonObj);
Image image = buttonObj.AddGraphic<Image>();
Image image = buttonObj.AddComponent<Image>();
image.type = Image.Type.Sliced;
image.color = new Color(1, 1, 1, 0.75f);
@ -248,7 +241,7 @@ namespace UnityExplorer.UI
btn.colors = colors;
}
Text text = textObj.AddGraphic<Text>();
Text text = textObj.AddComponent<Text>();
text.text = "Button";
SetDefaultTextValues(text);
text.alignment = TextAnchor.MiddleCenter;
@ -271,7 +264,7 @@ namespace UnityExplorer.UI
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", sliderObj);
GameObject handleObj = CreateUIObject("Handle", handleSlideAreaObj);
Image bgImage = bgObj.AddGraphic<Image>();
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
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.sizeDelta = new Vector2(-20f, 0f);
Image fillImage = fillObj.AddGraphic<Image>();
Image fillImage = fillObj.AddComponent<Image>();
fillImage.type = Image.Type.Sliced;
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.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);
handleObj.GetComponent<RectTransform>().sizeDelta = new Vector2(20f, 0f);
@ -319,11 +312,11 @@ namespace UnityExplorer.UI
GameObject slideAreaObj = CreateUIObject("Sliding Area", scrollObj);
GameObject handleObj = CreateUIObject("Handle", slideAreaObj);
Image scrollImage = scrollObj.AddGraphic<Image>();
Image scrollImage = scrollObj.AddComponent<Image>();
scrollImage.type = Image.Type.Sliced;
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.color = new Color(0.4f, 0.4f, 0.4f);
@ -368,14 +361,14 @@ namespace UnityExplorer.UI
}
#endif
Image bgImage = bgObj.AddGraphic<Image>();
Image bgImage = bgObj.AddComponent<Image>();
bgImage.type = Image.Type.Sliced;
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);
text = labelObj.AddGraphic<Text>();
text = labelObj.AddComponent<Text>();
text.text = "Toggle";
SetDefaultTextValues(text);
@ -425,7 +418,7 @@ namespace UnityExplorer.UI
{
GameObject mainObj = CreateUIObject("InputField", parent);
Image mainImage = mainObj.AddGraphic<Image>();
Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Sliced;
mainImage.color = new Color(0.15f, 0.15f, 0.15f);
@ -463,7 +456,7 @@ namespace UnityExplorer.UI
// mainInput.textViewport = textArea.GetComponent<RectTransform>();
GameObject placeHolderObj = CreateUIObject("Placeholder", textArea);
Text placeholderText = placeHolderObj.AddGraphic<Text>();
Text placeholderText = placeHolderObj.AddComponent<Text>();
SetDefaultTextValues(placeholderText);
placeholderText.text = "...";
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
@ -484,7 +477,7 @@ namespace UnityExplorer.UI
mainInput.placeholder = placeholderText;
GameObject inputTextObj = CreateUIObject("Text", textArea);
Text inputText = inputTextObj.AddGraphic<Text>();
Text inputText = inputTextObj.AddComponent<Text>();
SetDefaultTextValues(inputText);
inputText.text = "";
inputText.color = new Color(1f, 1f, 1f, 1f);
@ -532,11 +525,11 @@ namespace UnityExplorer.UI
scrollRectTransform.pivot = Vector2.one;
scrollRectTransform.sizeDelta = new Vector2(scrollRectTransform.sizeDelta.x, 0f);
Text itemLabelText = itemLabelObj.AddGraphic<Text>();
Text itemLabelText = itemLabelObj.AddComponent<Text>();
SetDefaultTextValues(itemLabelText);
itemLabelText.alignment = TextAnchor.MiddleLeft;
var arrowText = arrowObj.AddGraphic<Text>();
var arrowText = arrowObj.AddComponent<Text>();
SetDefaultTextValues(arrowText);
arrowText.text = "▼";
var arrowRect = arrowObj.GetComponent<RectTransform>();
@ -545,7 +538,7 @@ namespace UnityExplorer.UI
arrowRect.sizeDelta = new Vector2(20f, 20f);
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);
Toggle itemToggle = itemObj.AddComponent<Toggle>();
@ -561,7 +554,7 @@ namespace UnityExplorer.UI
#else
itemToggle.onValueChanged.AddListener((bool val) => { itemToggle.OnDeselect(null); });
#endif
Image templateImage = templateObj.AddGraphic<Image>();
Image templateImage = templateObj.AddComponent<Image>();
templateImage.type = Image.Type.Sliced;
templateImage.color = new Color(0.15f, 0.15f, 0.15f, 1.0f);
@ -577,14 +570,14 @@ namespace UnityExplorer.UI
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
Image viewportImage = viewportObj.AddGraphic<Image>();
Image viewportImage = viewportObj.AddComponent<Image>();
viewportImage.type = Image.Type.Sliced;
Text labelText = labelObj.AddGraphic<Text>();
Text labelText = labelObj.AddComponent<Text>();
SetDefaultTextValues(labelText);
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.type = Image.Type.Sliced;
@ -653,7 +646,7 @@ namespace UnityExplorer.UI
mainLayout.flexibleWidth = 5000;
mainLayout.flexibleHeight = 5000;
Image mainImage = mainObj.AddGraphic<Image>();
Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Filled;
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.offsetMax = new Vector2(-20.0f, 0.0f);
viewportObj.AddGraphic<Image>().color = Color.white;
viewportObj.AddComponent<Image>().color = Color.white;
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
content = CreateUIObject("Content", viewportObj);

View File

@ -20,7 +20,7 @@ namespace UnityExplorer.UI
public static EventSystem EventSys { 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 Font ConsoleFont { get; private set; }