This commit is contained in:
Sinai 2022-04-30 20:31:33 +10:00
parent b97eada516
commit b35d6f5787
2 changed files with 38 additions and 40 deletions

View File

@ -462,9 +462,6 @@ namespace UnityExplorer.CSConsole
#region Lexer Highlighting #region Lexer Highlighting
/// <summary>
/// Returns true if caret is inside string or comment, false otherwise
/// </summary>
private static void HighlightVisibleInput(out bool inStringOrComment) private static void HighlightVisibleInput(out bool inStringOrComment)
{ {
inStringOrComment = false; inStringOrComment = false;

View File

@ -28,28 +28,31 @@ namespace UnityExplorer.CacheObject
public abstract class CacheObjectBase public abstract class CacheObjectBase
{ {
public ICacheObjectController Owner { get; set; } public ICacheObjectController Owner { get; set; }
public CacheObjectCell CellView { get; internal set; } public CacheObjectCell CellView { get; internal set; }
public object Value { get; protected set; } public object Value { get; protected set; }
public Type FallbackType { get; protected set; } public Type FallbackType { get; protected set; }
public bool LastValueWasNull { get; private set; } public ValueState State { get; set; }
public Exception LastException { get; protected set; }
public ValueState State = ValueState.NotEvaluated; bool valueIsNull;
public Type LastValueType; Type currentValueType;
// InteractiveValues
public InteractiveValue IValue { get; private set; } public InteractiveValue IValue { get; private set; }
public Type CurrentIValueType { get; private set; } public Type CurrentIValueType { get; private set; }
public bool SubContentShowWanted { get; private set; } public bool SubContentShowWanted { get; private set; }
// UI
public string NameLabelText { get; protected set; } public string NameLabelText { get; protected set; }
public string NameLabelTextRaw { get; protected set; } public string NameLabelTextRaw { get; protected set; }
public string ValueLabelText { get; protected set; } public string ValueLabelText { get; protected set; }
// Abstract
public abstract bool ShouldAutoEvaluate { get; } public abstract bool ShouldAutoEvaluate { get; }
public abstract bool HasArguments { get; } public abstract bool HasArguments { get; }
public abstract bool CanWrite { get; } public abstract bool CanWrite { get; }
public Exception LastException { get; protected set; }
protected const string NOT_YET_EVAL = "<color=grey>Not yet evaluated</color>";
public virtual void SetFallbackType(Type fallbackType) public virtual void SetFallbackType(Type fallbackType)
{ {
@ -57,17 +60,6 @@ namespace UnityExplorer.CacheObject
this.ValueLabelText = GetValueLabel(); this.ValueLabelText = GetValueLabel();
} }
protected const string NOT_YET_EVAL = "<color=grey>Not yet evaluated</color>";
public virtual void ReleasePooledObjects()
{
if (this.IValue != null)
ReleaseIValue();
if (this.CellView != null)
UnlinkFromView();
}
public virtual void SetView(CacheObjectCell cellView) public virtual void SetView(CacheObjectCell cellView)
{ {
this.CellView = cellView; this.CellView = cellView;
@ -86,6 +78,15 @@ namespace UnityExplorer.CacheObject
this.IValue.UIRoot.transform.SetParent(InactiveIValueHolder.transform, false); this.IValue.UIRoot.transform.SetParent(InactiveIValueHolder.transform, false);
} }
public virtual void ReleasePooledObjects()
{
if (this.IValue != null)
ReleaseIValue();
if (this.CellView != null)
UnlinkFromView();
}
// Updating and applying values // Updating and applying values
// The only method which sets the CacheObjectBase.Value // The only method which sets the CacheObjectBase.Value
@ -130,18 +131,18 @@ namespace UnityExplorer.CacheObject
if (LastException != null) if (LastException != null)
{ {
LastValueWasNull = true; valueIsNull = true;
LastValueType = FallbackType; currentValueType = FallbackType;
State = ValueState.Exception; State = ValueState.Exception;
} }
else if (Value.IsNullOrDestroyed()) else if (Value.IsNullOrDestroyed())
{ {
LastValueWasNull = true; valueIsNull = true;
State = GetStateForType(FallbackType); State = GetStateForType(FallbackType);
} }
else else
{ {
LastValueWasNull = false; valueIsNull = false;
State = GetStateForType(Value.GetActualType()); State = GetStateForType(Value.GetActualType());
} }
@ -163,10 +164,10 @@ namespace UnityExplorer.CacheObject
public ValueState GetStateForType(Type type) public ValueState GetStateForType(Type type)
{ {
if (LastValueType == type && (State != ValueState.Exception || LastException != null)) if (currentValueType == type && (State != ValueState.Exception || LastException != null))
return State; return State;
LastValueType = type; currentValueType = type;
if (type == typeof(bool)) if (type == typeof(bool))
return ValueState.Boolean; return ValueState.Boolean;
else if (type.IsPrimitive || type == typeof(decimal)) else if (type.IsPrimitive || type == typeof(decimal))
@ -189,7 +190,7 @@ namespace UnityExplorer.CacheObject
protected string GetValueLabel() protected string GetValueLabel()
{ {
string label = ""; string label = string.Empty;
switch (State) switch (State)
{ {
@ -206,19 +207,19 @@ namespace UnityExplorer.CacheObject
// and valuestruct also doesnt want it if we can parse it // and valuestruct also doesnt want it if we can parse it
case ValueState.ValueStruct: case ValueState.ValueStruct:
if (ParseUtility.CanParse(LastValueType)) if (ParseUtility.CanParse(currentValueType))
return null; return null;
break; break;
// string wants it trimmed to max 200 chars // string wants it trimmed to max 200 chars
case ValueState.String: case ValueState.String:
if (!LastValueWasNull) if (!valueIsNull)
return $"\"{ToStringUtility.PruneString(Value as string, 200, 5)}\""; return $"\"{ToStringUtility.PruneString(Value as string, 200, 5)}\"";
break; break;
// try to prefix the count of the collection for lists and dicts // try to prefix the count of the collection for lists and dicts
case ValueState.Collection: case ValueState.Collection:
if (!LastValueWasNull) if (!valueIsNull)
{ {
if (Value is IList iList) if (Value is IList iList)
label = $"[{iList.Count}] "; label = $"[{iList.Count}] ";
@ -230,7 +231,7 @@ namespace UnityExplorer.CacheObject
break; break;
case ValueState.Dictionary: case ValueState.Dictionary:
if (!LastValueWasNull) if (!valueIsNull)
{ {
if (Value is IDictionary iDict) if (Value is IDictionary iDict)
label = $"[{iDict.Count}] "; label = $"[{iDict.Count}] ";
@ -291,7 +292,7 @@ namespace UnityExplorer.CacheObject
SetValueState(cell, new(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite)); SetValueState(cell, new(false, typeLabelActive: true, inputActive: true, applyActive: CanWrite));
break; break;
case ValueState.String: case ValueState.String:
if (LastValueWasNull) if (valueIsNull)
SetValueState(cell, new(true, subContentButtonActive: true)); SetValueState(cell, new(true, subContentButtonActive: true));
else else
SetValueState(cell, new(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true)); SetValueState(cell, new(true, false, SignatureHighlighter.StringOrange, subContentButtonActive: true));
@ -301,17 +302,17 @@ namespace UnityExplorer.CacheObject
break; break;
case ValueState.Color: case ValueState.Color:
case ValueState.ValueStruct: case ValueState.ValueStruct:
if (ParseUtility.CanParse(LastValueType)) if (ParseUtility.CanParse(currentValueType))
SetValueState(cell, new(false, false, null, true, false, true, CanWrite, true, true)); SetValueState(cell, new(false, false, null, true, false, true, CanWrite, true, true));
else else
SetValueState(cell, new(true, inspectActive: true, subContentButtonActive: true)); SetValueState(cell, new(true, inspectActive: true, subContentButtonActive: true));
break; break;
case ValueState.Collection: case ValueState.Collection:
case ValueState.Dictionary: case ValueState.Dictionary:
SetValueState(cell, new(true, inspectActive: !LastValueWasNull, subContentButtonActive: !LastValueWasNull)); SetValueState(cell, new(true, inspectActive: !valueIsNull, subContentButtonActive: !valueIsNull));
break; break;
case ValueState.Unsupported: case ValueState.Unsupported:
SetValueState(cell, new(true, inspectActive: !LastValueWasNull)); SetValueState(cell, new(true, inspectActive: !valueIsNull));
break; break;
} }
@ -333,7 +334,7 @@ namespace UnityExplorer.CacheObject
// Type label (for primitives) // Type label (for primitives)
cell.TypeLabel.gameObject.SetActive(args.typeLabelActive); cell.TypeLabel.gameObject.SetActive(args.typeLabelActive);
if (args.typeLabelActive) if (args.typeLabelActive)
cell.TypeLabel.text = SignatureHighlighter.Parse(LastValueType, false); cell.TypeLabel.text = SignatureHighlighter.Parse(currentValueType, false);
// toggle for bools // toggle for bools
cell.Toggle.gameObject.SetActive(args.toggleActive); cell.Toggle.gameObject.SetActive(args.toggleActive);
@ -348,7 +349,7 @@ namespace UnityExplorer.CacheObject
cell.InputField.UIRoot.SetActive(args.inputActive); cell.InputField.UIRoot.SetActive(args.inputActive);
if (args.inputActive) if (args.inputActive)
{ {
cell.InputField.Text = ParseUtility.ToStringForInput(Value, LastValueType); cell.InputField.Text = ParseUtility.ToStringForInput(Value, currentValueType);
cell.InputField.Component.readOnly = !CanWrite; cell.InputField.Component.readOnly = !CanWrite;
} }
@ -357,12 +358,12 @@ namespace UnityExplorer.CacheObject
// Inspect button only if last value not null. // Inspect button only if last value not null.
if (cell.InspectButton != null) if (cell.InspectButton != null)
cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull); cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !valueIsNull);
// set subcontent button if needed, and for null strings and exceptions // set subcontent button if needed, and for null strings and exceptions
cell.SubContentButton.Component.gameObject.SetActive( cell.SubContentButton.Component.gameObject.SetActive(
args.subContentButtonActive args.subContentButtonActive
&& (!LastValueWasNull || State == ValueState.String || State == ValueState.Exception)); && (!valueIsNull || State == ValueState.String || State == ValueState.Exception));
} }
// CacheObjectCell Apply // CacheObjectCell Apply
@ -373,7 +374,7 @@ namespace UnityExplorer.CacheObject
SetUserValue(this.CellView.Toggle.isOn); SetUserValue(this.CellView.Toggle.isOn);
else else
{ {
if (ParseUtility.TryParse(CellView.InputField.Text, LastValueType, out object value, out Exception ex)) if (ParseUtility.TryParse(CellView.InputField.Text, currentValueType, out object value, out Exception ex))
{ {
SetUserValue(value); SetUserValue(value);
} }