private void HandleDrag() { bool moving = CurrentEventData.IsPointerMoving(); bool shouldStartDrag = ShouldStartDrag(CurrentEventData.pressPosition, CurrentEventData.position, ModuleController.eventSystem.pixelDragThreshold, CurrentEventData.useDragThreshold); if (moving && shouldStartDrag && CurrentEventData.pointerDrag != null && !CurrentEventData.dragging) { EventExecutor.Execute(CurrentEventData.pointerDrag, CurrentEventData, ExecuteEvents.beginDragHandler); CurrentEventData.dragging = true; } // Drag notification if (CurrentEventData.dragging && moving && CurrentEventData.pointerDrag != null) { // Before doing drag we should cancel any pointer down state // And clear selection! if (CurrentEventData.pointerPress != CurrentEventData.pointerDrag) { EventExecutor.Execute(CurrentEventData.pointerPress, CurrentEventData, ExecuteEvents.pointerUpHandler); CurrentEventData.eligibleForClick = false; CurrentEventData.pointerPress = null; CurrentEventData.rawPointerPress = null; } EventExecutor.Execute(CurrentEventData.pointerDrag, CurrentEventData, ExecuteEvents.dragHandler); } }
private void CastRay() { Vector2 currentPose = lastPose; if (IsPointerActiveAndAvailable()) { currentPose = GvrMathHelpers.NormalizedCartesianToSpherical(Pointer.PointerTransform.forward); } if (CurrentEventData == null) { CurrentEventData = new PointerEventData(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 = GvrMathHelpers.GetViewportCenter(); bool isPointerActiveAndAvailable = IsPointerActiveAndAvailable(); if (isPointerActiveAndAvailable) { RaycastAll(); raycastResult = ModuleController.FindFirstRaycast(ModuleController.RaycastResultCache); } 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."); } }