A few important fixes

* Reflection on Il2CppSystem-namespace instances has been fixed
* Type/Value Syntax highlighting generalized and improved globally
* Scene changes now refresh the scene-picker dropdown
* probably other minor stuff too
This commit is contained in:
sinaioutlander
2020-11-13 18:46:36 +11:00
parent dc449d4a1e
commit bc113e9093
21 changed files with 450 additions and 395 deletions

View File

@ -41,7 +41,7 @@ namespace UnityExplorer.UI.Shared
get => m_currentPage;
set
{
if (value < LastPage)
if (value < PageCount)
m_currentPage = value;
}
}
@ -60,11 +60,11 @@ namespace UnityExplorer.UI.Shared
{
m_listCount = value;
if (LastPage <= 0 && m_pageUIHolder.activeSelf)
if (PageCount <= 0 && m_pageUIHolder.activeSelf)
{
m_pageUIHolder.SetActive(false);
}
else if (LastPage > 0 && !m_pageUIHolder.activeSelf)
else if (PageCount > 0 && !m_pageUIHolder.activeSelf)
{
m_pageUIHolder.SetActive(true);
}
@ -73,7 +73,7 @@ namespace UnityExplorer.UI.Shared
}
}
public int LastPage => (int)Math.Ceiling(ListCount / (decimal)ItemsPerPage) - 1;
public int PageCount => (int)Math.Ceiling(ListCount / (decimal)ItemsPerPage) - 1;
// The index of the first element of the current page
public int StartIndex
@ -138,7 +138,7 @@ namespace UnityExplorer.UI.Shared
}
else
{
if (m_currentPage < LastPage)
if (m_currentPage < PageCount)
{
m_currentPage++;
didTurn = true;
@ -160,7 +160,7 @@ namespace UnityExplorer.UI.Shared
public void RefreshUI()
{
m_currentPageLabel.text = $"Page {m_currentPage + 1} / {LastPage + 1}";
m_currentPageLabel.text = $"Page {m_currentPage + 1} / {PageCount + 1}";
}
public void ConstructUI(GameObject parent)

View File

@ -22,7 +22,7 @@ namespace UnityExplorer.UI.Shared
public const string Local = "#a6e9e9";
public const string StructGreen = "#0e9931";
public const string StructGreen = "#0fba3a";
public static string Enum = "#92c470";
@ -33,7 +33,7 @@ namespace UnityExplorer.UI.Shared
string classColor;
if (type.IsAbstract && type.IsSealed)
classColor = Class_Static;
else if (type.IsEnum)
else if (type.IsEnum || type.IsGenericParameter)
classColor = Enum;
else if (type.IsValueType)
classColor = StructGreen;
@ -43,7 +43,7 @@ namespace UnityExplorer.UI.Shared
return classColor;
}
public static string GetHighlight(Type type, bool includeNamespace, MemberInfo memberInfo = null)
public static string ParseFullSyntax(Type type, bool includeNamespace, MemberInfo memberInfo = null)
{
string ret = "";
@ -55,91 +55,132 @@ namespace UnityExplorer.UI.Shared
}
else
{
string ns = includeNamespace
? $"<color=#{s_silver.ToHex()}>{type.Namespace}</color>."
: "";
ret += ns;
if (includeNamespace && !string.IsNullOrEmpty(type.Namespace))
ret += $"<color=#{s_silver.ToHex()}>{type.Namespace}</color>.";
var declaring = type.DeclaringType;
while (declaring != null)
{
ret += $"<color={GetClassColor(declaring)}>{declaring.Name}</color>.";
ret += HighlightTypeName(declaring) + ".";
declaring = declaring.DeclaringType;
}
ret += $"<color={GetClassColor(type)}>{type.Name}</color>";
ret += HighlightTypeName(type);
}
// todo MemberInfo
if (memberInfo != null)
{
ret += ".";
string memberColor = "";
bool isStatic = false;
string memberColor = GetMemberInfoColor(memberInfo, out bool isStatic);
string memberHighlight = $"<color={memberColor}>{memberInfo.Name}</color>";
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)
memberHighlight = $"<i>{memberHighlight}</i>";
if (isStatic)
ret += "<i>";
ret += $"<color={memberColor}>{memberInfo.Name}</color>";
if (isStatic)
ret += "</i>";
ret += memberHighlight;
// 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 += ">";
}
ret += ParseGenericArgs(gArgs, true);
}
}
return ret;
}
private static string HighlightTypeName(Type type)
{
var typeName = type.Name;
var gArgs = type.GetGenericArguments();
if (gArgs.Length > 0)
{
// remove the `N from the end of the type name
// this could actually be >9 in some cases, so get the length of the length string and use that.
// eg, if it was "List`15", we would remove the ending 3 chars
int suffixLen = 1 + gArgs.Length.ToString().Length;
// make sure the typename actually has expected "`N" format.
if (typeName[typeName.Length - suffixLen] == '`')
typeName = typeName.Substring(0, typeName.Length - suffixLen);
}
// highlight the base name itself
// do this after removing the `N suffix, so only the name itself is in the color tags.
typeName = $"<color={GetClassColor(type)}>{typeName}</color>";
// parse the generic args, if any
if (gArgs.Length > 0)
typeName += ParseGenericArgs(gArgs);
return typeName;
}
private static string ParseGenericArgs(Type[] gArgs, bool allGeneric = false)
{
if (gArgs.Length < 1)
return "";
var args = "<";
for (int i = 0; i < gArgs.Length; i++)
{
if (i > 0)
args += ", ";
var arg = gArgs[i];
if (allGeneric)
{
args += $"<color={Enum}>{arg.Name}</color>";
continue;
}
// using HighlightTypeName makes it recursive, so we can parse nested generic args.
args += HighlightTypeName(arg);
}
return args + ">";
}
private static string GetMemberInfoColor(MemberInfo memberInfo, out bool isStatic)
{
string memberColor = "";
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;
}
return memberColor;
}
}
}