DayDream, detect pointer without using Event System

676 views Asked by At

Google's new DayDream samples are using the Event System to detect if the pointer is on an object. Previously it wasn't working like that at all, it was a reticle, and you would then create a Raycast between the Camera and the reticle, such as:

Vector3 rayDirection = GvrController.Orientation * Vector3.forward;
if (Physics.Raycast(origin, rayDirection, out hitInfo, Mathf.Infinity)) {

And then you detect if a specific Object is between the reticle and the Camera.

This way doesn't exactly work anymore. Google is now using the event system, and then checking if the reticle is positioned on an object. Is there a way for me to check that for any object without using the Event System.

The Event System is a good method, it's just I have about 40 different objects that all work the same way, and implementing an event point/click for these 40 different objects seems like an overkill when previously I could just check an object by tag.

Anyone was able by any chance to be able to detect if the pointer is positioned on an object without using the Event system? Raycasts don't seem to properly work anymore as the pointer seems to be more of a 2D object, just like a Mouse.

This works approximately, but not very well:

Vector3 origin = Head.transform.position + GvrController.ArmModel.wristPosition;
Vector3 rayDirection = GvrController.ArmModel.pointerRotation * Vector3.forward;

Any help would be appreciated :)

1

There are 1 answers

1
Umair M On BEST ANSWER

If you don't want to use EventTrigger component, you can simply use your same old script and implement IPointerEnterHandler, IPointerExitHandler, OnPointerClickHandler etc and use same compare tag method for every object.

I think its much more easy to use than custom raycast. As there is always a Graphics Raycaster (or Physics Raycaster for 3D Objects) at work so why not use what it has to offer.

public class MyOldScriptWhichUsedRaycasting: MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
    public void OnPointerEnter (PointerEventData eventData) 
    {
        if(gameObject.CompareTag("Grabable"))
        {
            //do stuff here. 
        }
    }
    public void OnPointerExit (PointerEventData eventData) 
    {
        if(gameObject.CompareTag("Grabable"))
        {
            //do stuff here. 
        }
    }
    public void OnPointerClick (PointerEventData eventData) 
    {
        if(gameObject.CompareTag("Grabable"))
        {
            //do stuff here. 
        }
    }
}

Hope this helps