From d81e9df6fbc4fb0eb2ca70c7b3a46418045923aa Mon Sep 17 00:00:00 2001 From: mnicolas94 Date: Wed, 17 Aug 2022 15:33:59 -0400 Subject: [PATCH 1/5] fix: fix issue with unity version 2021.1 issue Thundernerd/Unity3D-SerializableInterface#51 --- Editor/Drawers/ReferenceDrawer.cs | 2 +- Editor/Utilities/IconUtility.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index 85e4010..03383f6 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -219,7 +219,7 @@ protected void SetModeValue(SerializedProperty property, ReferenceMode mode) protected object GetRawReferenceValue(SerializedProperty property) { -#if UNITY_2021_1_OR_NEWER +#if UNITY_2021_2_OR_NEWER return property.RawReferenceProperty().managedReferenceValue; #else ISerializableInterface instance = diff --git a/Editor/Utilities/IconUtility.cs b/Editor/Utilities/IconUtility.cs index 0f539aa..f54f422 100644 --- a/Editor/Utilities/IconUtility.cs +++ b/Editor/Utilities/IconUtility.cs @@ -5,7 +5,7 @@ namespace TNRD.Utilities { internal static class IconUtility { -#if UNITY_2021_1_OR_NEWER +#if UNITY_2021_3_OR_NEWER || UNITY_2020_3 private static Texture2D folderIcon; public static Texture2D FolderIcon From ffe848c940898c22816268d8be2aa3d84721a678 Mon Sep 17 00:00:00 2001 From: mnicolas94 Date: Wed, 17 Aug 2022 15:37:43 -0400 Subject: [PATCH 2/5] fix: fix version directive in IconUtility issue Thundernerd/Unity3D-SerializableInterface#51 --- Editor/Utilities/IconUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/Utilities/IconUtility.cs b/Editor/Utilities/IconUtility.cs index f54f422..b95cd3e 100644 --- a/Editor/Utilities/IconUtility.cs +++ b/Editor/Utilities/IconUtility.cs @@ -5,7 +5,7 @@ namespace TNRD.Utilities { internal static class IconUtility { -#if UNITY_2021_3_OR_NEWER || UNITY_2020_3 +#if UNITY_2021_2_OR_NEWER private static Texture2D folderIcon; public static Texture2D FolderIcon From 8d663496eef8eab34e5553617ad9697d3e61d8f1 Mon Sep 17 00:00:00 2001 From: mnicolas94 Date: Mon, 22 Aug 2022 12:47:54 -0400 Subject: [PATCH 3/5] FIX: fix editor drawing of managed classes inside list --- Editor/Drawers/ReferenceDrawer.cs | 5 +- Editor/Utilities/SerializedPropertiesUtils.cs | 76 +++++++++++++++++++ .../SerializedPropertiesUtils.cs.meta | 3 + 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 Editor/Utilities/SerializedPropertiesUtils.cs create mode 100644 Editor/Utilities/SerializedPropertiesUtils.cs.meta diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index 03383f6..c654886 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -222,9 +222,8 @@ protected object GetRawReferenceValue(SerializedProperty property) #if UNITY_2021_2_OR_NEWER return property.RawReferenceProperty().managedReferenceValue; #else - ISerializableInterface instance = - (ISerializableInterface)FieldInfo.GetValue(property.serializedObject.targetObject); - return instance.GetRawReference(); + var target = (ISerializableInterface) SerializedPropertiesUtils.GetTargetObjectOfProperty(property); + return target.GetRawReference(); #endif } diff --git a/Editor/Utilities/SerializedPropertiesUtils.cs b/Editor/Utilities/SerializedPropertiesUtils.cs new file mode 100644 index 0000000..7d587fc --- /dev/null +++ b/Editor/Utilities/SerializedPropertiesUtils.cs @@ -0,0 +1,76 @@ +using System; +using System.Reflection; +using UnityEditor; + +namespace TNRD.Utilities +{ + public static class SerializedPropertiesUtils + { + /// + /// This code was taken from https://github.com/dbrizov/NaughtyAttributes + /// + public static object GetTargetObjectOfProperty(SerializedProperty prop) + { + if (prop == null) return null; + + var path = prop.propertyPath.Replace(".Array.data[", "["); + object obj = prop.serializedObject.targetObject; + var elements = path.Split('.'); + foreach (var element in elements) + { + if (element.Contains("[")) + { + var elementName = element.Substring(0, element.IndexOf("[")); + var index = Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[", "").Replace("]", "")); + obj = GetValue_Imp(obj, elementName, index); + } + else + { + obj = GetValue_Imp(obj, element); + } + } + return obj; + } + + + /// + /// This code was taken from https://github.com/dbrizov/NaughtyAttributes + /// + private static object GetValue_Imp(object source, string name, int index) + { + var enumerable = GetValue_Imp(source, name) as System.Collections.IEnumerable; + if (enumerable == null) return null; + var enm = enumerable.GetEnumerator(); + + for (int i = 0; i <= index; i++) + { + if (!enm.MoveNext()) return null; + } + return enm.Current; + } + + /// + /// This code was taken from https://github.com/dbrizov/NaughtyAttributes + /// + private static object GetValue_Imp(object source, string name) + { + if (source == null) + return null; + var type = source.GetType(); + + while (type != null) + { + var f = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + if (f != null) + return f.GetValue(source); + + var p = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); + if (p != null) + return p.GetValue(source, null); + + type = type.BaseType; + } + return null; + } + } +} diff --git a/Editor/Utilities/SerializedPropertiesUtils.cs.meta b/Editor/Utilities/SerializedPropertiesUtils.cs.meta new file mode 100644 index 0000000..6528141 --- /dev/null +++ b/Editor/Utilities/SerializedPropertiesUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5500cde56ec243e9ab23bb041b7089e6 +timeCreated: 1661186485 \ No newline at end of file From 191d442026fbc37fb86cc980bce68bfb5e8fb874 Mon Sep 17 00:00:00 2001 From: mnicolas94 Date: Fri, 9 Sep 2022 17:35:23 -0400 Subject: [PATCH 4/5] fix: make changes requested in code review. Also, fix stop condition in for loop that traverses serialized property's path in SerializedPropertyUtilities.GetValue() function --- Editor/Drawers/ReferenceDrawer.cs | 2 +- Editor/Utilities/SerializedPropertiesUtils.cs | 76 ------------------- .../SerializedPropertiesUtils.cs.meta | 3 - .../Utilities/SerializedPropertyUtilities.cs | 2 +- 4 files changed, 2 insertions(+), 81 deletions(-) delete mode 100644 Editor/Utilities/SerializedPropertiesUtils.cs delete mode 100644 Editor/Utilities/SerializedPropertiesUtils.cs.meta diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index c654886..c708c9e 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -222,7 +222,7 @@ protected object GetRawReferenceValue(SerializedProperty property) #if UNITY_2021_2_OR_NEWER return property.RawReferenceProperty().managedReferenceValue; #else - var target = (ISerializableInterface) SerializedPropertiesUtils.GetTargetObjectOfProperty(property); + ISerializableInterface target = (ISerializableInterface) SerializedPropertyUtilities.GetValue(property); return target.GetRawReference(); #endif } diff --git a/Editor/Utilities/SerializedPropertiesUtils.cs b/Editor/Utilities/SerializedPropertiesUtils.cs deleted file mode 100644 index 7d587fc..0000000 --- a/Editor/Utilities/SerializedPropertiesUtils.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Reflection; -using UnityEditor; - -namespace TNRD.Utilities -{ - public static class SerializedPropertiesUtils - { - /// - /// This code was taken from https://github.com/dbrizov/NaughtyAttributes - /// - public static object GetTargetObjectOfProperty(SerializedProperty prop) - { - if (prop == null) return null; - - var path = prop.propertyPath.Replace(".Array.data[", "["); - object obj = prop.serializedObject.targetObject; - var elements = path.Split('.'); - foreach (var element in elements) - { - if (element.Contains("[")) - { - var elementName = element.Substring(0, element.IndexOf("[")); - var index = Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[", "").Replace("]", "")); - obj = GetValue_Imp(obj, elementName, index); - } - else - { - obj = GetValue_Imp(obj, element); - } - } - return obj; - } - - - /// - /// This code was taken from https://github.com/dbrizov/NaughtyAttributes - /// - private static object GetValue_Imp(object source, string name, int index) - { - var enumerable = GetValue_Imp(source, name) as System.Collections.IEnumerable; - if (enumerable == null) return null; - var enm = enumerable.GetEnumerator(); - - for (int i = 0; i <= index; i++) - { - if (!enm.MoveNext()) return null; - } - return enm.Current; - } - - /// - /// This code was taken from https://github.com/dbrizov/NaughtyAttributes - /// - private static object GetValue_Imp(object source, string name) - { - if (source == null) - return null; - var type = source.GetType(); - - while (type != null) - { - var f = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - if (f != null) - return f.GetValue(source); - - var p = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); - if (p != null) - return p.GetValue(source, null); - - type = type.BaseType; - } - return null; - } - } -} diff --git a/Editor/Utilities/SerializedPropertiesUtils.cs.meta b/Editor/Utilities/SerializedPropertiesUtils.cs.meta deleted file mode 100644 index 6528141..0000000 --- a/Editor/Utilities/SerializedPropertiesUtils.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5500cde56ec243e9ab23bb041b7089e6 -timeCreated: 1661186485 \ No newline at end of file diff --git a/Editor/Utilities/SerializedPropertyUtilities.cs b/Editor/Utilities/SerializedPropertyUtilities.cs index aac3127..cabfef5 100644 --- a/Editor/Utilities/SerializedPropertyUtilities.cs +++ b/Editor/Utilities/SerializedPropertyUtilities.cs @@ -41,7 +41,7 @@ public static object GetValue(SerializedProperty property) object targetObject = property.serializedObject.targetObject; string[] elements = path.Split('.'); - for (int i = 0; i < elements.Length - 1; i++) + for (int i = 0; i < elements.Length; i++) { string element = elements[i]; if (element.Contains("[")) From a1cfb3c23842d015ed2532f36199ecd0117f9579 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 10 Sep 2022 09:24:45 +0000 Subject: [PATCH 5/5] chore(release): 1.12.1 [skip ci] ### [1.12.1](https://github.com/Thundernerd/Unity3D-SerializableInterface/compare/v1.12.0...v1.12.1) (2022-09-10) ### Bug Fixes * fix editor drawing of managed classes inside list ([8d66349](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/8d663496eef8eab34e5553617ad9697d3e61d8f1)) * fix issue with unity version 2021.1 ([d81e9df](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/d81e9df6fbc4fb0eb2ca70c7b3a46418045923aa)), closes [Thundernerd/Unity3D-SerializableInterface#51](https://github.com/Thundernerd/Unity3D-SerializableInterface/issues/51) * fix version directive in IconUtility ([ffe848c](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/ffe848c940898c22816268d8be2aa3d84721a678)), closes [Thundernerd/Unity3D-SerializableInterface#51](https://github.com/Thundernerd/Unity3D-SerializableInterface/issues/51) * make changes requested in code review. Also, fix stop condition in for loop that traverses serialized property's path in SerializedPropertyUtilities.GetValue() function ([191d442](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/191d442026fbc37fb86cc980bce68bfb5e8fb874)) --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d892a08..6533c43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +### [1.12.1](https://github.com/Thundernerd/Unity3D-SerializableInterface/compare/v1.12.0...v1.12.1) (2022-09-10) + + +### Bug Fixes + +* fix editor drawing of managed classes inside list ([8d66349](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/8d663496eef8eab34e5553617ad9697d3e61d8f1)) +* fix issue with unity version 2021.1 ([d81e9df](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/d81e9df6fbc4fb0eb2ca70c7b3a46418045923aa)), closes [Thundernerd/Unity3D-SerializableInterface#51](https://github.com/Thundernerd/Unity3D-SerializableInterface/issues/51) +* fix version directive in IconUtility ([ffe848c](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/ffe848c940898c22816268d8be2aa3d84721a678)), closes [Thundernerd/Unity3D-SerializableInterface#51](https://github.com/Thundernerd/Unity3D-SerializableInterface/issues/51) +* make changes requested in code review. Also, fix stop condition in for loop that traverses serialized property's path in SerializedPropertyUtilities.GetValue() function ([191d442](https://github.com/Thundernerd/Unity3D-SerializableInterface/commit/191d442026fbc37fb86cc980bce68bfb5e8fb874)) + ## [1.12.0](https://github.com/Thundernerd/Unity3D-SerializableInterface/compare/v1.11.1...v1.12.0) (2022-09-09) diff --git a/package.json b/package.json index f040261..55ec8f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "net.tnrd.serializableinterface", - "version": "1.12.0", + "version": "1.12.1", "displayName": "Serializable Interface", "unity": "2020.1", "description": "A wrapper that allows serialization of interfaces that supports both UnityEngine.Object and regular object types",