TransformExtensions.cs 900 B

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. namespace UnityEditor.U2D.Animation
  3. {
  4. internal static class TransformExtensions
  5. {
  6. public static Vector3 GetScaledRight(this Transform transform)
  7. {
  8. return transform.localToWorldMatrix.MultiplyVector(Vector3.right);
  9. }
  10. public static Vector3 GetScaledUp(this Transform transform)
  11. {
  12. return transform.localToWorldMatrix.MultiplyVector(Vector3.up);
  13. }
  14. public static bool IsDescendentOf(this Transform transform, Transform ancestor)
  15. {
  16. if (ancestor != null)
  17. {
  18. var parent = transform.parent;
  19. while (parent != null)
  20. {
  21. if (parent == ancestor)
  22. return true;
  23. parent = parent.parent;
  24. }
  25. }
  26. return false;
  27. }
  28. }
  29. }