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(); base.UpdateValue();
if (Value == null) return;
var color = (Color)Value; var color = (Color)Value;
r = color.r.ToString(); r = color.r.ToString();

View File

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

View File

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

View File

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