Skip to content

Commit

Permalink
Merge pull request #47 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.44
  • Loading branch information
uurha committed Aug 23, 2024
1 parent 8fa9f8b commit a742f57
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Editor/Extensions/SerializedPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public static CachedFieldInfo GetFieldInfoAndStaticTypeFromProperty(this Seriali
}

fieldPath = self.propertyPath;
if (classType != null)
{
SerializedPropertyUtility.CleanCacheForProperty(classType, fieldPath);
}
}

if (classType == null)
Expand Down
18 changes: 17 additions & 1 deletion Editor/Utility/SerializedPropertyUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit a742f57

Please sign in to comment.