From a742f57f1adae04a779604d900ba43fa324cbc73 Mon Sep 17 00:00:00 2001 From: uurha Date: Fri, 23 Aug 2024 22:16:22 +0000 Subject: [PATCH] Merge pull request #47 from techno-dwarf-works/feature/refactoring Version 0.0.44 --- .../Extensions/SerializedPropertyExtensions.cs | 4 ++++ Editor/Utility/SerializedPropertyUtility.cs | 18 +++++++++++++++++- package.json | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Editor/Extensions/SerializedPropertyExtensions.cs b/Editor/Extensions/SerializedPropertyExtensions.cs index ee3f2ea..c3672e3 100644 --- a/Editor/Extensions/SerializedPropertyExtensions.cs +++ b/Editor/Extensions/SerializedPropertyExtensions.cs @@ -119,6 +119,10 @@ public static CachedFieldInfo GetFieldInfoAndStaticTypeFromProperty(this Seriali } fieldPath = self.propertyPath; + if (classType != null) + { + SerializedPropertyUtility.CleanCacheForProperty(classType, fieldPath); + } } if (classType == null) diff --git a/Editor/Utility/SerializedPropertyUtility.cs b/Editor/Utility/SerializedPropertyUtility.cs index e36ef74..77faba2 100644 --- a/Editor/Utility/SerializedPropertyUtility.cs +++ b/Editor/Utility/SerializedPropertyUtility.cs @@ -68,6 +68,14 @@ public static bool GetTypeFromManagedReferenceFullTypeName(string managedReferen return managedReferenceInstanceType != null; } + public static void CleanCacheForProperty(Type type, string propertyPath) + { + propertyPath = ArrayDataWithIndexRegex.Replace(propertyPath, ArrayElementDotName); + var cache = new CachePropertyKey(type, propertyPath); + + FieldInfoFromPropertyPathCache.Remove(cache); + } + public static CachedFieldInfo GetFieldInfoFromPropertyPath(Type type, string propertyPath) { var arrayElement = ArrayDataWithIndexRegexAny.IsMatch(propertyPath); @@ -118,9 +126,17 @@ private static bool FieldInfoFromPropertyPath(string propertyPath, ref Type type fieldInfo = foundField; type = fieldInfo.FieldType; - if (i >= parts.Length - 1 || parts[i + 1] != ArrayElementName || !type.IsArrayOrList()) continue; + if (i >= parts.Length - 1 || parts[i + 1] != ArrayElementName || !type.IsArrayOrList()) + { + continue; + } i++; type = type.GetCollectionElementType(); + + if (fieldInfo != null) + { + return false; + } } return false; diff --git a/package.json b/package.json index edf06bb..61c4e05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.commons", "displayName": "Better Commons", - "version": "0.0.43", + "version": "0.0.44", "unity": "2021.3", "description": " ", "dependencies": {