2020-08-22 00:16:05 +10:00
|
|
|
|
using System;
|
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-09-16 20:03:57 +10:00
|
|
|
|
public string ButtonLabel => m_btnLabel ?? GetButtonLabel();
|
|
|
|
|
private string m_btnLabel;
|
|
|
|
|
|
|
|
|
|
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
2020-08-22 17:17:11 +10:00
|
|
|
|
private MethodInfo m_toStringMethod;
|
|
|
|
|
|
2020-09-18 23:10:46 +10:00
|
|
|
|
public override void UpdateValue()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateValue();
|
|
|
|
|
|
|
|
|
|
GetButtonLabel();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
public override void DrawValue(Rect window, float width)
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-09-16 20:03:57 +10:00
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
|
|
|
|
if (GUILayout.Button(ButtonLabel, new GUILayoutOption[] { GUILayout.Width(width - 15) }))
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-09-16 20:03:57 +10:00
|
|
|
|
WindowManager.InspectObject(Value, out bool _);
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-09-16 20:03:57 +10:00
|
|
|
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
2020-08-22 17:17:11 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
private MethodInfo GetToStringMethod()
|
2020-08-22 17:17:11 +10:00
|
|
|
|
{
|
2020-09-16 20:03:57 +10:00
|
|
|
|
try
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-09-16 20:03:57 +10:00
|
|
|
|
m_toStringMethod = ReflectionHelpers.GetActualType(Value).GetMethod("ToString", new Type[0])
|
|
|
|
|
?? typeof(object).GetMethod("ToString", new Type[0]);
|
|
|
|
|
|
|
|
|
|
// test invoke
|
|
|
|
|
m_toStringMethod.Invoke(Value, null);
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-09-16 20:03:57 +10:00
|
|
|
|
catch
|
2020-09-09 19:15:47 +10:00
|
|
|
|
{
|
2020-09-16 20:03:57 +10:00
|
|
|
|
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
2020-09-09 19:15:47 +10:00
|
|
|
|
}
|
2020-09-16 20:03:57 +10:00
|
|
|
|
return m_toStringMethod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetButtonLabel()
|
|
|
|
|
{
|
2020-09-18 23:10:46 +10:00
|
|
|
|
if (Value == null) return null;
|
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
string label = (string)ToStringMethod?.Invoke(Value, null) ?? Value.ToString();
|
2020-09-09 19:15:47 +10:00
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
var classColor = ValueType.IsAbstract && ValueType.IsSealed
|
|
|
|
|
? UIStyles.Syntax.Class_Static
|
|
|
|
|
: UIStyles.Syntax.Class_Instance;
|
|
|
|
|
|
2020-09-19 01:44:38 +10:00
|
|
|
|
string typeLabel = $"<color={classColor}>{ValueType.FullName}</color>";
|
|
|
|
|
|
2020-09-16 20:03:57 +10:00
|
|
|
|
if (Value is UnityEngine.Object)
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-09-19 01:44:38 +10:00
|
|
|
|
label = label.Replace($"({ValueType.FullName})", $"({typeLabel})");
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-09-16 20:03:57 +10:00
|
|
|
|
else
|
2020-08-22 00:16:05 +10:00
|
|
|
|
{
|
2020-09-19 01:44:38 +10:00
|
|
|
|
if (!label.Contains(ValueType.FullName))
|
2020-09-16 20:03:57 +10:00
|
|
|
|
{
|
2020-09-19 01:44:38 +10:00
|
|
|
|
label += $" ({typeLabel})";
|
2020-09-16 20:03:57 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-19 01:44:38 +10:00
|
|
|
|
label = label.Replace(ValueType.FullName, typeLabel);
|
2020-09-16 20:03:57 +10:00
|
|
|
|
}
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
2020-09-16 20:03:57 +10:00
|
|
|
|
|
|
|
|
|
return m_btnLabel = label;
|
2020-08-22 00:16:05 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|