/// <summary> /// Stops dragging the object. /// </summary> public void StopDragging() { if (IsBeingPlaced == IsBeingPlacedStates.No) { return; } // Remove self as a modal input handler InputManager.Instance.PopModalInputHandler(); IsBeingPlaced = IsBeingPlacedStates.No; currentInputSource = null; StoppedDragging.RaiseEvent(); if (spatialMappingManager != null) { spatialMappingManager.DrawVisualMeshes = false; } if (EnablePersistenceInWorldAnchor) { // Add world anchor when object placement is done. anchorManager.AttachAnchor(gameObject, SavedAnchorFriendlyName); } }
public void OnSourceLost(SourceStateEventData eventData) { // event not used in TapToPlace if (DraggingMethod == DraggingMethods.TapToPlaceWithGaze) { return; } if (currentInputSource != null && eventData.SourceId == currentInputSourceId) { if (IsBeingPlaced == IsBeingPlacedStates.ByHand) { // if hand is lost, replace by gaze if (DraggingMethod == DraggingMethods.TapToPlaceWithGazePlusPreciseHandDrag) { IsBeingPlaced = IsBeingPlacedStates.ByGaze; } else { StopDragging(); } } } }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging(IsBeingPlacedStates isBeingPlacedBy) { if (!IsDraggingEnabled) { return; } // if already dragging with the same method if (IsBeingPlaced == isBeingPlacedBy) { return; } // if start dragging if (IsBeingPlaced == IsBeingPlacedStates.No) { // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); } IsBeingPlaced = isBeingPlacedBy; Vector3 handPosition; if (DraggingMethod != DraggingMethods.TapToPlaceWithGaze && currentInputSource != null && currentInputSource.TryGetPosition(currentInputSourceId, out handPosition)) { Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - handPivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - handPivotPosition); Vector3 objForward = ObjectToPlace.transform.forward; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(ObjectToPlace.transform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - handPivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - handPivotPosition); objForward = mainCamera.transform.InverseTransformDirection(objForward); // in camera space objDirection = mainCamera.transform.InverseTransformDirection(objDirection); // in camera space handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; // Store the initial offset between the hand and the object, so that we can consider it when dragging gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); draggingPosition = gazeHitPosition; } StartedDragging.RaiseEvent(); if (Placement == PlacementOptions.ForceSpatialMapping) { if (spatialMappingManager != null) { spatialMappingManager.DrawVisualMeshes = DrawVisualMeshes; } } if (EnablePersistenceInWorldAnchor) { Debug.Log(gameObject.name + " : Removing existing world anchor if any."); anchorManager.RemoveAnchor(gameObject); } }