From 7b700cbe55be0728e940912234b36f8ed5245ee4 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sun, 9 May 2021 02:22:03 +1000 Subject: [PATCH] Cleanup, extend ParseUtility to dict keys --- src/Core/Reflection/Extensions.cs | 2 +- src/Core/Utility/ArgumentUtility.cs | 1 - src/Core/Utility/IOUtility.cs | 1 - src/Core/Utility/ParseUtility.cs | 3 +-- .../Utility/SignatureHighlighter.cs | 2 +- src/{UI => Core}/Utility/ToStringUtility.cs | 2 +- src/UI/CacheObject/CacheKeyValuePair.cs | 4 +-- src/UI/CacheObject/CacheObjectBase.cs | 25 ++++++++++++++++--- .../Views/CacheKeyValuePairCell.cs | 2 +- src/UI/IValues/InteractiveColor.cs | 1 - src/UI/IValues/InteractiveDictionary.cs | 3 ++- src/UI/IValues/InteractiveEnum.cs | 3 +-- src/UI/IValues/InteractiveList.cs | 4 ++- src/UI/IValues/InteractiveString.cs | 1 - src/UI/IValues/InteractiveValue.cs | 2 ++ src/UI/IValues/InteractiveValueStruct.cs | 1 - src/UI/Inspectors/InspectorManager.cs | 8 ++++-- src/UI/Models/InputFieldRef.cs | 1 - src/UnityExplorer.csproj | 14 ++--------- 19 files changed, 44 insertions(+), 36 deletions(-) rename src/{UI => Core}/Utility/SignatureHighlighter.cs (99%) rename src/{UI => Core}/Utility/ToStringUtility.cs (99%) diff --git a/src/Core/Reflection/Extensions.cs b/src/Core/Reflection/Extensions.cs index 7ba0753..f948fd5 100644 --- a/src/Core/Reflection/Extensions.cs +++ b/src/Core/Reflection/Extensions.cs @@ -92,7 +92,7 @@ namespace UnityExplorer public static string ReflectionExToString(this Exception e, bool innerMost = true) { if (innerMost) - e.GetInnerMostException(); + e = e.GetInnerMostException(); return $"{e.GetType()}: {e.Message}"; } diff --git a/src/Core/Utility/ArgumentUtility.cs b/src/Core/Utility/ArgumentUtility.cs index da85a5e..c7b1634 100644 --- a/src/Core/Utility/ArgumentUtility.cs +++ b/src/Core/Utility/ArgumentUtility.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace UnityExplorer { diff --git a/src/Core/Utility/IOUtility.cs b/src/Core/Utility/IOUtility.cs index 9a97300..9282703 100644 --- a/src/Core/Utility/IOUtility.cs +++ b/src/Core/Utility/IOUtility.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace UnityExplorer { diff --git a/src/Core/Utility/ParseUtility.cs b/src/Core/Utility/ParseUtility.cs index 88100cc..4fb6e82 100644 --- a/src/Core/Utility/ParseUtility.cs +++ b/src/Core/Utility/ParseUtility.cs @@ -4,7 +4,6 @@ using System.Globalization; using System.Linq; using System.Reflection; using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace UnityExplorer @@ -264,7 +263,7 @@ namespace UnityExplorer if (!(obj is Quaternion quaternion)) return null; - Vector3 vector = Quaternion.ToEulerAngles(quaternion); + Vector3 vector = quaternion.eulerAngles; return string.Format(en_US, "{0}, {1}, {2}", new object[] { diff --git a/src/UI/Utility/SignatureHighlighter.cs b/src/Core/Utility/SignatureHighlighter.cs similarity index 99% rename from src/UI/Utility/SignatureHighlighter.cs rename to src/Core/Utility/SignatureHighlighter.cs index 497663f..3e7a1a3 100644 --- a/src/UI/Utility/SignatureHighlighter.cs +++ b/src/Core/Utility/SignatureHighlighter.cs @@ -7,7 +7,7 @@ using System.Text; using UnityEngine; using UnityExplorer.Core.Runtime; -namespace UnityExplorer.UI.Utility +namespace UnityExplorer { /// /// Syntax-highlights a member's signature, by either the Type name or a Type and Member together. diff --git a/src/UI/Utility/ToStringUtility.cs b/src/Core/Utility/ToStringUtility.cs similarity index 99% rename from src/UI/Utility/ToStringUtility.cs rename to src/Core/Utility/ToStringUtility.cs index 8e4066c..f580d75 100644 --- a/src/UI/Utility/ToStringUtility.cs +++ b/src/Core/Utility/ToStringUtility.cs @@ -8,7 +8,7 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityExplorer.Core.Runtime; -namespace UnityExplorer.UI.Utility +namespace UnityExplorer { public static class ToStringUtility { diff --git a/src/UI/CacheObject/CacheKeyValuePair.cs b/src/UI/CacheObject/CacheKeyValuePair.cs index f330d8f..38f2c1e 100644 --- a/src/UI/CacheObject/CacheKeyValuePair.cs +++ b/src/UI/CacheObject/CacheKeyValuePair.cs @@ -41,10 +41,10 @@ namespace UnityExplorer.UI.CacheObject this.DisplayedKey = key.TryCast(); var type = DisplayedKey.GetType(); - if (type == typeof(string) || (type.IsPrimitive && !(type == typeof(bool)))) + if (ParseUtility.CanParse(type)) { KeyInputWanted = true; - KeyInputText = DisplayedKey.ToString(); + KeyInputText = ParseUtility.ToStringForInput(DisplayedKey, type); KeyInputTypeText = SignatureHighlighter.Parse(type, false); } else diff --git a/src/UI/CacheObject/CacheObjectBase.cs b/src/UI/CacheObject/CacheObjectBase.cs index 0428942..ee71abe 100644 --- a/src/UI/CacheObject/CacheObjectBase.cs +++ b/src/UI/CacheObject/CacheObjectBase.cs @@ -98,7 +98,13 @@ namespace UnityExplorer.UI.CacheObject TrySetUserValue(value); - SetDataToCell(CellView); + if (CellView != null) + SetDataToCell(CellView); + + // If the owner's parent CacheObject is set, we are setting the value of an inspected struct. + // Set the inspector target as the value back to that parent cacheobject. + if (Owner.ParentCacheObject != null) + Owner.ParentCacheObject.SetUserValue(Owner.Target); } public abstract void TrySetUserValue(object value); @@ -114,7 +120,12 @@ namespace UnityExplorer.UI.CacheObject ProcessOnEvaluate(); if (this.IValue != null) - this.IValue.SetValue(Value); + { + if (SubContentShowWanted) + this.IValue.SetValue(Value); + else + IValue.PendingValueWanted = true; + } } protected virtual void ProcessOnEvaluate() @@ -348,8 +359,6 @@ namespace UnityExplorer.UI.CacheObject // CacheObjectCell Apply - // todo make this a reusable utility method - public virtual void OnCellApplyClicked() { if (State == ValueState.Boolean) @@ -399,6 +408,14 @@ namespace UnityExplorer.UI.CacheObject { SubContentShowWanted = !SubContentShowWanted; CellView.SubContentHolder.SetActive(SubContentShowWanted); + + if (SubContentShowWanted && IValue.PendingValueWanted) + { + IValue.PendingValueWanted = false; + this.ProcessOnEvaluate(); + this.SetDataToCell(this.CellView); + IValue.SetValue(this.Value); + } } CellView.RefreshSubcontentButton(); diff --git a/src/UI/CacheObject/Views/CacheKeyValuePairCell.cs b/src/UI/CacheObject/Views/CacheKeyValuePairCell.cs index 1b8a5e9..8b209f5 100644 --- a/src/UI/CacheObject/Views/CacheKeyValuePairCell.cs +++ b/src/UI/CacheObject/Views/CacheKeyValuePairCell.cs @@ -61,7 +61,7 @@ namespace UnityExplorer.UI.CacheObject.Views KeyInspectButton = UIFactory.CreateButton(keyGroup, "KeyInspectButton", "Inspect", new Color(0.15f, 0.15f, 0.15f)); UIFactory.SetLayoutElement(KeyInspectButton.Button.gameObject, minWidth: 60, flexibleWidth: 0, minHeight: 25, flexibleHeight: 0); - InspectButton.OnClick += KeyInspectClicked; + KeyInspectButton.OnClick += KeyInspectClicked; // label diff --git a/src/UI/IValues/InteractiveColor.cs b/src/UI/IValues/InteractiveColor.cs index f6932fa..d5b6678 100644 --- a/src/UI/IValues/InteractiveColor.cs +++ b/src/UI/IValues/InteractiveColor.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityExplorer.UI.CacheObject; diff --git a/src/UI/IValues/InteractiveDictionary.cs b/src/UI/IValues/InteractiveDictionary.cs index f943128..dff20a2 100644 --- a/src/UI/IValues/InteractiveDictionary.cs +++ b/src/UI/IValues/InteractiveDictionary.cs @@ -167,7 +167,8 @@ namespace UnityExplorer.UI.IValues var entry = cachedEntries[keyIndex]; entry.SetValueFromSource(value); - entry.SetDataToCell(entry.CellView); + if (entry.CellView != null) + entry.SetDataToCell(entry.CellView); } catch (Exception ex) { diff --git a/src/UI/IValues/InteractiveEnum.cs b/src/UI/IValues/InteractiveEnum.cs index 8a348ff..7b57a9d 100644 --- a/src/UI/IValues/InteractiveEnum.cs +++ b/src/UI/IValues/InteractiveEnum.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityExplorer.UI.CacheObject; @@ -84,7 +83,7 @@ namespace UnityExplorer.UI.IValues values.Add(ValueAtIdx(i).Name); } - CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values))); + CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values.ToArray()))); } catch (Exception ex) { diff --git a/src/UI/IValues/InteractiveList.cs b/src/UI/IValues/InteractiveList.cs index a95a194..19a823b 100644 --- a/src/UI/IValues/InteractiveList.cs +++ b/src/UI/IValues/InteractiveList.cs @@ -149,7 +149,9 @@ namespace UnityExplorer.UI.IValues var entry = cachedEntries[index]; entry.SetValueFromSource(value); - entry.SetDataToCell(entry.CellView); + + if (entry.CellView != null) + entry.SetDataToCell(entry.CellView); } catch (Exception ex) { diff --git a/src/UI/IValues/InteractiveString.cs b/src/UI/IValues/InteractiveString.cs index 063e57a..c970af7 100644 --- a/src/UI/IValues/InteractiveString.cs +++ b/src/UI/IValues/InteractiveString.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityExplorer.Core.Config; diff --git a/src/UI/IValues/InteractiveValue.cs b/src/UI/IValues/InteractiveValue.cs index 9891ba6..80f5000 100644 --- a/src/UI/IValues/InteractiveValue.cs +++ b/src/UI/IValues/InteractiveValue.cs @@ -39,6 +39,8 @@ namespace UnityExplorer.UI.IValues public CacheObjectBase CurrentOwner => m_owner; private CacheObjectBase m_owner; + public bool PendingValueWanted; + public virtual void OnBorrowed(CacheObjectBase owner) { if (this.m_owner != null) diff --git a/src/UI/IValues/InteractiveValueStruct.cs b/src/UI/IValues/InteractiveValueStruct.cs index ec3105b..2d965b4 100644 --- a/src/UI/IValues/InteractiveValueStruct.cs +++ b/src/UI/IValues/InteractiveValueStruct.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityExplorer.UI.CacheObject; diff --git a/src/UI/Inspectors/InspectorManager.cs b/src/UI/Inspectors/InspectorManager.cs index 5dbb530..f9fa3c5 100644 --- a/src/UI/Inspectors/InspectorManager.cs +++ b/src/UI/Inspectors/InspectorManager.cs @@ -77,8 +77,12 @@ namespace UnityExplorer.UI.Inspectors Inspectors.Add(inspector); inspector.Target = target; - if (sourceCache != null && inspector is ReflectionInspector ri) - ri.ParentCacheObject = sourceCache; + if (sourceCache != null && sourceCache.CanWrite) + { + // only set parent cache object if we are inspecting a struct, otherwise there is no point. + if (target.GetType().IsValueType && inspector is ReflectionInspector ri) + ri.ParentCacheObject = sourceCache; + } UIManager.SetPanelActive(UIManager.Panels.Inspector, true); inspector.UIRoot.transform.SetParent(InspectorPanel.Instance.ContentHolder.transform, false); diff --git a/src/UI/Models/InputFieldRef.cs b/src/UI/Models/InputFieldRef.cs index 5fc4596..b18c2f5 100644 --- a/src/UI/Models/InputFieldRef.cs +++ b/src/UI/Models/InputFieldRef.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityExplorer.UI.Models; diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index b71ac98..ef6ab21 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -306,20 +306,10 @@ - - + + - - - - - - - - - -