Add GetChildProperties

This commit is contained in:
Makihiro 2024-02-18 02:38:00 +09:00
parent f69bfc6773
commit f656cd0f12

View File

@ -1,5 +1,6 @@
#if UNITY_2019_3_OR_NEWER #if UNITY_2019_3_OR_NEWER
using System; using System;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -7,6 +8,27 @@ using UnityEngine;
namespace MackySoft.SerializeReferenceExtensions.Editor { namespace MackySoft.SerializeReferenceExtensions.Editor {
public static class ManagedReferenceUtility { public static class ManagedReferenceUtility {
public static IEnumerable<SerializedProperty> GetChildProperties (this SerializedProperty parent, int depth = 1)
{
parent = parent.Copy();
int depthOfParent = parent.depth;
var enumerator = parent.GetEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Current is not SerializedProperty childProperty)
{
continue;
}
if (childProperty.depth > (depthOfParent + depth))
{
continue;
}
yield return childProperty.Copy();
}
}
public static object SetManagedReference (this SerializedProperty property,Type type) { public static object SetManagedReference (this SerializedProperty property,Type type) {
object result = null; object result = null;