TransformUtils.cs 972 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using UnityEngine;
  3. namespace ExtensionMethods
  4. {
  5. public static class TransformUtils
  6. {
  7. public static Transform[] GetChildren(this Transform transform)
  8. {
  9. Transform[] array = new Transform[transform.childCount];
  10. for (int i = 0; i < transform.childCount; i++)
  11. {
  12. Transform child = transform.GetChild(i);
  13. array[i] = child;
  14. }
  15. return array;
  16. }
  17. public static bool IsBiologicalChildOf(this Transform transform, GameObject parent)
  18. {
  19. return transform.parent == parent.transform;
  20. }
  21. public static bool IsBiologicalChildOf(this Transform transform, Transform parent)
  22. {
  23. return transform.parent == parent;
  24. }
  25. public static bool IsBiologicalParentOf(this Transform transform, GameObject child)
  26. {
  27. return transform == child.transform.parent;
  28. }
  29. public static bool IsBiologicalParentOf(this Transform transform, Transform child)
  30. {
  31. return transform == child.parent;
  32. }
  33. }
  34. }