RectBoneSelector.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class RectBoneSelector : IRectSelector<BoneCache>
  6. {
  7. public ISelection<BoneCache> selection { get; set; }
  8. public BoneCache[] bones { get; set; }
  9. public Rect rect { get; set; }
  10. public void Select()
  11. {
  12. if (bones == null)
  13. return;
  14. foreach (var bone in bones)
  15. {
  16. if (!bone.isVisible)
  17. continue;
  18. Vector2 p1 = bone.position;
  19. Vector2 p2 = bone.endPosition;
  20. Vector2 point = Vector2.zero;
  21. if (rect.Contains(p1, true) || rect.Contains(p2, true) ||
  22. MathUtility.SegmentIntersection(new Vector2(rect.xMin, rect.yMin), new Vector2(rect.xMax, rect.yMin), p1, p2, ref point) ||
  23. MathUtility.SegmentIntersection(new Vector2(rect.xMax, rect.yMin), new Vector2(rect.xMax, rect.yMax), p1, p2, ref point) ||
  24. MathUtility.SegmentIntersection(new Vector2(rect.xMax, rect.yMax), new Vector2(rect.xMin, rect.yMax), p1, p2, ref point) ||
  25. MathUtility.SegmentIntersection(new Vector2(rect.xMin, rect.yMax), new Vector2(rect.xMin, rect.yMin), p1, p2, ref point)
  26. )
  27. selection.Select(bone.ToCharacterIfNeeded(), true);
  28. }
  29. }
  30. }
  31. }