* Cleanup some small bugs introduced in 1.4.0
* Added better exception handling for failed Reflection, and the ability to hide failed reflection members in the Reflection window, as well as see the error type.
* Reflection window members now display the full name instead of just the member name (eg. "Camera.main" instead of just "main").
This commit is contained in:
sinaioutlander
2020-08-22 17:17:11 +10:00
parent 62b1688d53
commit 6bafab785b
13 changed files with 276 additions and 279 deletions

View File

@ -1,35 +1,64 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UnityEngine;
namespace Explorer
{
public class CacheOther : CacheObject
{
private MethodInfo m_toStringMethod;
private bool m_triedToGetMethod;
public MethodInfo ToStringMethod
{
get
{
if (m_toStringMethod == null && !m_triedToGetMethod)
{
if (Value == null) return null;
m_triedToGetMethod = true;
try
{
var methods = ReflectionHelpers.GetActualType(Value)
.GetMethods(ReflectionHelpers.CommonFlags)
.Where(x => x.Name == "ToString")
.GetEnumerator();
while (methods.MoveNext())
{
// just get the first (top-most level) method, then break.
m_toStringMethod = methods.Current;
break;
}
}
catch { }
}
return m_toStringMethod;
}
}
public override void DrawValue(Rect window, float width)
{
string label;
if (Value is UnityEngine.Object uObj)
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
if (!label.Contains(ValueType))
{
label = uObj.name;
label += $" ({ValueType})";
}
else
if (Value is UnityEngine.Object unityObj && !label.Contains(unityObj.name))
{
label = Value.ToString();
}
string typeLabel = Value.GetType().FullName;
if (!label.Contains(typeLabel))
{
label += $" ({typeLabel})";
label = unityObj.name + " | " + label;
}
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.MaxWidth(window.width - 230) }))
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.MaxWidth(width) }))
{
WindowManager.InspectObject(Value, out bool _);
}
@ -38,12 +67,12 @@ namespace Explorer
public override void SetValue()
{
throw new NotImplementedException("TODO");
}
public override void UpdateValue(object obj)
{
//public override void UpdateValue(object obj)
//{
}
//}
}
}