2020-08-22 00:16:05 +10:00
|
|
|
|
using System;
|
2020-08-22 17:17:11 +10:00
|
|
|
|
using System.Collections;
|
2020-08-22 00:16:05 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-08-22 17:17:11 +10:00
|
|
|
|
using System.Reflection;
|
2020-08-22 00:16:05 +10:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Explorer
|
|
|
|
|
{
|
2020-08-29 21:15:54 +10:00
|
|
|
|
public class CacheOther : CacheObjectBase
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-08-22 17:17:11 +10:00
|
|
|
|
private MethodInfo m_toStringMethod;
|
|
|
|
|
private bool m_triedToGetMethod;
|
|
|
|
|
|
|
|
|
|
public MethodInfo ToStringMethod
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-08-22 17:17:11 +10:00
|
|
|
|
get
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-08-22 17:17:11 +10:00
|
|
|
|
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;
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-08-22 17:17:11 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DrawValue(Rect window, float width)
|
|
|
|
|
{
|
|
|
|
|
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
|
|
|
|
|
|
|
|
|
if (!label.Contains(ValueType))
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-08-22 17:17:11 +10:00
|
|
|
|
label += $" ({ValueType})";
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-08-22 17:17:11 +10:00
|
|
|
|
if (Value is UnityEngine.Object unityObj && !label.Contains(unityObj.name))
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-08-22 17:17:11 +10:00
|
|
|
|
label = unityObj.name + " | " + label;
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
2020-08-24 01:42:19 +10:00
|
|
|
|
if (GUILayout.Button("<color=yellow>" + label + "</color>", new GUILayoutOption[] { GUILayout.MaxWidth(width + 40) }))
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
|
|
|
|
WindowManager.InspectObject(Value, out bool _);
|
|
|
|
|
}
|
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|