Skip to content

Commit

Permalink
Merge pull request neuecc#284 from Bezarius/InspectorDisplayDrawer_Ne…
Browse files Browse the repository at this point in the history
…stedFiled_Fix

If the field is in the base class, the inspector can not access it. Fix.
  • Loading branch information
neuecc authored Jul 16, 2018
2 parents 0728e83 + 5c67a80 commit 735fed5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions UnityEngineBridge/InspectorDisplayDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,24 @@ public override void OnGUI(Rect position, UnityEditor.SerializedProperty propert
object GetValueRecursive(object obj, int index, string[] paths)
{
var path = paths[index];
var fieldInfo = obj.GetType().GetField(path, BindingFlags.IgnoreCase | BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

FieldInfo fldInfo = null;
var type = obj.GetType();
while (fldInfo == null)
{
// attempt to get information about the field
fldInfo = type.GetField(path, BindingFlags.IgnoreCase | BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

if (fldInfo != null ||
type.BaseType == null ||
type.BaseType.IsSubclassOf(typeof(ReactiveProperty<>))) break;

// if the field information is missing, it may be in the base class
type = type.BaseType;
}

// If array, path = Array.data[index]
if (fieldInfo == null && path == "Array")
if (fldInfo == null && path == "Array")
{
try
{
Expand All @@ -172,12 +186,12 @@ object GetValueRecursive(object obj, int index, string[] paths)
throw;
}
}
else if (fieldInfo == null)
else if (fldInfo == null)
{
throw new Exception("Can't decode path, please report to UniRx's GitHub issues:" + string.Join(", ", paths));
}

var v = fieldInfo.GetValue(obj);
var v = fldInfo.GetValue(obj);
if (index < paths.Length - 1)
{
return GetValueRecursive(v, ++index, paths);
Expand Down

0 comments on commit 735fed5

Please sign in to comment.