2020-11-09 21:38:25 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEngine;
|
2020-11-12 16:15:41 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
using UnityEngine.UI;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
using UnityExplorer.Helpers;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
using UnityExplorer.UI.Shared;
|
2020-11-12 16:15:41 +11:00
|
|
|
|
using UnityExplorer.Unstrip;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
|
|
|
|
public class InteractiveValue
|
|
|
|
|
{
|
|
|
|
|
public CacheObjectBase OwnerCacheObject;
|
|
|
|
|
|
|
|
|
|
public object Value { get; set; }
|
|
|
|
|
public Type ValueType;
|
|
|
|
|
|
2020-11-12 20:31:08 +11:00
|
|
|
|
// might not need
|
|
|
|
|
public virtual bool HasSubContent => false;
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
public string RichTextValue => m_richValue ?? GetRichTextValue();
|
|
|
|
|
internal string m_richValue;
|
|
|
|
|
internal string m_richValueType;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod();
|
2020-11-12 16:15:41 +11:00
|
|
|
|
internal MethodInfo m_toStringMethod;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
public virtual void Init()
|
|
|
|
|
{
|
|
|
|
|
UpdateValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void UpdateValue()
|
|
|
|
|
{
|
2020-11-11 20:16:43 +11:00
|
|
|
|
if (!m_text)
|
|
|
|
|
return;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-11 20:16:43 +11:00
|
|
|
|
if (OwnerCacheObject is CacheMember ownerMember && !string.IsNullOrEmpty(ownerMember.ReflectionException))
|
|
|
|
|
{
|
|
|
|
|
m_text.text = "<color=red>" + ownerMember.ReflectionException + "</color>";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
GetRichTextValue();
|
|
|
|
|
|
|
|
|
|
m_text.text = RichTextValue;
|
|
|
|
|
|
|
|
|
|
//if (Value == null)
|
|
|
|
|
// m_text.text = $"<color=red>null</color> {m_richValueType}";
|
|
|
|
|
//else
|
|
|
|
|
// m_text.text = RichTextValue;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
}
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
private MethodInfo GetToStringMethod()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_toStringMethod = ReflectionHelpers.GetActualType(Value).GetMethod("ToString", new Type[0])
|
|
|
|
|
?? typeof(object).GetMethod("ToString", new Type[0]);
|
|
|
|
|
|
|
|
|
|
// test invoke
|
|
|
|
|
m_toStringMethod.Invoke(Value, null);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
m_toStringMethod = typeof(object).GetMethod("ToString", new Type[0]);
|
|
|
|
|
}
|
|
|
|
|
return m_toStringMethod;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
public string GetRichTextValue()
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (Value != null)
|
|
|
|
|
ValueType = Value.GetType();
|
|
|
|
|
|
|
|
|
|
m_richValueType = UISyntaxHighlight.GetHighlight(ValueType, true);
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 20:31:08 +11:00
|
|
|
|
if (OwnerCacheObject is CacheMember cm && !cm.HasEvaluated)
|
|
|
|
|
return $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (Value == null) return $"<color=grey>null</color> ({m_richValueType})";
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
|
|
|
|
string label;
|
|
|
|
|
|
2020-11-12 20:31:08 +11:00
|
|
|
|
if (ValueType == typeof(TextAsset) && Value is TextAsset textAsset)
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
|
|
|
|
label = textAsset.text;
|
|
|
|
|
|
|
|
|
|
if (label.Length > 10)
|
|
|
|
|
label = $"{label.Substring(0, 10)}...";
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
label = $"\"{label}\" {textAsset.name} ({m_richValueType})";
|
|
|
|
|
}
|
|
|
|
|
else if (ValueType == typeof(EventSystem))
|
|
|
|
|
{
|
|
|
|
|
label = m_richValueType;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-12 16:15:41 +11:00
|
|
|
|
var toString = (string)ToStringMethod.Invoke(Value, null);
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
var temp = toString.Replace(ValueType.FullName, "").Trim();
|
2020-11-09 21:38:25 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (string.IsNullOrEmpty(temp))
|
2020-11-09 21:38:25 +11:00
|
|
|
|
{
|
2020-11-12 16:15:41 +11:00
|
|
|
|
label = m_richValueType;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-12 16:15:41 +11:00
|
|
|
|
if (toString.Length > 200)
|
|
|
|
|
toString = toString.Substring(0, 200) + "...";
|
|
|
|
|
|
|
|
|
|
label = toString;
|
|
|
|
|
|
|
|
|
|
var unityType = $"({ValueType.FullName})";
|
|
|
|
|
if (Value is UnityEngine.Object && label.Contains(unityType))
|
|
|
|
|
label = label.Replace(unityType, $"({m_richValueType})");
|
2020-11-09 21:38:25 +11:00
|
|
|
|
else
|
2020-11-12 16:15:41 +11:00
|
|
|
|
label += $" ({m_richValueType})";
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
return m_richValue = label;
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
#region UI CONSTRUCTION
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
|
|
|
|
internal GameObject m_UIContent;
|
|
|
|
|
internal Text m_text;
|
2020-11-12 20:31:08 +11:00
|
|
|
|
internal GameObject m_subContentParent;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
|
2020-11-12 20:31:08 +11:00
|
|
|
|
public virtual void ConstructUI(GameObject parent, GameObject subGroup)
|
2020-11-11 20:16:43 +11:00
|
|
|
|
{
|
|
|
|
|
m_UIContent = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
|
|
|
|
|
var mainLayout = m_UIContent.AddComponent<LayoutElement>();
|
2020-11-12 16:15:41 +11:00
|
|
|
|
mainLayout.minWidth = 200;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
mainLayout.flexibleWidth = 5000;
|
|
|
|
|
mainLayout.minHeight = 25;
|
|
|
|
|
m_text = m_UIContent.GetComponent<Text>();
|
2020-11-12 16:15:41 +11:00
|
|
|
|
|
2020-11-12 20:31:08 +11:00
|
|
|
|
m_subContentParent = subGroup;
|
2020-11-11 20:16:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 16:15:41 +11:00
|
|
|
|
#endregion
|
2020-11-09 21:38:25 +11:00
|
|
|
|
}
|
|
|
|
|
}
|