diff --git a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs index e410cbe..7996dc1 100644 --- a/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs +++ b/Assets/BetterEditorTools/Editor/EditorTools/SerializedPropertyExtensions.cs @@ -62,9 +62,8 @@ public static string GetPropertyParentList(this SerializedProperty property) public static string GetPropertyParentList(string propertyPath) { - int length = propertyPath.LastIndexOf(".Array.data[", StringComparison.Ordinal); - return length < 0 ? (string) null : propertyPath.Substring(0, length); + return length < 0 ? (string)null : propertyPath.Substring(0, length); } public static string GetArrayNameFromPath(this SerializedProperty property) @@ -242,12 +241,12 @@ private static bool IsCollectionType(this Type targetType) return false; } - + public static List GetPropertyContainers(this SerializedProperty property) { string propertyPath = property.propertyPath; object container = property.serializedObject.targetObject; - + int i = 0; PropertyPathComponent deferredToken; var list = new List(); @@ -278,7 +277,7 @@ private static object GetPropertyContainer(SerializedProperty property, out Prop container = GetPathComponentValue(container, deferredToken); deferredToken = token; } - + return container; } @@ -364,18 +363,37 @@ private static object GetMemberValue(object container, string name) if (container == null) return null; var type = container.GetType(); - var members = type.GetMember(name, BetterEditorDefines.FieldsFlags); - for (int i = 0; i < members.Length; ++i) + var members = TraverseBaseClasses(type, name); + for (int i = 0; i < members.Count; ++i) { if (members[i] is FieldInfo field) return field.GetValue(container); - else if (members[i] is PropertyInfo property) + + if (members[i] is PropertyInfo property) return property.GetValue(container); } return null; } + private static List TraverseBaseClasses(Type currentType, string name) + { + var memberInfos = new List(); + + var currentTypeFields = currentType.GetMember(name, BetterEditorDefines.FieldsFlags); + memberInfos.AddRange(currentTypeFields); + + var baseType = currentType.BaseType; + + if (baseType == null) return memberInfos; + var baseTypeFields = baseType.GetMember(name, BetterEditorDefines.FieldsFlags); + memberInfos.AddRange(baseTypeFields); + + memberInfos.AddRange(TraverseBaseClasses(baseType, name)); // Recursively traverse the base classes + + return memberInfos; + } + private static void SetMemberValue(object container, string name, object value) { var type = container.GetType(); @@ -384,7 +402,7 @@ private static void SetMemberValue(object container, string name, object value) { if (members[i] is FieldInfo field) { - if(!type.IsValueType && !type.IsEnum) + if (!type.IsValueType && !type.IsEnum) { field.SetValue(container, value); } @@ -392,6 +410,7 @@ private static void SetMemberValue(object container, string name, object value) { field.SetValueDirect(__makeref(container), value); } + return; } else if (members[i] is PropertyInfo property) diff --git a/Assets/BetterEditorTools/package.json b/Assets/BetterEditorTools/package.json index 0dc0013..0140398 100644 --- a/Assets/BetterEditorTools/package.json +++ b/Assets/BetterEditorTools/package.json @@ -2,7 +2,7 @@ "name": "com.uurha.bettereditortools", "displayName": "Better Editor Tools", "description": "Collection of useful tools for Unity Editor", - "version": "1.0.66", + "version": "1.0.67", "unity": "2020.1", "dependencies": { "com.uurha.betterdatastructures": "0.1.1",