mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-15 15:57:52 +08:00
Progress on ReflectionInspector, framework mostly done
This commit is contained in:
@ -10,11 +10,14 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
{
|
||||
public FieldInfo FieldInfo { get; internal set; }
|
||||
|
||||
public override bool ShouldAutoEvaluate => true;
|
||||
|
||||
public override void Initialize(ReflectionInspector inspector, Type declaringType, MemberInfo member, Type returnType)
|
||||
{
|
||||
base.Initialize(inspector, declaringType, member, returnType);
|
||||
|
||||
CanWrite = true;
|
||||
// not constant
|
||||
CanWrite = !(FieldInfo.IsLiteral && !FieldInfo.IsInitOnly);
|
||||
}
|
||||
|
||||
protected override void TryEvaluate()
|
||||
|
@ -3,11 +3,15 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityExplorer.UI.Inspectors.CacheObject.Views;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
{
|
||||
// TODO some of this can be reused for CacheEnumerated / CacheKVP as well, just doing members for now.
|
||||
// Will put shared stuff in CacheObjectBase.
|
||||
|
||||
public abstract class CacheMember : CacheObjectBase
|
||||
{
|
||||
public ReflectionInspector ParentInspector { get; internal set; }
|
||||
@ -18,8 +22,9 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
public object Value { get; protected set; }
|
||||
public Type FallbackType { get; private set; }
|
||||
|
||||
public bool HasEvaluated { get; protected set; }
|
||||
public bool HasArguments { get; protected set; }
|
||||
public abstract bool ShouldAutoEvaluate { get; }
|
||||
public bool HasArguments => Arguments?.Length > 0;
|
||||
public ParameterInfo[] Arguments { get; protected set; }
|
||||
public bool Evaluating { get; protected set; }
|
||||
public bool CanWrite { get; protected set; }
|
||||
public bool HadException { get; protected set; }
|
||||
@ -29,6 +34,20 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
public string TypeLabelText { get; protected set; }
|
||||
public string ValueLabelText { get; protected set; }
|
||||
|
||||
public enum ValueState
|
||||
{
|
||||
NotEvaluated, Exception, NullValue,
|
||||
Boolean, Number, String, Enum,
|
||||
Collection, ValueStruct, Unsupported
|
||||
}
|
||||
|
||||
protected ValueState State = ValueState.NotEvaluated;
|
||||
|
||||
private const string NOT_YET_EVAL = "<color=grey>Not yet evaluated</color>";
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the CacheMember when an Inspector is opened and caches the member
|
||||
/// </summary>
|
||||
public virtual void Initialize(ReflectionInspector inspector, Type declaringType, MemberInfo member, Type returnType)
|
||||
{
|
||||
this.DeclaringType = declaringType;
|
||||
@ -36,72 +55,183 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
this.FallbackType = returnType;
|
||||
this.MemberLabelText = SignatureHighlighter.ParseFullSyntax(declaringType, false, member);
|
||||
this.NameForFiltering = $"{declaringType.Name}.{member.Name}";
|
||||
this.TypeLabelText = SignatureHighlighter.HighlightTypeName(returnType);
|
||||
this.TypeLabelText = SignatureHighlighter.HighlightTypeName(FallbackType, false);
|
||||
this.ValueLabelText = GetValueLabel();
|
||||
}
|
||||
|
||||
public void SetCell(CacheMemberCell cell)
|
||||
public virtual void OnDestroyed()
|
||||
{
|
||||
cell.MemberLabel.text = MemberLabelText;
|
||||
cell.TypeLabel.text = TypeLabelText;
|
||||
|
||||
if (HasArguments && !HasEvaluated)
|
||||
{
|
||||
// todo
|
||||
cell.ValueLabel.text = "Not yet evalulated";
|
||||
}
|
||||
else if (!HasEvaluated)
|
||||
Evaluate();
|
||||
|
||||
if (HadException)
|
||||
{
|
||||
cell.InspectButton.Button.gameObject.SetActive(false);
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
cell.ValueLabel.supportRichText = true;
|
||||
cell.ValueLabel.text = $"<color=red>{ReflectionUtility.ReflectionExToString(LastException)}</color>";
|
||||
}
|
||||
else if (Value.IsNullOrDestroyed())
|
||||
{
|
||||
cell.InspectButton.Button.gameObject.SetActive(false);
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
cell.ValueLabel.supportRichText = true;
|
||||
cell.ValueLabel.text = ValueLabelText;
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.ValueLabel.supportRichText = false;
|
||||
cell.ValueLabel.text = ValueLabelText;
|
||||
|
||||
var valueType = Value.GetActualType();
|
||||
if (valueType.IsPrimitive || valueType == typeof(decimal))
|
||||
{
|
||||
cell.InspectButton.Button.gameObject.SetActive(false);
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
}
|
||||
else if (valueType == typeof(string))
|
||||
{
|
||||
cell.InspectButton.Button.gameObject.SetActive(false);
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.InspectButton.Button.gameObject.SetActive(true);
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
// TODO release IValue / Evaluate back to pool, etc
|
||||
}
|
||||
|
||||
protected abstract void TryEvaluate();
|
||||
|
||||
/// <summary>
|
||||
/// Evaluate when first shown (if ShouldAutoEvaluate), or else when Evaluate button is clicked.
|
||||
/// </summary>
|
||||
public void Evaluate()
|
||||
{
|
||||
TryEvaluate();
|
||||
|
||||
if (!HadException)
|
||||
ProcessOnEvaluate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process the CacheMember state when the value has been evaluated (or re-evaluated)
|
||||
/// </summary>
|
||||
protected virtual void ProcessOnEvaluate()
|
||||
{
|
||||
var prevState = State;
|
||||
|
||||
if (HadException)
|
||||
State = ValueState.Exception;
|
||||
else if (Value.IsNullOrDestroyed())
|
||||
State = ValueState.NullValue;
|
||||
else
|
||||
{
|
||||
ValueLabelText = ToStringUtility.ToString(Value, FallbackType);
|
||||
var type = Value.GetActualType();
|
||||
|
||||
if (type == typeof(bool))
|
||||
State = ValueState.Boolean;
|
||||
else if (type.IsPrimitive || type == typeof(decimal))
|
||||
State = ValueState.Number;
|
||||
else if (type == typeof(string))
|
||||
State = ValueState.String;
|
||||
else if (type.IsEnum)
|
||||
State = ValueState.Enum;
|
||||
else if (type.IsEnumerable() || type.IsDictionary())
|
||||
State = ValueState.Collection;
|
||||
// todo Color and ValueStruct
|
||||
else
|
||||
State = ValueState.Unsupported;
|
||||
}
|
||||
|
||||
HasEvaluated = true;
|
||||
// Set label text
|
||||
ValueLabelText = GetValueLabel();
|
||||
|
||||
if (State != prevState)
|
||||
{
|
||||
// TODO handle if subcontent / evaluate shown, check type change, etc
|
||||
}
|
||||
}
|
||||
|
||||
private string GetValueLabel()
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case ValueState.NotEvaluated:
|
||||
return $"<i>{NOT_YET_EVAL} ({SignatureHighlighter.HighlightTypeName(FallbackType, true)})</i>";
|
||||
case ValueState.Exception:
|
||||
return $"<i><color=red>{ReflectionUtility.ReflectionExToString(LastException)}</color></i>";
|
||||
case ValueState.Boolean:
|
||||
case ValueState.Number:
|
||||
return null;
|
||||
case ValueState.String:
|
||||
string s = Value as string;
|
||||
if (s.Length > 200)
|
||||
s = $"{s.Substring(0, 200)}...";
|
||||
return $"\"{s}\"";
|
||||
case ValueState.NullValue:
|
||||
return $"<i>{ToStringUtility.ToStringWithType(Value, FallbackType, true)}</i>";
|
||||
case ValueState.Enum:
|
||||
case ValueState.Collection:
|
||||
case ValueState.ValueStruct:
|
||||
case ValueState.Unsupported:
|
||||
default:
|
||||
return ToStringUtility.ToStringWithType(Value, FallbackType, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the cell view for an enabled cell based on this CacheMember model.
|
||||
/// </summary>
|
||||
public void SetCell(CacheMemberCell cell)
|
||||
{
|
||||
cell.MemberLabel.text = MemberLabelText;
|
||||
cell.ValueLabel.gameObject.SetActive(true);
|
||||
|
||||
cell.EvaluateHolder.SetActive(!ShouldAutoEvaluate);
|
||||
if (!ShouldAutoEvaluate)
|
||||
{
|
||||
cell.EvaluateButton.Button.gameObject.SetActive(true);
|
||||
if (HasArguments)
|
||||
cell.EvaluateButton.ButtonText.text = $"Evaluate ({Arguments.Length})";
|
||||
else
|
||||
cell.EvaluateButton.ButtonText.text = "Evaluate";
|
||||
}
|
||||
|
||||
if (State == ValueState.NotEvaluated && !ShouldAutoEvaluate)
|
||||
{
|
||||
// todo evaluate buttons etc
|
||||
SetCellState(cell, true, true, Color.white, false, false, false, false, false, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (State == ValueState.NotEvaluated)
|
||||
Evaluate();
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case ValueState.Exception:
|
||||
case ValueState.NullValue:
|
||||
SetCellState(cell, true, true, Color.white, false, false, false, false, false, false);
|
||||
break;
|
||||
case ValueState.Boolean:
|
||||
SetCellState(cell, false, false, default, true, toggleActive: true, false, CanWrite, false, false);
|
||||
break;
|
||||
case ValueState.Number:
|
||||
SetCellState(cell, false, true, Color.white, true, false, inputActive: true, CanWrite, false, false);
|
||||
break;
|
||||
case ValueState.String:
|
||||
SetCellState(cell, true, false, SignatureHighlighter.StringOrange, false, false, false, false, false, true);
|
||||
break;
|
||||
case ValueState.Enum:
|
||||
SetCellState(cell, true, true, Color.white, false, false, false, false, false, true);
|
||||
break;
|
||||
case ValueState.Collection:
|
||||
case ValueState.ValueStruct:
|
||||
SetCellState(cell, true, true, Color.white, false, false, false, false, true, true);
|
||||
break;
|
||||
case ValueState.Unsupported:
|
||||
SetCellState(cell, true, true, Color.white, false, false, false, false, true, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCellState(CacheMemberCell cell, bool valueActive, bool valueRichText, Color valueColor,
|
||||
bool typeLabelActive, bool toggleActive, bool inputActive, bool applyActive, bool inspectActive, bool subContentActive)
|
||||
{
|
||||
//cell.ValueLabel.gameObject.SetActive(valueActive);
|
||||
if (valueActive)
|
||||
{
|
||||
cell.ValueLabel.text = ValueLabelText;
|
||||
cell.ValueLabel.supportRichText = valueRichText;
|
||||
cell.ValueLabel.color = valueColor;
|
||||
}
|
||||
else
|
||||
cell.ValueLabel.text = "";
|
||||
|
||||
cell.TypeLabel.gameObject.SetActive(typeLabelActive);
|
||||
if (typeLabelActive)
|
||||
cell.TypeLabel.text = TypeLabelText;
|
||||
|
||||
cell.Toggle.gameObject.SetActive(toggleActive);
|
||||
if (toggleActive)
|
||||
{
|
||||
cell.Toggle.isOn = (bool)Value;
|
||||
cell.ToggleText.text = Value.ToString();
|
||||
}
|
||||
|
||||
cell.InputField.gameObject.SetActive(inputActive);
|
||||
if (inputActive)
|
||||
cell.InputField.text = Value.ToString();
|
||||
|
||||
cell.ApplyButton.Button.gameObject.SetActive(applyActive);
|
||||
cell.InspectButton.Button.gameObject.SetActive(inspectActive);
|
||||
cell.SubContentButton.Button.gameObject.SetActive(subContentActive);
|
||||
|
||||
cell.UpdateButton.Button.gameObject.SetActive(ShouldAutoEvaluate);
|
||||
}
|
||||
|
||||
|
||||
@ -144,9 +274,10 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
target = target.TryCast(declaringType);
|
||||
|
||||
infos.Clear();
|
||||
infos.AddRange(declaringType.GetMethods(flags));
|
||||
infos.AddRange(declaringType.GetProperties(flags));
|
||||
infos.AddRange(declaringType.GetFields(flags));
|
||||
infos.AddRange(declaringType.GetEvents(flags));
|
||||
infos.AddRange(declaringType.GetMethods(flags));
|
||||
|
||||
foreach (var member in infos)
|
||||
{
|
||||
|
@ -10,11 +10,13 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
{
|
||||
public MethodInfo MethodInfo { get; internal set; }
|
||||
|
||||
public override bool ShouldAutoEvaluate => false;
|
||||
|
||||
public override void Initialize(ReflectionInspector inspector, Type declaringType, MemberInfo member, Type returnType)
|
||||
{
|
||||
base.Initialize(inspector, declaringType, member, returnType);
|
||||
|
||||
|
||||
Arguments = MethodInfo.GetParameters();
|
||||
}
|
||||
|
||||
protected override void TryEvaluate()
|
||||
|
@ -10,11 +10,14 @@ namespace UnityExplorer.UI.Inspectors.CacheObject
|
||||
{
|
||||
public PropertyInfo PropertyInfo { get; internal set; }
|
||||
|
||||
public override bool ShouldAutoEvaluate => !HasArguments;
|
||||
|
||||
public override void Initialize(ReflectionInspector inspector, Type declaringType, MemberInfo member, Type returnType)
|
||||
{
|
||||
base.Initialize(inspector, declaringType, member, returnType);
|
||||
|
||||
|
||||
this.CanWrite = PropertyInfo.CanWrite;
|
||||
Arguments = PropertyInfo.GetIndexParameters();
|
||||
}
|
||||
|
||||
protected override void TryEvaluate()
|
||||
|
@ -4,10 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Widgets;
|
||||
|
||||
namespace UnityExplorer.UI.Inspectors.CacheObject.Views
|
||||
{
|
||||
// Todo add C# events for the unity UI listeners
|
||||
|
||||
public class CacheMemberCell : ICell
|
||||
{
|
||||
#region ICell
|
||||
@ -38,26 +41,83 @@ namespace UnityExplorer.UI.Inspectors.CacheObject.Views
|
||||
#endregion
|
||||
|
||||
public ReflectionInspector CurrentOwner { get; set; }
|
||||
public int CurrentDataIndex { get; set; }
|
||||
public CacheMember CurrentOccupant { get; set; }
|
||||
|
||||
public Action<CacheMember> OnApplyClicked;
|
||||
public Action<CacheMember> OnInspectClicked;
|
||||
public Action<CacheMember> OnSubContentClicked;
|
||||
public Action<CacheMember> OnUpdateClicked;
|
||||
public Action<CacheMember> OnEvaluateClicked;
|
||||
|
||||
public LayoutElement MemberLayout;
|
||||
public LayoutElement ReturnTypeLayout;
|
||||
public LayoutElement RightGroupLayout;
|
||||
|
||||
public Text MemberLabel;
|
||||
public Text TypeLabel;
|
||||
|
||||
public GameObject RightGroupHolder;
|
||||
public ButtonRef InspectButton;
|
||||
//public GameObject RightGroupHolder;
|
||||
public Text TypeLabel;
|
||||
public Text ValueLabel;
|
||||
public Toggle Toggle;
|
||||
public Text ToggleText;
|
||||
public InputField InputField;
|
||||
|
||||
public GameObject EvaluateHolder;
|
||||
public ButtonRef EvaluateButton;
|
||||
|
||||
public ButtonRef InspectButton;
|
||||
public ButtonRef SubContentButton;
|
||||
public ButtonRef ApplyButton;
|
||||
public ButtonRef UpdateButton;
|
||||
|
||||
public GameObject SubContentHolder;
|
||||
|
||||
public void OnReturnToPool()
|
||||
{
|
||||
// remove listeners
|
||||
OnApplyClicked = null;
|
||||
OnInspectClicked = null;
|
||||
OnSubContentClicked = null;
|
||||
OnUpdateClicked = null;
|
||||
OnEvaluateClicked = null;
|
||||
|
||||
CurrentOwner = null;
|
||||
}
|
||||
|
||||
private void ApplyClicked()
|
||||
{
|
||||
OnApplyClicked?.Invoke(CurrentOccupant);
|
||||
}
|
||||
|
||||
private void InspectClicked()
|
||||
{
|
||||
OnInspectClicked?.Invoke(CurrentOccupant);
|
||||
}
|
||||
|
||||
private void SubContentClicked()
|
||||
{
|
||||
OnSubContentClicked?.Invoke(CurrentOccupant);
|
||||
}
|
||||
|
||||
private void UpdateClicked()
|
||||
{
|
||||
OnUpdateClicked?.Invoke(CurrentOccupant);
|
||||
}
|
||||
|
||||
private void EvaluateClicked()
|
||||
{
|
||||
OnEvaluateClicked?.Invoke(CurrentOccupant);
|
||||
}
|
||||
|
||||
private void ToggleClicked(bool value)
|
||||
{
|
||||
ToggleText.text = value.ToString();
|
||||
}
|
||||
|
||||
public GameObject CreateContent(GameObject parent)
|
||||
{
|
||||
uiRoot = UIFactory.CreateUIObject("CacheMemberCell", parent, new Vector2(100, 30));
|
||||
m_rect = uiRoot.GetComponent<RectTransform>();
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(uiRoot, true, true, true, true, 2, 0);
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(uiRoot, true, false, true, true, 2, 0);
|
||||
UIFactory.SetLayoutElement(uiRoot, minWidth: 100, flexibleWidth: 9999, minHeight: 30, flexibleHeight: 600);
|
||||
UIRoot.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
|
||||
@ -67,31 +127,64 @@ namespace UnityExplorer.UI.Inspectors.CacheObject.Views
|
||||
|
||||
var horiRow = UIFactory.CreateUIObject("HoriGroup", uiRoot);
|
||||
UIFactory.SetLayoutElement(horiRow, minHeight: 29, flexibleHeight: 150, flexibleWidth: 9999);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(horiRow, false, true, true, true, 5, 2, childAlignment: TextAnchor.UpperLeft);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(horiRow, false, false, true, true, 5, 2, childAlignment: TextAnchor.UpperLeft);
|
||||
horiRow.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
|
||||
MemberLabel = UIFactory.CreateLabel(horiRow, "MemberLabel", "<notset>", TextAnchor.UpperLeft);
|
||||
MemberLabel = UIFactory.CreateLabel(horiRow, "MemberLabel", "<notset>", TextAnchor.MiddleLeft);
|
||||
MemberLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
UIFactory.SetLayoutElement(MemberLabel.gameObject, minHeight: 25, minWidth: 20, flexibleHeight: 300, flexibleWidth: 0);
|
||||
MemberLayout = MemberLabel.GetComponent<LayoutElement>();
|
||||
|
||||
TypeLabel = UIFactory.CreateLabel(horiRow, "ReturnLabel", "<notset>", TextAnchor.UpperLeft);
|
||||
var rightGroupHolder = UIFactory.CreateUIObject("RightGroup", horiRow);
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(rightGroupHolder, false, false, true, true, 4, childAlignment: TextAnchor.UpperLeft);
|
||||
UIFactory.SetLayoutElement(rightGroupHolder, minHeight: 25, minWidth: 200, flexibleWidth: 9999, flexibleHeight: 800);
|
||||
RightGroupLayout = rightGroupHolder.GetComponent<LayoutElement>();
|
||||
|
||||
EvaluateHolder = UIFactory.CreateUIObject("EvalGroup", rightGroupHolder);
|
||||
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(EvaluateHolder, false, false, true, true, 3);
|
||||
UIFactory.SetLayoutElement(EvaluateHolder, minHeight: 25, flexibleWidth: 9999, flexibleHeight: 775);
|
||||
|
||||
EvaluateButton = UIFactory.CreateButton(EvaluateHolder, "EvaluateButton", "Evaluate", new Color(0.15f, 0.15f, 0.15f));
|
||||
UIFactory.SetLayoutElement(EvaluateButton.Button.gameObject, minWidth: 100, minHeight: 25);
|
||||
EvaluateButton.OnClick += EvaluateClicked;
|
||||
|
||||
var rightHoriGroup = UIFactory.CreateUIObject("RightHoriGroup", rightGroupHolder);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(rightHoriGroup, false, false, true, true, 4, childAlignment: TextAnchor.UpperLeft);
|
||||
UIFactory.SetLayoutElement(rightHoriGroup, minHeight: 25, minWidth: 200, flexibleWidth: 9999, flexibleHeight: 800);
|
||||
|
||||
SubContentButton = UIFactory.CreateButton(rightHoriGroup, "SubContentButton", "▲");
|
||||
UIFactory.SetLayoutElement(SubContentButton.Button.gameObject, minWidth: 25, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);
|
||||
SubContentButton.OnClick += SubContentClicked;
|
||||
|
||||
TypeLabel = UIFactory.CreateLabel(rightHoriGroup, "ReturnLabel", "<notset>", TextAnchor.MiddleLeft);
|
||||
TypeLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
UIFactory.SetLayoutElement(TypeLabel.gameObject, minHeight: 25, flexibleHeight: 150, minWidth: 20, flexibleWidth: 0);
|
||||
ReturnTypeLayout = TypeLabel.GetComponent<LayoutElement>();
|
||||
UIFactory.SetLayoutElement(TypeLabel.gameObject, minHeight: 25, flexibleHeight: 150, minWidth: 70, flexibleWidth: 0);
|
||||
//ReturnTypeLayout = TypeLabel.GetComponent<LayoutElement>();
|
||||
|
||||
RightGroupHolder = UIFactory.CreateUIObject("RightGroup", horiRow);
|
||||
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(RightGroupHolder, false, false, true, true, 4, childAlignment: TextAnchor.UpperLeft);
|
||||
UIFactory.SetLayoutElement(RightGroupHolder, minHeight: 25, minWidth: 200, flexibleWidth: 9999, flexibleHeight: 150);
|
||||
RightGroupLayout = RightGroupHolder.GetComponent<LayoutElement>();
|
||||
var toggleObj = UIFactory.CreateToggle(rightHoriGroup, "Toggle", out Toggle, out ToggleText);
|
||||
UIFactory.SetLayoutElement(toggleObj, minWidth: 70, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);
|
||||
ToggleText.color = SignatureHighlighter.KeywordBlue;
|
||||
Toggle.onValueChanged.AddListener(ToggleClicked);
|
||||
|
||||
InspectButton = UIFactory.CreateButton(RightGroupHolder, "InspectButton", "Inspect", new Color(0.23f, 0.23f, 0.23f));
|
||||
var inputObj = UIFactory.CreateInputField(rightHoriGroup, "InputField", "...", out InputField);
|
||||
UIFactory.SetLayoutElement(inputObj, minWidth: 150, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0);
|
||||
|
||||
InspectButton = UIFactory.CreateButton(rightHoriGroup, "InspectButton", "Inspect", new Color(0.15f, 0.15f, 0.15f));
|
||||
UIFactory.SetLayoutElement(InspectButton.Button.gameObject, minWidth: 60, flexibleWidth: 0, minHeight: 25);
|
||||
InspectButton.OnClick += InspectClicked;
|
||||
|
||||
ValueLabel = UIFactory.CreateLabel(RightGroupHolder, "ValueLabel", "Value goes here", TextAnchor.MiddleLeft);
|
||||
ApplyButton = UIFactory.CreateButton(rightHoriGroup, "ApplyButton", "Apply", new Color(0.15f, 0.15f, 0.15f));
|
||||
UIFactory.SetLayoutElement(ApplyButton.Button.gameObject, minWidth: 70, minHeight: 25, flexibleWidth: 0, flexibleHeight: 0);
|
||||
ApplyButton.OnClick += ApplyClicked;
|
||||
|
||||
ValueLabel = UIFactory.CreateLabel(rightHoriGroup, "ValueLabel", "Value goes here", TextAnchor.MiddleLeft);
|
||||
ValueLabel.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
UIFactory.SetLayoutElement(ValueLabel.gameObject, minHeight: 25, flexibleHeight: 150, flexibleWidth: 9999);
|
||||
|
||||
UpdateButton = UIFactory.CreateButton(rightHoriGroup, "UpdateButton", "Update", new Color(0.15f, 0.2f, 0.15f));
|
||||
UIFactory.SetLayoutElement(UpdateButton.Button.gameObject, minWidth: 65, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0);
|
||||
UpdateButton.OnClick += UpdateClicked;
|
||||
|
||||
// Subcontent (todo?)
|
||||
|
||||
SubContentHolder = UIFactory.CreateUIObject("SubContent", uiRoot);
|
||||
|
@ -29,7 +29,7 @@ namespace UnityExplorer.UI.Inspectors
|
||||
CreateInspector<ReflectionInspector>(obj);
|
||||
}
|
||||
|
||||
public static void InspectStatic(Type type)
|
||||
public static void Inspect(Type type)
|
||||
{
|
||||
CreateInspector<ReflectionInspector>(type, true);
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ namespace UnityExplorer.UI.Inspectors
|
||||
|
||||
private List<CacheMember> members = new List<CacheMember>();
|
||||
private readonly List<CacheMember> filteredMembers = new List<CacheMember>();
|
||||
private readonly List<int> filteredIndices = new List<int>();
|
||||
|
||||
public override GameObject UIRoot => uiRoot;
|
||||
private GameObject uiRoot;
|
||||
@ -37,7 +36,6 @@ namespace UnityExplorer.UI.Inspectors
|
||||
public Text AssemblyText;
|
||||
|
||||
private LayoutElement memberTitleLayout;
|
||||
private LayoutElement typeTitleLayout;
|
||||
|
||||
public override void OnBorrowedFromPool(object target)
|
||||
{
|
||||
@ -97,21 +95,22 @@ namespace UnityExplorer.UI.Inspectors
|
||||
{
|
||||
var member = members[i];
|
||||
filteredMembers.Add(member);
|
||||
filteredIndices.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnReturnToPool()
|
||||
{
|
||||
base.OnReturnToPool();
|
||||
foreach (var member in members)
|
||||
member.OnDestroyed();
|
||||
|
||||
members.Clear();
|
||||
filteredMembers.Clear();
|
||||
filteredIndices.Clear();
|
||||
|
||||
// release all cachememberviews
|
||||
MemberScrollPool.ReturnCells();
|
||||
MemberScrollPool.SetUninitialized();
|
||||
|
||||
base.OnReturnToPool();
|
||||
}
|
||||
|
||||
public override void OnSetActive()
|
||||
@ -141,6 +140,7 @@ namespace UnityExplorer.UI.Inspectors
|
||||
{
|
||||
timeOfLastUpdate = Time.time;
|
||||
|
||||
// Update displayed values (TODO)
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,33 +154,54 @@ namespace UnityExplorer.UI.Inspectors
|
||||
|
||||
public int ItemCount => filteredMembers.Count;
|
||||
|
||||
public int GetRealIndexOfTempIndex(int tempIndex)
|
||||
{
|
||||
if (filteredIndices.Count <= tempIndex)
|
||||
return -1;
|
||||
|
||||
return filteredIndices[tempIndex];
|
||||
}
|
||||
|
||||
public void OnCellBorrowed(CacheMemberCell cell)
|
||||
{
|
||||
cell.CurrentOwner = this;
|
||||
|
||||
// todo add listeners
|
||||
cell.OnInspectClicked += OnCellInspect;
|
||||
cell.OnApplyClicked += OnCellApply;
|
||||
cell.OnSubContentClicked += OnCellSubContentToggle;
|
||||
cell.OnUpdateClicked += OnCellUpdateClicked;
|
||||
cell.OnEvaluateClicked += OnCellEvaluateClicked;
|
||||
}
|
||||
|
||||
private void OnCellInspect(CacheMember occupant)
|
||||
{
|
||||
InspectorManager.Inspect(occupant.Value);
|
||||
}
|
||||
|
||||
private void OnCellApply(CacheMember occupant)
|
||||
{
|
||||
ExplorerCore.Log($"TODO OnApply: {occupant.NameForFiltering}");
|
||||
}
|
||||
|
||||
private void OnCellSubContentToggle(CacheMember occupant)
|
||||
{
|
||||
ExplorerCore.Log($"TODO SubContentToggle: {occupant.NameForFiltering}");
|
||||
}
|
||||
|
||||
private void OnCellUpdateClicked(CacheMember occupant)
|
||||
{
|
||||
ExplorerCore.Log("TODO Update: " + occupant.NameForFiltering);
|
||||
}
|
||||
|
||||
private void OnCellEvaluateClicked(CacheMember occupant)
|
||||
{
|
||||
ExplorerCore.Log("TODO Evaluate or toggle: " + occupant);
|
||||
}
|
||||
|
||||
public void OnCellReturned(CacheMemberCell cell)
|
||||
{
|
||||
// todo remove listeners
|
||||
|
||||
// return ivalue
|
||||
|
||||
cell.CurrentOwner = null;
|
||||
cell.OnReturnToPool();
|
||||
}
|
||||
|
||||
public void SetCell(CacheMemberCell cell, int index)
|
||||
{
|
||||
index = GetRealIndexOfTempIndex(index);
|
||||
if (cell.CurrentOccupant != null)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (index < 0 || index >= filteredMembers.Count)
|
||||
{
|
||||
@ -188,7 +209,9 @@ namespace UnityExplorer.UI.Inspectors
|
||||
return;
|
||||
}
|
||||
|
||||
members[index].SetCell(cell);
|
||||
var member = filteredMembers[index];
|
||||
cell.CurrentOccupant = member;
|
||||
member.SetCell(cell);
|
||||
|
||||
SetCellLayout(cell);
|
||||
}
|
||||
@ -198,20 +221,25 @@ namespace UnityExplorer.UI.Inspectors
|
||||
// need to do anything?
|
||||
}
|
||||
|
||||
private static float MemLabelWidth => Math.Min(400f, 0.35f * InspectorManager.PanelWidth - 5);
|
||||
private static float ReturnLabelWidth => Math.Min(225f, 0.25f * InspectorManager.PanelWidth - 5);
|
||||
private static float RightGroupWidth => InspectorManager.PanelWidth - MemLabelWidth - ReturnLabelWidth - 50;
|
||||
#endregion
|
||||
|
||||
// Cell layout (fake table alignment)
|
||||
|
||||
private static float MemLabelWidth { get; set; }
|
||||
private static float RightGroupWidth { get; set; }
|
||||
|
||||
private void SetTitleLayouts()
|
||||
{
|
||||
// Calculate sizes
|
||||
MemLabelWidth = Math.Max(200, Math.Min(450f, 0.4f * InspectorManager.PanelWidth - 5));
|
||||
RightGroupWidth = Math.Max(200, InspectorManager.PanelWidth - MemLabelWidth - 55);
|
||||
|
||||
memberTitleLayout.minWidth = MemLabelWidth;
|
||||
typeTitleLayout.minWidth = ReturnLabelWidth;
|
||||
}
|
||||
|
||||
private void SetCellLayout(CacheMemberCell cell)
|
||||
{
|
||||
cell.MemberLayout.minWidth = MemLabelWidth;
|
||||
cell.ReturnTypeLayout.minWidth = ReturnLabelWidth;
|
||||
cell.RightGroupLayout.minWidth = RightGroupWidth;
|
||||
}
|
||||
|
||||
@ -223,8 +251,6 @@ namespace UnityExplorer.UI.Inspectors
|
||||
SetCellLayout(cell);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override GameObject CreateContent(GameObject parent)
|
||||
{
|
||||
uiRoot = UIFactory.CreateVerticalGroup(parent, "ReflectionInspector", true, true, true, true, 5,
|
||||
@ -243,16 +269,16 @@ namespace UnityExplorer.UI.Inspectors
|
||||
var memberTitle = UIFactory.CreateLabel(listTitles, "MemberTitle", "Member Name", TextAnchor.LowerLeft, Color.grey, fontSize: 15);
|
||||
memberTitleLayout = memberTitle.gameObject.AddComponent<LayoutElement>();
|
||||
|
||||
var typeTitle = UIFactory.CreateLabel(listTitles, "TypeTitle", "Type", TextAnchor.LowerLeft, Color.grey, fontSize: 15);
|
||||
typeTitleLayout = typeTitle.gameObject.AddComponent<LayoutElement>();
|
||||
//var typeTitle = UIFactory.CreateLabel(listTitles, "TypeTitle", "Type", TextAnchor.LowerLeft, Color.grey, fontSize: 15);
|
||||
//typeTitleLayout = typeTitle.gameObject.AddComponent<LayoutElement>();
|
||||
|
||||
var valueTitle = UIFactory.CreateLabel(listTitles, "ValueTitle", "Value", TextAnchor.LowerLeft, Color.grey, fontSize: 15);
|
||||
UIFactory.SetLayoutElement(valueTitle.gameObject, flexibleWidth: 9999);
|
||||
UIFactory.SetLayoutElement(valueTitle.gameObject, minWidth: 150, flexibleWidth: 9999);
|
||||
|
||||
MemberScrollPool = UIFactory.CreateScrollPool<CacheMemberCell>(uiRoot, "MemberList", out GameObject scrollObj,
|
||||
out GameObject scrollContent, new Color(0.09f, 0.09f, 0.09f));
|
||||
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
|
||||
UIFactory.SetLayoutElement(scrollContent, flexibleHeight: 9999);
|
||||
//UIFactory.SetLayoutElement(scrollContent, flexibleHeight: 9999);
|
||||
|
||||
MemberScrollPool.Initialize(this);
|
||||
|
||||
|
Reference in New Issue
Block a user