/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (isDragging) { return; } // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; //GazeCursor.Instance.SetState(GazeCursor.State.Move); //GazeCursor.Instance.SetTargetObject(HostTransform); // Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; currentInputSource.TryGetPosition(currentInputSourceId, out startHandPosition); handPosition = startHandPosition; // Spawn Pokeball pokeballInstance = Instantiate(throwObjectPrefab, startHandPosition, Camera.main.transform.rotation); pokeballInstance.GetComponent <Collider>().enabled = false; aiming = true; //draggingPosition = gazeHitPosition; StartedDragging.RaiseEvent(); }
void HandleTouchStart() { if (itemIndex < ItemsSource.Count) { StartedDragging?.Invoke(this, new DraggingEventArgs(ItemsSource[itemIndex])); } }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; //GazeCursor.Instance.SetState(GazeCursor.State.Move); //GazeCursor.Instance.SetTargetObject(HostTransform); Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); //Debug.Log("Hand Position " + handPosition); Vector3 pivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objForward = mainCamera.transform.InverseTransformDirection(objForward); // in camera space objUp = mainCamera.transform.InverseTransformDirection(objUp); // in camera space objDirection = mainCamera.transform.InverseTransformDirection(objDirection); // in camera space handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // 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(); //hide some objects while dragging for (int i = 0; i < objectsToHide.Length; i++) { objectsToHide[i].SetActive(false); //or renderer instead? } }
/// <summary> /// Starts dragging the object. /// </summary> private void StartDragging() { if (isDragging) { return; } StopPlacingWithGaze(); isDragging = true; Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objDirection = Camera.main.transform.InverseTransformDirection(objDirection); handDirection = Camera.main.transform.InverseTransformDirection(handDirection); // Store the initial offset between the hand and the object, so that we can consider it when dragging. gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); StartedDragging.RaiseEvent(); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } if (!gameObject.GetComponent <Rigidbody>()) { gameObject.AddComponent <Rigidbody>(); gameObject.GetComponent <Rigidbody>().mass = 0.5f; } gameObject.GetComponent <Rigidbody>().useGravity = false; // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; //GazeCursor.Instance.SetState(GazeCursor.State.Move); //GazeCursor.Instance.SetTargetObject(HostTransform); Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objForward = mainCamera.transform.InverseTransformDirection(objForward); // in camera space objUp = mainCamera.transform.InverseTransformDirection(objUp); // in camera space objDirection = mainCamera.transform.InverseTransformDirection(objDirection); // in camera space handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // 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(); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); HueSlider = GetTemplateChild("HueSlider") as ColorPickerSlider; HueSlider.ValueChanged += delegate(object sender, RoutedPropertyChangedEventArgs <double> e) { SaveToConfig(); }; HueSlider.StartedDragging += delegate() { StartedDragging?.Invoke(); }; HueSlider.StoppedDragging += delegate() { StoppedDragging?.Invoke(); }; DoubleCollection ticks = new DoubleCollection(); // Add a tick at the minimum value, which is a negative value. This is the // tick for white. ticks.Add(HueSlider.Minimum); // Add a tick for 0-359. Don't add 360, since that's the same as 0. for (int i = 0; i < 360; ++i) { ticks.Add(i); } HueSlider.Ticks = ticks; OnConfigChange onConfigChange; onConfigChange = new OnConfigChange(this, delegate(LoadFromConfigDelegateArgs args) { int pad = SelectedPanel < 9? 0:1; LoadUIFromConfig(args.controller[pad].config); }); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingAndScalingEnabled) { return; } if (isDragging) { return; } //extract the only input source IInputSource currentInputSource = currentInputSources.Values.ToArray()[0]; uint currentInputSourceId = handsPositions.Keys.ToArray()[0]; // Add self as a modal input handler, to get all inputs during the manipulation //InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; //GazeCursor.Instance.SetState(GazeCursor.State.Move); //GazeCursor.Instance.SetTargetObject(HostTransform); Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objForward = mainCamera.transform.InverseTransformDirection(objForward); // in camera space objUp = mainCamera.transform.InverseTransformDirection(objUp); // in camera space objDirection = mainCamera.transform.InverseTransformDirection(objDirection); // in camera space handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // 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; handsPositions[currentInputSourceId] = gazeHitPosition; StartedDragging.RaiseEvent(); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objForward = mainCamera.transform.InverseTransformDirection(objForward); // in camera space objUp = mainCamera.transform.InverseTransformDirection(objUp); // in camera space objDirection = mainCamera.transform.InverseTransformDirection(objDirection); // in camera space handDirection = mainCamera.transform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // 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; if (popupMenu) { popupMenu.parent = transform; popupMenu.gameObject.SetActive(false); } StartedDragging.RaiseEvent(); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging(Vector3 initialDraggingPosition) { this.GetComponentInParent <Rigidbody>().useGravity = false; if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // TODO: robertes: Fix push/pop and single-handler model so that multiple HandDraggable components // can be active at once. // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; Transform cameraTransform = CameraCache.Main.transform; Vector3 handPosition; currentInputSource.TryGetPointerPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(cameraTransform); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(initialDraggingPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = cameraTransform.transform.InverseTransformDirection(HostTransform.position - initialDraggingPosition); Vector3 objDirection = Vector3.Normalize(initialDraggingPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); objForward = cameraTransform.InverseTransformDirection(objForward); // in camera space objUp = cameraTransform.InverseTransformDirection(objUp); // in camera space objDirection = cameraTransform.InverseTransformDirection(objDirection); // in camera space handDirection = cameraTransform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // Store the initial offset between the hand and the object, so that we can consider it when dragging gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); draggingPosition = initialDraggingPosition; StartedDragging.RaiseEvent(); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { Debug.Log("Still Dragging " + this.name); return; } // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; Debug.Log("Starting Dragging " + this.name); GameObject.Find("StageCollection").SendMessage("UpdateDragging", this.name); //GazeCursor.Instance.SetState(GazeCursor.State.Move); //GazeCursor.Instance.SetTargetObject(HostTransform); Vector3 gazeHitPosition = GazeManager.Instance.HitInfo.point; Vector3 handPosition; currentInputSource.TryGetPosition(currentInputSourceId, out handPosition); Vector3 pivotPosition = GetHandPivotPosition(); handRefDistance = Vector3.Magnitude(handPosition - pivotPosition); objRefDistance = Vector3.Magnitude(gazeHitPosition - pivotPosition); Vector3 objForward = HostTransform.forward; // Store where the object was grabbed from objRefGrabPoint = mainCamera.transform.InverseTransformDirection(HostTransform.position - gazeHitPosition); Vector3 objDirection = Vector3.Normalize(gazeHitPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(handPosition - pivotPosition); 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(); }
//Called when dragging starts //Save initial hand position public void StartDragging(Vector3 initialDraggingPosition) { if (!isEnabled || !allowDragging || isDragging) { return; } // TODO: robertes: Fix push/pop and single-handler model so that multiple HandDraggable components // can be active at once. // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; if (hostRigidbody != null) { hostRigidbodyWasKinematic = hostRigidbody.isKinematic; hostRigidbody.isKinematic = true; } Vector3 inputPosition = Vector3.zero; #if UNITY_2017_2_OR_NEWER InteractionSourceInfo sourceKind; currentInputSource.TryGetSourceKind(currentInputSourceId, out sourceKind); switch (sourceKind) { case InteractionSourceInfo.Hand: currentInputSource.TryGetGripPosition(currentInputSourceId, out inputPosition); break; case InteractionSourceInfo.Controller: currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); break; } #else currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); #endif Debug.Log("Hand reference position " + inputPosition.ToString()); draggingPosition = initialDraggingPosition; handDraggingPosition = inputPosition; StartedDragging.RaiseEvent(); }
public void StartDragging() { if (!gizmoSetting.IsDraggingEnabled) { return; } if (isDragging) { return; } InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; currentInputSource.TryGetPosition(currentInputSourceId, out startHandPosition); Vector3 rotationAxisVec; switch (rotationType) { case RotationType.Roll: rotationAxisVec = gizmoSetting.HostTransform.right; break; case RotationType.Yaw: rotationAxisVec = gizmoSetting.HostTransform.up; break; case RotationType.Pitch: rotationAxisVec = gizmoSetting.HostTransform.forward; break; default: return; } Vector3 projectionVect = Vector3.ProjectOnPlane(rotationAxisVec, mainCamera.transform.forward); projectionVect.Normalize(); orthogonalRotationAxisVec = Vector3.Cross(mainCamera.transform.forward, projectionVect); orthogonalRotationAxisVec.Normalize(); rend.material.color = gizmoSetting.rotDraggingColor; gizmoSetting.IsDraggingRotator = true; StartedDragging.RaiseEvent(); }
private void HandleTouchStart() { if (_itemIndex >= ItemsSource.Count) { return; } if (_cardDistance != 0) { return; } _lastX = 0; _isDragging = true; StartedDragging?.Invoke(this, new DraggingEventArgs(ItemsSource[_itemIndex], 0)); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; currentInputSource.TryGetPosition(currentInputSourceId, out this.startHandPos); this.objStartPos = HostTransform.position; StartedDragging.RaiseEvent(); }
public void StartDragging() { if (!gizmoSetting.IsDraggingEnabled) { return; } if (isDragging) { return; } InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; Vector3 targetPosition = gizmoSetting.HostTransform.position; currentInputSource.TryGetPosition(currentInputSourceId, out startHandPosition); rend.material.color = gizmoSetting.movDraggingColor; gizmoSetting.IsDraggingMover = true; StartedDragging.RaiseEvent(); }
/// <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); } }
// How are there no events for this? protected override void OnThumbDragStarted(DragStartedEventArgs e) { base.OnThumbDragStarted(e); StartedDragging?.Invoke(); }
/// <summary> /// Starts dragging the object /// </summary> public void StartDragging() { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // TODO: robertes: Fix push/pop and single-hanlder model so that multiple handdraggable components // can be active at once. // Add self as a modal input handler, to get all inputs during the manipulation isDragging = true; if (hostRigidbody != null) { hostRigidbodyWasKinematic = hostRigidbody.isKinematic; hostRigidbody.isKinematic = true; } Vector3 initialDraggingPosition = HostTransform.position; Transform cameraTransform = CameraCache.Main.transform; Vector3 inputPosition = Vector3.zero; // TODO: 如何获取手势输入的空间点 Vector3 pivotPosition = GetHandPivotPosition(cameraTransform); handRefDistance = Vector3.Magnitude(inputPosition - pivotPosition); objRefDistance = Vector3.Magnitude(initialDraggingPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = cameraTransform.transform.InverseTransformDirection(HostTransform.position - initialDraggingPosition); Vector3 objDirection = Vector3.Normalize(initialDraggingPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(inputPosition - pivotPosition); objForward = cameraTransform.InverseTransformDirection(objForward); // the transform in camera space objUp = cameraTransform.InverseTransformDirection(objUp); // the transform up in camera space objDirection = cameraTransform.InverseTransformDirection(objDirection); // the transform direction in camera space handDirection = cameraTransform.InverseTransformDirection(handDirection); // the hand transform direction in camera space; objRefForward = objForward; objRefUp = objUp; // Store the initial offset between the hand and the object, so that we can consider it when dragging gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); draggingPosition = initialDraggingPosition; StartedDragging.RaiseEvent(); }
/// <summary> /// Starts dragging the object. /// </summary> public void StartDragging(Vector3 initialDraggingPosition) { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // TODO: robertes: Fix push/pop and single-handler model so that multiple HandDraggable components // can be active at once. // Add self as a modal input handler, to get all inputs during the manipulation InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; if (hostRigidbody != null) { hostRigidbodyWasKinematic = hostRigidbody.isKinematic; hostRigidbody.isKinematic = true; } Transform cameraTransform = CameraCache.Main.transform; Vector3 inputPosition = Vector3.zero; #if UNITY_2017_2_OR_NEWER InteractionSourceInfo sourceKind; currentInputSource.TryGetSourceKind(currentInputSourceId, out sourceKind); switch (sourceKind) { case InteractionSourceInfo.Hand: currentInputSource.TryGetGripPosition(currentInputSourceId, out inputPosition); break; case InteractionSourceInfo.Controller: currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); break; } #else currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); #endif Vector3 pivotPosition = GetHandPivotPosition(cameraTransform); handRefDistance = Vector3.Magnitude(inputPosition - pivotPosition); objRefDistance = Vector3.Magnitude(initialDraggingPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // Store where the object was grabbed from objRefGrabPoint = cameraTransform.transform.InverseTransformDirection(HostTransform.position - initialDraggingPosition); Vector3 objDirection = Vector3.Normalize(initialDraggingPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(inputPosition - pivotPosition); objForward = cameraTransform.InverseTransformDirection(objForward); // in camera space objUp = cameraTransform.InverseTransformDirection(objUp); // in camera space objDirection = cameraTransform.InverseTransformDirection(objDirection); // in camera space handDirection = cameraTransform.InverseTransformDirection(handDirection); // in camera space objRefForward = objForward; objRefUp = objUp; // Store the initial offset between the hand and the object, so that we can consider it when dragging gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); draggingPosition = initialDraggingPosition; StartedDragging.RaiseEvent(); }
/// <summary> /// オブジェクトのドラッグを開始する /// </summary> public void StartDragging(Vector3 initialDraggingPosition) { if (!IsDraggingEnabled) { return; } if (isDragging) { return; } // マニピュレーションのあいだのすべての入力を取得するため、自身をモーダル入力対象に追加する InputManager.Instance.PushModalInputHandler(gameObject); isDragging = true; Transform cameraTransform = CameraCache.Main.transform; // 手もしくはコントローラーの位置を取得する Vector3 inputPosition = Vector3.zero; #if UNITY_2017_2_OR_NEWER InteractionSourceInfo sourceKind; currentInputSource.TryGetSourceKind(currentInputSourceId, out sourceKind); switch (sourceKind) { case InteractionSourceInfo.Hand: currentInputSource.TryGetGripPosition(currentInputSourceId, out inputPosition); break; case InteractionSourceInfo.Controller: currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); break; } #else currentInputSource.TryGetPointerPosition(currentInputSourceId, out inputPosition); #endif // 基点の位置を取得する Vector3 pivotPosition = GetHandPivotPosition(cameraTransform); // つかんだときの基点と手とのあいだの距離 handRefDistance = Vector3.Magnitude(inputPosition - pivotPosition); // 基点とオブジェクトのあいだの距離 objRefDistance = Vector3.Magnitude(initialDraggingPosition - pivotPosition); Vector3 objForward = HostTransform.forward; Vector3 objUp = HostTransform.up; // オブジェクトがつかまれた場所を保持する objRefGrabPoint = cameraTransform.transform.InverseTransformDirection(HostTransform.position - initialDraggingPosition); Vector3 objDirection = Vector3.Normalize(initialDraggingPosition - pivotPosition); Vector3 handDirection = Vector3.Normalize(inputPosition - pivotPosition); objForward = cameraTransform.InverseTransformDirection(objForward); // カメラ空間での objUp = cameraTransform.InverseTransformDirection(objUp); // カメラ空間での objDirection = cameraTransform.InverseTransformDirection(objDirection); // カメラ空間での handDirection = cameraTransform.InverseTransformDirection(handDirection); // カメラ空間での objRefForward = objForward; objRefUp = objUp; // 手とオブジェクトのあいだの最初の回転の差分を保持する // これによりドラッグ中にこれを考慮できる gazeAngularOffset = Quaternion.FromToRotation(handDirection, objDirection); draggingPosition = initialDraggingPosition; StartedDragging.RaiseEvent(); }