Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmaskRaycastFilter is not reliable #14

Closed
rozx opened this issue Feb 6, 2019 · 1 comment
Closed

UnmaskRaycastFilter is not reliable #14

rozx opened this issue Feb 6, 2019 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rozx
Copy link

rozx commented Feb 6, 2019

UnmaskRaycastFilter is not reliable?

So for our project, since our camera is using perspective projection, the funciton

camera.WorldToScreenPoint() is not reliable when converting from world position to screen point, therefore the UnmaskRaycastFilter's function IsRaycastLocationValid() is always returning false no matter what.

However I have found a solution for this: instead of using camera.WorldToScreenPoint(), unity has a build in function RectTransformUtility.RectangleContainsScreenPoint() to check whether a screen point is inside the rect transform. So maybe this is better? At least it worked for me 😄

Here is the modified version of IsRaycastLocationValid() function:

public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
  // Skip if deactived.
  if (!isActiveAndEnabled || !m_TargetUnmask || !m_TargetUnmask.isActiveAndEnabled){
   return true;
  }
    // check inside
  return !RectTransformUtility.RectangleContainsScreenPoint((m_TargetUnmask.transform as RectTransform), sp);
}
@mob-sakai mob-sakai self-assigned this Feb 6, 2019
@mob-sakai
Copy link
Owner

Hi @rozx
Thunk you for your reporting.

Yes, we should use RectTransformUtility.RectangleContainsScreenPoint.

@mob-sakai mob-sakai added the bug Something isn't working label Feb 6, 2019
@mob-sakai mob-sakai changed the title UnmaskRaycastFilter is not reliable? UnmaskRaycastFilter is not reliable Feb 7, 2019
@mob-sakai mob-sakai added this to the v1.1.1 milestone Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants