UnityEssentials
Small but useful tools and features for Unity
SerializedPropertyExtensions.cs
Go to the documentation of this file.
1 #if UNITY_EDITOR
2 using System.Collections.Generic;
3 using UnityEditor;
4 
5 namespace UnityEngine
6 {
11  public static class SerializedPropertyExtensions
12  {
18  public static IEnumerable<SerializedProperty> GetChildren(this SerializedProperty serializedProperty)
19  {
20  SerializedProperty currentProperty = serializedProperty.Copy();
21  SerializedProperty nextSiblingProperty = serializedProperty.Copy();
22  {
23  nextSiblingProperty.Next(false);
24  }
25 
26  if (currentProperty.Next(true))
27  {
28  do
29  {
30  if (SerializedProperty.EqualContents(currentProperty, nextSiblingProperty))
31  break;
32 
33  yield return currentProperty;
34  }
35  while (currentProperty.Next(false));
36  }
37  }
38 
44  public static IEnumerable<SerializedProperty> GetVisibleChildren(this SerializedProperty serializedProperty)
45  {
46  SerializedProperty currentProperty = serializedProperty.Copy();
47  SerializedProperty nextSiblingProperty = serializedProperty.Copy();
48  {
49  nextSiblingProperty.NextVisible(false);
50  }
51 
52  if (currentProperty.NextVisible(true))
53  {
54  do
55  {
56  if (SerializedProperty.EqualContents(currentProperty, nextSiblingProperty))
57  break;
58 
59  yield return currentProperty;
60  }
61  while (currentProperty.NextVisible(false));
62  }
63  }
64  }
65 }
66 #endif