Skip to content

Commit f656cd0

Browse files
committed
Add GetChildProperties
1 parent f69bfc6 commit f656cd0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/ManagedReferenceUtility.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
#if UNITY_2019_3_OR_NEWER
22
using System;
3+
using System.Collections.Generic;
34
using System.Reflection;
45
using UnityEditor;
56
using UnityEngine;
67

78
namespace MackySoft.SerializeReferenceExtensions.Editor {
89
public static class ManagedReferenceUtility {
910

11+
public static IEnumerable<SerializedProperty> GetChildProperties (this SerializedProperty parent, int depth = 1)
12+
{
13+
parent = parent.Copy();
14+
15+
int depthOfParent = parent.depth;
16+
var enumerator = parent.GetEnumerator();
17+
18+
while (enumerator.MoveNext())
19+
{
20+
if (enumerator.Current is not SerializedProperty childProperty)
21+
{
22+
continue;
23+
}
24+
if (childProperty.depth > (depthOfParent + depth))
25+
{
26+
continue;
27+
}
28+
yield return childProperty.Copy();
29+
}
30+
}
31+
1032
public static object SetManagedReference (this SerializedProperty property,Type type) {
1133
object result = null;
1234

0 commit comments

Comments
 (0)