private void CastPointer()
    {
        RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward);
        if (hits.Length < 1)
        {
            DisplayPointerLine();
            Vector3 tempPointPos = Vector3.zero;
            DisplayPoint(false, tempPointPos);

            if (lastPointedElement == null)
            {
                return;
            }
            lastPointedElement.OnPointerLeft();
            lastPointedElement = null;
            return;
        }
        RaycastHit nearestHit = FindNearestHit(hits);

        DisplayPointerLine(nearestHit.distance);
        DisplayPoint(true, nearestHit.point);

        IPointableUIElement pointableElement = FindPointables(hits);

        // call feedbacks when the pointer left a interactable UI element
        if (pointableElement == null)
        {
            if (lastPointedElement == null)
            {
                return;
            }
            lastPointedElement.OnPointerLeft();
            lastPointedElement = pointableElement;
            return;
        }

        // call feedbacks when the pointer hits a interactable UI element
        if (pointableElement != lastPointedElement)
        {
            pointableElement.OnPointed();
            lastPointedElement = pointableElement;
        }

        var trackedObject = GetComponent <SteamVR_TrackedObject>();
        var device        = SteamVR_Controller.Input((int)trackedObject.index);

        bool isClicked = device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger);

        if (!isClicked)
        {
            return;
        }
        device.TriggerHapticPulse(500);
        pointableElement.OnClicked();
    }
    private IPointableUIElement FindPointables(RaycastHit[] hits)
    {
        for (int i = 0; i < hits.Length; i++)
        {
            IPointableUIElement pointable = hits[i].collider.GetComponent <IPointableUIElement>();
            if (pointable != null)
            {
                return(pointable);
            }
        }

        return(null);
    }
    private void CastPointer()
    {
        RaycastHit[] hits = Physics.RaycastAll(transform.position, transform.forward);
        if (hits.Length < 1)
        {
            DisplayPointerLine();
            Vector3 tempPointPos = Vector3.zero;
            DisplayPoint(false, tempPointPos);

            if (lastPointedElement == null)
            {
                return;
            }
            lastPointedElement.OnPointerLeft();
            lastPointedElement = null;
            return;
        }
        RaycastHit nearestHit = FindNearestHit(hits);

        DisplayPointerLine(nearestHit.distance);
        DisplayPoint(true, nearestHit.point);

        IPointableUIElement pointableElement = FindPointables(hits);

        // call feedbacks when the pointer left a interactable UI element
        if (pointableElement == null)
        {
            if (lastPointedElement == null)
            {
                return;
            }
            lastPointedElement.OnPointerLeft();
            lastPointedElement = pointableElement;
            return;
        }

        // call feedbacks when the pointer hits a interactable UI element
        if (pointableElement != lastPointedElement)
        {
            pointableElement.OnPointed();
            lastPointedElement = pointableElement;
        }

        bool isClicked = OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger);

        if (isClicked)
        {
            SetGrabbableObjectParam(nearestHit.collider.gameObject);
            pointableElement.OnClicked();
        }

        bool isHeld = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger);

        if (isHeld)
        {
            //SetObjectDistFromController(nearestHit.collider.gameObject);
        }

        bool isReleased = OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger);

        if (isReleased)
        {
            pointableElement.OnReleased();
            lastTouchPoint = Vector2.zero;
        }
    }