Skip to content

Commit 7c75931

Browse files
Bruno MikoskiBruno Mikoski
authored andcommitted
2 parents cd309f3 + c977ab9 commit 7c75931

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using BrunoMikoski.ScriptableObjectCollections.Utils;
2+
using UnityEditor;
3+
4+
namespace BrunoMikoski.ScriptableObjectCollections
5+
{
6+
public static class SerializedObjectExtensions
7+
{
8+
public static bool TryFindProperty(this SerializedObject serializedObject, string propertyName, out SerializedProperty property, bool tryBackingFieldIfFails = true)
9+
{
10+
property = serializedObject.FindProperty(propertyName);
11+
if (property == null && tryBackingFieldIfFails)
12+
{
13+
property = serializedObject.FindProperty(propertyName.AsBackingField());
14+
}
15+
16+
return property != null;
17+
}
18+
}
19+
}

Scripts/Editor/Extensions/SerializedObjectExtensions.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scripts/Editor/Extensions/SerializedPropertyExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace BrunoMikoski.ScriptableObjectCollections
1111
{
12-
1312
public static class SerializedPropertyExtensions
1413
{
1514
public static FieldInfo GetFieldInfoFromPathByType(this SerializedProperty property, Type parentType)
@@ -303,4 +302,4 @@ static T DescendHierarchy<T>(object targetObject, List<string> splitName, List<i
303302
return DescendHierarchy<T>(newObj, splitName, splitCounts, depth + 1);
304303
}
305304
}
306-
}
305+
}

Scripts/Editor/Generators/CollectionGenerators.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Reflection;
6+
using BrunoMikoski.ScriptableObjectCollections.Utils;
67
using UnityEditor;
78
using UnityEngine;
89
using Object = UnityEngine.Object;
@@ -201,6 +202,9 @@ private static void RunGeneratorInternal(
201202

202203
if (generateStaticAccess)
203204
CodeGenerationUtility.GenerateStaticCollectionScript(collection);
205+
206+
EditorUtility.SetDirty(collection);
207+
ActiveEditorTracker.sharedTracker.ForceRebuild();
204208
}
205209

206210
private static bool TryGetItemTemplateType(ItemTemplate itemTemplate, out Type resultType)
@@ -264,8 +268,7 @@ private static void CopyFieldToSerializedProperty(
264268
return;
265269

266270
// Get the property to copy the value to.
267-
SerializedProperty serializedProperty = serializedObject.FindProperty(field.Name);
268-
if (serializedProperty == null)
271+
if(!serializedObject.TryFindProperty(field.Name, out SerializedProperty serializedProperty))
269272
return;
270273

271274
object value = field.GetValue(owner);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace BrunoMikoski.ScriptableObjectCollections.Utils
2+
{
3+
public static class StringExtensions
4+
{
5+
public static string AsBackingField(this string value)
6+
{
7+
return $"<{value}>k__BackingField";
8+
}
9+
}
10+
}

Scripts/Editor/Utils/StringExtensions.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)