2021-04-27 21:22:48 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
2021-04-28 20:47:48 +10:00
|
|
|
|
using UnityEngine;
|
2022-01-17 19:42:05 +11:00
|
|
|
|
using UnityExplorer.Runtime;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.CacheObject.Views;
|
|
|
|
|
using UnityExplorer.Inspectors;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib.UI.Models;
|
2021-06-30 07:49:58 +10:00
|
|
|
|
using UnityExplorer.UI;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib;
|
|
|
|
|
using UniverseLib.UI;
|
2022-01-02 19:43:55 +11:00
|
|
|
|
using UnityExplorer.UI.Widgets;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.Utility;
|
|
|
|
|
using UniverseLib.UI.ObjectPool;
|
2022-03-14 05:20:43 +11:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using HarmonyLib;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-06-30 07:49:58 +10:00
|
|
|
|
namespace UnityExplorer.CacheObject
|
2021-04-27 21:22:48 +10:00
|
|
|
|
{
|
|
|
|
|
public abstract class CacheMember : CacheObjectBase
|
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public abstract Type DeclaringType { get; }
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public string NameForFiltering { get; protected set; }
|
2022-02-19 17:50:10 +11:00
|
|
|
|
public object DeclaringInstance => IsStatic ? null : (m_declaringInstance ??= Owner.Target.TryCast(DeclaringType));
|
2021-05-06 04:02:42 +10:00
|
|
|
|
private object m_declaringInstance;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public abstract bool IsStatic { get; }
|
2021-05-04 20:10:46 +10:00
|
|
|
|
public override bool HasArguments => Arguments?.Length > 0 || GenericArguments.Length > 0;
|
|
|
|
|
public ParameterInfo[] Arguments { get; protected set; } = new ParameterInfo[0];
|
2021-05-08 20:54:16 +10:00
|
|
|
|
public Type[] GenericArguments { get; protected set; } = ArgumentUtility.EmptyTypes;
|
2021-05-04 20:10:46 +10:00
|
|
|
|
public EvaluateWidget Evaluator { get; protected set; }
|
|
|
|
|
public bool Evaluating => Evaluator != null && Evaluator.UIRoot.activeSelf;
|
2021-06-05 19:36:09 +10:00
|
|
|
|
|
2021-04-30 21:34:50 +10:00
|
|
|
|
public virtual void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
|
2021-04-28 20:47:48 +10:00
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
this.Owner = inspector;
|
2022-03-14 05:20:43 +11:00
|
|
|
|
this.NameLabelText = this switch
|
|
|
|
|
{
|
|
|
|
|
CacheMethod => SignatureHighlighter.HighlightMethod(member as MethodInfo),
|
|
|
|
|
CacheConstructor => SignatureHighlighter.HighlightConstructor(member as ConstructorInfo),
|
|
|
|
|
_ => SignatureHighlighter.Parse(member.DeclaringType, false, member),
|
|
|
|
|
};
|
2022-03-10 04:31:19 +11:00
|
|
|
|
|
|
|
|
|
this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
|
2021-08-23 18:35:08 +10:00
|
|
|
|
this.NameLabelTextRaw = NameForFiltering;
|
2021-04-28 20:47:48 +10:00
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2021-05-04 20:10:46 +10:00
|
|
|
|
public override void ReleasePooledObjects()
|
|
|
|
|
{
|
|
|
|
|
base.ReleasePooledObjects();
|
|
|
|
|
|
|
|
|
|
if (this.Evaluator != null)
|
|
|
|
|
{
|
|
|
|
|
this.Evaluator.OnReturnToPool();
|
|
|
|
|
Pool<EvaluateWidget>.Return(this.Evaluator);
|
|
|
|
|
this.Evaluator = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 21:27:09 +10:00
|
|
|
|
public override void UnlinkFromView()
|
2021-05-04 20:10:46 +10:00
|
|
|
|
{
|
|
|
|
|
if (this.Evaluator != null)
|
|
|
|
|
this.Evaluator.UIRoot.transform.SetParent(Pool<EvaluateWidget>.Instance.InactiveHolder.transform, false);
|
2021-05-05 21:27:09 +10:00
|
|
|
|
|
|
|
|
|
base.UnlinkFromView();
|
2021-05-04 20:10:46 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract object TryEvaluate();
|
2021-04-28 20:47:48 +10:00
|
|
|
|
|
2021-04-29 21:01:08 +10:00
|
|
|
|
protected abstract void TrySetValue(object value);
|
|
|
|
|
|
2021-09-06 15:51:40 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Evaluate is called when first shown (if ShouldAutoEvaluate), or else when Evaluate button is clicked, or auto-updated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Evaluate()
|
2021-05-04 20:10:46 +10:00
|
|
|
|
{
|
2021-09-06 15:51:40 +10:00
|
|
|
|
SetValueFromSource(TryEvaluate());
|
2021-05-04 20:10:46 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
/// <summary>
|
2021-09-06 15:51:40 +10:00
|
|
|
|
/// Called when user presses the Evaluate button.
|
2021-04-28 20:47:48 +10:00
|
|
|
|
/// </summary>
|
2021-09-06 15:51:40 +10:00
|
|
|
|
public void EvaluateAndSetCell()
|
2021-04-28 20:47:48 +10:00
|
|
|
|
{
|
2021-09-06 15:51:40 +10:00
|
|
|
|
Evaluate();
|
|
|
|
|
if (CellView != null)
|
|
|
|
|
SetDataToCell(CellView);
|
2021-04-28 20:47:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 06:36:39 +10:00
|
|
|
|
public override void TrySetUserValue(object value)
|
2021-04-28 20:47:48 +10:00
|
|
|
|
{
|
2021-04-30 21:34:50 +10:00
|
|
|
|
TrySetValue(value);
|
|
|
|
|
Evaluate();
|
2021-04-28 20:47:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
protected override void SetValueState(CacheObjectCell cell, ValueStateArgs args)
|
2021-04-28 20:47:48 +10:00
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
base.SetValueState(cell, args);
|
2021-04-28 20:47:48 +10:00
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2022-02-19 17:50:10 +11:00
|
|
|
|
private static readonly Color evalEnabledColor = new(0.15f, 0.25f, 0.15f);
|
|
|
|
|
private static readonly Color evalDisabledColor = new(0.15f, 0.15f, 0.15f);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
protected override bool TryAutoEvaluateIfUnitialized(CacheObjectCell objectcell)
|
2021-04-28 20:47:48 +10:00
|
|
|
|
{
|
2021-04-30 21:34:50 +10:00
|
|
|
|
var cell = objectcell as CacheMemberCell;
|
2021-04-28 20:47:48 +10:00
|
|
|
|
|
|
|
|
|
cell.EvaluateHolder.SetActive(!ShouldAutoEvaluate);
|
|
|
|
|
if (!ShouldAutoEvaluate)
|
|
|
|
|
{
|
2021-05-11 19:18:27 +10:00
|
|
|
|
cell.EvaluateButton.Component.gameObject.SetActive(true);
|
2021-04-28 20:47:48 +10:00
|
|
|
|
if (HasArguments)
|
2021-05-04 20:10:46 +10:00
|
|
|
|
{
|
|
|
|
|
if (!Evaluating)
|
|
|
|
|
cell.EvaluateButton.ButtonText.text = $"Evaluate ({Arguments.Length + GenericArguments.Length})";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cell.EvaluateButton.ButtonText.text = "Hide";
|
|
|
|
|
Evaluator.UIRoot.transform.SetParent(cell.EvaluateHolder.transform, false);
|
2022-01-31 21:24:01 +11:00
|
|
|
|
RuntimeHelper.SetColorBlock(cell.EvaluateButton.Component, evalEnabledColor, evalEnabledColor * 1.3f);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
else
|
2021-04-28 20:47:48 +10:00
|
|
|
|
cell.EvaluateButton.ButtonText.text = "Evaluate";
|
2021-05-04 20:10:46 +10:00
|
|
|
|
|
|
|
|
|
if (!Evaluating)
|
2022-01-31 21:24:01 +11:00
|
|
|
|
RuntimeHelper.SetColorBlock(cell.EvaluateButton.Component, evalDisabledColor, evalDisabledColor * 1.3f);
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 20:47:48 +10:00
|
|
|
|
if (State == ValueState.NotEvaluated && !ShouldAutoEvaluate)
|
|
|
|
|
{
|
2021-05-01 20:55:27 +10:00
|
|
|
|
SetValueState(cell, ValueStateArgs.Default);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
cell.RefreshSubcontentButton();
|
2021-04-27 21:22:48 +10:00
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
return false;
|
2021-04-28 20:47:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (State == ValueState.NotEvaluated)
|
|
|
|
|
Evaluate();
|
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
return true;
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 20:10:46 +10:00
|
|
|
|
public void OnEvaluateClicked()
|
|
|
|
|
{
|
|
|
|
|
if (!HasArguments)
|
|
|
|
|
{
|
|
|
|
|
EvaluateAndSetCell();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Evaluator == null)
|
|
|
|
|
{
|
|
|
|
|
this.Evaluator = Pool<EvaluateWidget>.Borrow();
|
|
|
|
|
Evaluator.OnBorrowedFromPool(this);
|
|
|
|
|
Evaluator.UIRoot.transform.SetParent((CellView as CacheMemberCell).EvaluateHolder.transform, false);
|
2022-01-18 20:19:20 +11:00
|
|
|
|
TryAutoEvaluateIfUnitialized(CellView);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Evaluator.UIRoot.activeSelf)
|
|
|
|
|
Evaluator.UIRoot.SetActive(false);
|
|
|
|
|
else
|
|
|
|
|
Evaluator.UIRoot.SetActive(true);
|
|
|
|
|
|
2022-01-18 20:19:20 +11:00
|
|
|
|
TryAutoEvaluateIfUnitialized(CellView);
|
2021-05-04 20:10:46 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 21:22:48 +10:00
|
|
|
|
}
|
|
|
|
|
}
|