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

@ -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;
}
}
}