Ejemplo n.º 1
0
    /// Returns the `GvrControllerButton` mask of buttons that went down to trigger the event.
    public static GvrControllerButton GvrGetButtonsDown(this PointerEventData pointerEventData)
    {
        GvrPointerEventData gped = pointerEventData as GvrPointerEventData;

        if (gped == null)
        {
            return(0);
        }
        return(gped.gvrButtonsDown);
    }
Ejemplo n.º 2
0
    private void CastRay()
    {
        Vector2 currentPose = lastPose;

        if (IsPointerActiveAndAvailable())
        {
            currentPose = GvrMathHelpers.NormalizedCartesianToSpherical(
                Pointer.PointerTransform.forward);
        }

        if (CurrentEventData == null)
        {
            CurrentEventData = new GvrPointerEventData(ModuleController.eventSystem);
            lastPose         = currentPose;
        }

        // Store the previous raycast result.
        RaycastResult previousRaycastResult = CurrentEventData.pointerCurrentRaycast;

        // The initial cast must use the enter radius.
        if (IsPointerActiveAndAvailable())
        {
            Pointer.ShouldUseExitRadiusForRaycast = false;
        }

        // Cast a ray into the scene
        CurrentEventData.Reset();

        // Set the position to the center of the camera.
        // This is only necessary if using the built-in Unity raycasters.
        RaycastResult raycastResult;

        CurrentEventData.position = GvrVRHelpers.GetViewportCenter();
        bool isPointerActiveAndAvailable = IsPointerActiveAndAvailable();

        if (isPointerActiveAndAvailable)
        {
            RaycastAll();
            raycastResult = ModuleController.FindFirstRaycast(ModuleController.RaycastResultCache);
            if (Pointer.ControllerInputDevice == null ||
                Pointer.ControllerInputDevice.IsDominantHand)
            {
                CurrentEventData.pointerId = (int)GvrControllerHand.Dominant;
            }
            else
            {
                CurrentEventData.pointerId = (int)GvrControllerHand.NonDominant;
            }
        }
        else
        {
            raycastResult = new RaycastResult();
            raycastResult.Clear();
        }

        // If we were already pointing at an object we must check that object against the exit
        // radius to make sure we are no longer pointing at it to prevent flicker.
        if (previousRaycastResult.gameObject != null &&
            raycastResult.gameObject != previousRaycastResult.gameObject &&
            isPointerActiveAndAvailable)
        {
            Pointer.ShouldUseExitRadiusForRaycast = true;
            RaycastAll();
            RaycastResult firstResult = ModuleController.FindFirstRaycast(
                ModuleController.RaycastResultCache);
            if (firstResult.gameObject == previousRaycastResult.gameObject)
            {
                raycastResult = firstResult;
            }
        }

        if (raycastResult.gameObject != null && raycastResult.worldPosition == Vector3.zero)
        {
            raycastResult.worldPosition = GvrMathHelpers.GetIntersectionPosition(
                CurrentEventData.enterEventCamera, raycastResult);
        }

        CurrentEventData.pointerCurrentRaycast = raycastResult;

        // Find the real screen position associated with the raycast
        // Based on the results of the hit and the state of the pointerData.
        if (raycastResult.gameObject != null)
        {
            CurrentEventData.position = raycastResult.screenPosition;
        }
        else if (IsPointerActiveAndAvailable() && CurrentEventData.enterEventCamera != null)
        {
            Vector3 pointerPos = Pointer.MaxPointerEndPoint;
            CurrentEventData.position =
                CurrentEventData.enterEventCamera.WorldToScreenPoint(pointerPos);
        }

        ModuleController.RaycastResultCache.Clear();
        CurrentEventData.delta = currentPose - lastPose;
        lastPose = currentPose;

        // Check to make sure the Raycaster being used is a GvrRaycaster.
        if (raycastResult.module != null &&
            !(raycastResult.module is GvrPointerGraphicRaycaster) &&
            !(raycastResult.module is GvrPointerPhysicsRaycaster))
        {
            //Debug.LogWarning("Using Raycaster (Raycaster: " + raycastResult.module.GetType() +
            //", Object: " + raycastResult.module.name + "). It is recommended to use " +
            //"GvrPointerPhysicsRaycaster or GvrPointerGrahpicRaycaster with GvrPointerInputModule.");
        }
    }