Fix SubContentWanted for InteractiveDictionary, remove redundant IValueTypes enum/dict

This commit is contained in:
sinaioutlander 2020-11-16 01:32:58 +11:00
parent 2e96d09f67
commit 4a1125cf1d
7 changed files with 26 additions and 58 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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<IValueTypes, Type> s_typeDict = new Dictionary<IValueTypes, Type>
{
{ 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;