Extensions.cs 640 B

12345678910111213141516171819202122232425
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEditor;
  4. namespace Chronos.Controls.Editor
  5. {
  6. public static class Extensions
  7. {
  8. /// <summary>
  9. /// Splits a given property into each of its multiple values.
  10. /// If it has a single value, only the same property is returned.
  11. /// </summary>
  12. public static IEnumerable<SerializedProperty> Multiple(this SerializedProperty property)
  13. {
  14. if (property.hasMultipleDifferentValues)
  15. {
  16. return property.serializedObject.targetObjects.Select(o => new SerializedObject(o).FindProperty(property.propertyPath));
  17. }
  18. else
  19. {
  20. return new[] { property };
  21. }
  22. }
  23. }
  24. }