Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. [RequireComponent (typeof (RectTransform), typeof (Collider2D))]
  5. public class Collider2DRaycastFilter : MonoBehaviour, ICanvasRaycastFilter
  6. {
  7. Collider2D myCollider;
  8. RectTransform rectTransform;
  9.  
  10. void Awake ()
  11. {
  12. myCollider = GetComponent<Collider2D>();
  13. rectTransform = GetComponent<RectTransform>();
  14. }
  15.  
  16. #region ICanvasRaycastFilter implementation
  17. public bool IsRaycastLocationValid (Vector2 screenPos, Camera eventCamera)
  18. {
  19. var worldPoint = Vector3.zero;
  20. var isInside = RectTransformUtility.ScreenPointToWorldPointInRectangle(
  21. rectTransform,
  22. screenPos,
  23. eventCamera,
  24. out worldPoint
  25. );
  26. if (isInside)
  27. isInside = myCollider.OverlapPoint(worldPoint);
  28. return isInside;
  29. }
  30. #endregion
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement