Fix for cases when structs return null (due to null declaring instance)

This commit is contained in:
sinaioutlander 2020-09-20 20:26:05 +10:00
parent 3639824df3
commit 04248a89ce
5 changed files with 22 additions and 14 deletions

View File

@ -21,6 +21,8 @@ namespace Explorer
{
base.UpdateValue();
if (Value == null) return;
var color = (Color)Value;
r = color.r.ToString();

View File

@ -11,23 +11,19 @@ namespace Explorer
{
public class CacheEnum : CacheObjectBase
{
public Type EnumType;
// public Type EnumType;
public string[] EnumNames;
public override void Init()
{
try
if (ValueType == null && Value != null)
{
EnumType = Value.GetType();
}
catch
{
EnumType = (MemInfo as FieldInfo)?.FieldType ?? (MemInfo as PropertyInfo).PropertyType;
ValueType = Value.GetType();
}
if (EnumType != null)
if (ValueType != null)
{
EnumNames = Enum.GetNames(EnumType);
EnumNames = Enum.GetNames(ValueType);
}
else
{
@ -62,7 +58,7 @@ namespace Explorer
if ((change < 0 && newindex >= 0) || (change > 0 && newindex < names.Count))
{
value = Enum.Parse(EnumType, names[newindex]);
value = Enum.Parse(ValueType, names[newindex]);
}
}
}

View File

@ -20,6 +20,8 @@ namespace Explorer
{
base.UpdateValue();
if (Value == null) return;
var euler = ((Quaternion)Value).eulerAngles;
x = euler.x.ToString();

View File

@ -21,6 +21,8 @@ namespace Explorer
{
base.UpdateValue();
if (Value == null) return;
var rect = (Rect)Value;
x = rect.x.ToString();

View File

@ -24,20 +24,26 @@ namespace Explorer
public override void Init()
{
if (Value is Vector2)
if (ValueType == null && Value != null)
{
ValueType = Value.GetType();
}
if (ValueType == typeof(Vector2))
{
VectorSize = 2;
m_toStringMethod = typeof(Vector2).GetMethod("ToString", new Type[0]);
}
else if (Value is Vector3)
else if (ValueType == typeof(Vector3))
{
VectorSize = 3;
m_toStringMethod = typeof(Vector3).GetMethod("ToString", new Type[0]);
}
else
{
VectorSize = 4;
m_toStringMethod = typeof(Vector4).GetMethod("ToString", new Type[0]);
}
m_toStringMethod = Value.GetType().GetMethod("ToString", new Type[0]);
}
public override void UpdateValue()