No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TransformCacheExtensions.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Linq;
  2. namespace UnityEditor.U2D.Animation
  3. {
  4. internal static class TransformCacheExtensions
  5. {
  6. internal static bool IsDescendant<T>(this T transform, T ancestor) where T : TransformCache
  7. {
  8. if (ancestor != null)
  9. {
  10. var parent = transform.parent;
  11. while (parent != null)
  12. {
  13. if (parent == ancestor)
  14. return true;
  15. parent = parent.parent;
  16. }
  17. }
  18. return false;
  19. }
  20. static bool IsDescendant<T>(this T transform, T[] ancestors) where T : TransformCache
  21. {
  22. return ancestors.FirstOrDefault( t => transform.IsDescendant<T>(t) ) != null;
  23. }
  24. internal static T[] FindRoots<T>(this T[] transforms) where T : TransformCache
  25. {
  26. return transforms.Where(t => t.IsDescendant(transforms) == false).ToArray();
  27. }
  28. internal static T FindRoot<T>(this T transform, T[] transforms) where T : TransformCache
  29. {
  30. var roots = transforms.FindRoots<T>();
  31. return roots.FirstOrDefault( r => transform == r || IsDescendant<T>(transform, r) );
  32. }
  33. }
  34. }