From 4a1125cf1d4c96987a635ce756609c944bb49991 Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Mon, 16 Nov 2020 01:32:58 +1100 Subject: [PATCH] Fix SubContentWanted for InteractiveDictionary, remove redundant IValueTypes enum/dict --- .../Reflection/CacheObject/CacheObjectBase.cs | 5 +- .../InteractiveValue/InteractiveBool.cs | 5 +- .../InteractiveValue/InteractiveDictionary.cs | 14 ++++-- .../InteractiveValue/InteractiveEnumerable.cs | 2 - .../InteractiveValue/InteractiveNumber.cs | 5 +- .../InteractiveValue/InteractiveString.cs | 5 +- .../InteractiveValue/InteractiveValue.cs | 48 ++++--------------- 7 files changed, 26 insertions(+), 58 deletions(-) diff --git a/src/Inspectors/Reflection/CacheObject/CacheObjectBase.cs b/src/Inspectors/Reflection/CacheObject/CacheObjectBase.cs index ba7deb3..871d61f 100644 --- a/src/Inspectors/Reflection/CacheObject/CacheObjectBase.cs +++ b/src/Inspectors/Reflection/CacheObject/CacheObjectBase.cs @@ -49,13 +49,14 @@ namespace UnityExplorer.Inspectors.Reflection { var value = IValue.Value; - // see if current value has changed types fundamentally + // if the type has changed fundamentally, make a new interactivevalue for it var type = value == null ? FallbackType : ReflectionHelpers.GetActualType(value); + var ivalueType = InteractiveValue.GetIValueForType(type); - if (ivalueType != IValue.IValueType) + if (ivalueType != IValue.GetType()) { IValue.OnDestroy(); CreateIValue(value, FallbackType); diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveBool.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveBool.cs index a1843ed..e225941 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveBool.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveBool.cs @@ -11,11 +11,8 @@ namespace UnityExplorer.Inspectors.Reflection { public class InteractiveBool : InteractiveValue { - public InteractiveBool(object value, Type valueType) : base(value, valueType) - { - } + public InteractiveBool(object value, Type valueType) : base(value, valueType) { } - public override IValueTypes IValueType => IValueTypes.Bool; public override bool HasSubContent => false; public override bool SubContentWanted => false; public override bool WantInspectBtn => false; diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveDictionary.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveDictionary.cs index 7df7bc9..7f8c09a 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveDictionary.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveDictionary.cs @@ -29,10 +29,18 @@ namespace UnityExplorer.Inspectors.Reflection } } - public override IValueTypes IValueType => IValueTypes.Dictionary; - public override bool HasSubContent => true; - public override bool SubContentWanted => (RefIDictionary?.Count ?? 1) > 0; public override bool WantInspectBtn => false; + public override bool HasSubContent => true; + // todo fix for il2cpp + public override bool SubContentWanted + { + get + { + if (m_recacheWanted) + return true; + else return m_entries.Count > 0; + } + } internal IDictionary RefIDictionary; diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveEnumerable.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveEnumerable.cs index 1331ae9..0f98d61 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveEnumerable.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveEnumerable.cs @@ -22,8 +22,6 @@ namespace UnityExplorer.Inspectors.Reflection m_baseEntryType = typeof(object); } - public override IValueTypes IValueType => IValueTypes.Enumerable; - public override bool WantInspectBtn => false; public override bool HasSubContent => true; public override bool SubContentWanted diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveNumber.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveNumber.cs index 370abb4..f6a781e 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveNumber.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveNumber.cs @@ -8,11 +8,8 @@ namespace UnityExplorer.Inspectors.Reflection { public class InteractiveNumber : InteractiveValue { - public InteractiveNumber(object value, Type valueType) : base(value, valueType) - { - } + public InteractiveNumber(object value, Type valueType) : base(value, valueType) { } - public override IValueTypes IValueType => IValueTypes.Number; public override bool HasSubContent => false; public override bool SubContentWanted => false; public override bool WantInspectBtn => false; diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveString.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveString.cs index c74dccf..1af0731 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveString.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveString.cs @@ -8,11 +8,8 @@ namespace UnityExplorer.Inspectors.Reflection { public class InteractiveString : InteractiveValue { - public InteractiveString(object value, Type valueType) : base(value, valueType) - { - } + public InteractiveString(object value, Type valueType) : base(value, valueType) { } - public override IValueTypes IValueType => IValueTypes.String; public override bool HasSubContent => false; public override bool SubContentWanted => false; public override bool WantInspectBtn => false; diff --git a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs index 79bec99..88a8080 100644 --- a/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs +++ b/src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs @@ -10,53 +10,25 @@ using UnityExplorer.UI; namespace UnityExplorer.Inspectors.Reflection { - // WIP - public enum IValueTypes - { - Any, - Enumerable, - Dictionary, - Bool, - String, - Number, - Enum, - Flags, - UnityStruct, - Color, // maybe - } - public class InteractiveValue { - // ~~~~~~~~~ Static ~~~~~~~~~ - // WIP - internal static Dictionary s_typeDict = new Dictionary - { - { IValueTypes.Any, typeof(InteractiveValue) }, - { IValueTypes.Dictionary, typeof(InteractiveDictionary) }, - { IValueTypes.Enumerable, typeof(InteractiveEnumerable) }, - { IValueTypes.Bool, typeof(InteractiveBool) }, - { IValueTypes.String, typeof(InteractiveString) }, - { IValueTypes.Number, typeof(InteractiveNumber) }, - }; - - // WIP - public static IValueTypes GetIValueForType(Type type) + public static Type GetIValueForType(Type type) { if (type == typeof(bool)) - return IValueTypes.Bool; + return typeof(InteractiveBool); else if (type == typeof(string)) - return IValueTypes.String; + return typeof(InteractiveString); else if (type.IsPrimitive) - return IValueTypes.Number; + return typeof(InteractiveNumber); else if (typeof(Transform).IsAssignableFrom(type)) - return IValueTypes.Any; + return typeof(InteractiveValue); else if (ReflectionHelpers.IsDictionary(type)) - return IValueTypes.Dictionary; + return typeof(InteractiveDictionary); else if (ReflectionHelpers.IsEnumerable(type)) - return IValueTypes.Enumerable; + return typeof(InteractiveEnumerable); else - return IValueTypes.Any; + return typeof(InteractiveValue); } public static InteractiveValue Create(object value, Type fallbackType) @@ -64,7 +36,7 @@ namespace UnityExplorer.Inspectors.Reflection var type = ReflectionHelpers.GetActualType(value) ?? fallbackType; var iType = GetIValueForType(type); - return (InteractiveValue)Activator.CreateInstance(s_typeDict[iType], new object[] { value, type }); + return (InteractiveValue)Activator.CreateInstance(iType, new object[] { value, type }); } // ~~~~~~~~~ Instance ~~~~~~~~~ @@ -80,8 +52,6 @@ namespace UnityExplorer.Inspectors.Reflection public object Value { get; set; } public readonly Type FallbackType; - public virtual IValueTypes IValueType => IValueTypes.Any; - public virtual bool HasSubContent => false; public virtual bool SubContentWanted => false; public virtual bool WantInspectBtn => true;