ShapeHitTest.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. namespace FairyGUI
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public class ShapeHitTest : IHitTest
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. public DisplayObject shape;
  13. public ShapeHitTest(DisplayObject obj)
  14. {
  15. shape = obj;
  16. }
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. /// <param name="contentRect"></param>
  21. /// <param name="localPoint"></param>
  22. /// <returns></returns>
  23. public bool HitTest(Rect contentRect, Vector2 localPoint)
  24. {
  25. if (shape.graphics == null)
  26. return false;
  27. if (shape.parent != null)
  28. {
  29. localPoint = shape.parent.TransformPoint(localPoint, shape);
  30. contentRect.size = shape.size;
  31. }
  32. IHitTest ht = shape.graphics.meshFactory as IHitTest;
  33. if (ht == null)
  34. return false;
  35. return ht.HitTest(contentRect, localPoint);
  36. }
  37. }
  38. }