mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-03 03:52:28 +08:00
1.4.1
* 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:
@ -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)
|
||||
//{
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user