Exemple #1
0
        /// <summary>
        /// Uniform code for different types of manipulation complete (stopped, source lost, etc..)
        /// </summary>
        private void HandleRelease(bool lost)
        {
            mTempInputSource = null;

            Vector3 handPosition;

            mCurrentInputSource.TryGetPointerPosition(mCurrentInputSourceId, out handPosition);

            mCurrentHandPosition = handPosition;
            Control.ManipulationUpdate(
                mStartHandPosition,
                mCurrentHandPosition,
                mStartHeadPosition,
                mStartHeadRay,
                lost ? GestureManipulationState.Lost : GestureManipulationState.None);

            InputManager.Instance.ClearModalInputStack();

            if (HasGaze)
            {
                base.OnInputUp(null);
            }
            else
            {
                base.OnInputUp(null);
                base.OnFocusExit();
            }

            mCurrentInputSource = null;

            HandleCursor(false);
        }
Exemple #2
0
        /// <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();
        }
Exemple #3
0
 public void OnInputDown(InputEventData eventData)
 {
     currentInputSource   = eventData.InputSource;
     currentInputSourceId = eventData.SourceId;
     currentInputSource.TryGetPointerPosition(currentInputSourceId, out defaultHandPosition);
     isRotatingEnabled = true;
 }
Exemple #4
0
    void INavigationHandler.OnNavigationUpdated(NavigationEventData eventData)
    {
        if (isSelected)
        {
            // 左右移动为旋转,上下移动为缩放
            float dx = eventData.NormalizedOffset.x;
            float dy = eventData.NormalizedOffset.y;
            if (System.Math.Abs(dx) > System.Math.Abs(dy))
            {
                // 2.c: Calculate a float rotationFactor based on eventData's NormalizedOffset.x multiplied by RotationSensitivity.
                // This will help control the amount of rotation.
                float rotationFactor = dx * RotationSensitivity;

                // 2.c: transform.Rotate around the Y axis using rotationFactor.
                transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
            }
            else
            {
                Vector3 dScale = Vector3.zero;
                //设置每一帧缩放的大小
                float scaleValue = 0.0002f;
                if (dy > 0)
                {
                    scaleValue = -1 * scaleValue;
                }
                //当缩放超出设置的最大,最小范围时直接返回
                if (transform.localScale.x > maxScale && scaleValue > 0)
                {
                    return;
                }
                if (transform.localScale.x < minScale && scaleValue < 0)
                {
                    return;
                }
                //根据比例计算每个方向上的缩放大小
                dScale.x              = scaleValue;
                dScale.y              = scaleValue;
                dScale.z              = scaleValue;
                transform.localScale += dScale;
            }
        }
        else
        {
            Vector3 currentHandPosition = Vector3.zero;
            InteractionSourceInfo sourceKind;
            inputSource.TryGetSourceKind(inputSourceId, out sourceKind);
            switch (sourceKind)
            {
            case InteractionSourceInfo.Hand:
                inputSource.TryGetGripPosition(inputSourceId, out currentHandPosition);
                break;

            case InteractionSourceInfo.Controller:
                inputSource.TryGetPointerPosition(inputSourceId, out currentHandPosition);
                break;
            }
            transform.position += (currentHandPosition - prevHandPosition) * TranslationSensitivity;
            prevHandPosition    = currentHandPosition;
        }
    }
Exemple #5
0
    void INavigationHandler.OnNavigationStarted(NavigationEventData eventData)
    {
        InputManager.Instance.PushModalInputHandler(gameObject);
        eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.

        if (!isSelected)
        {
            inputSource   = eventData.InputSource;
            inputSourceId = eventData.SourceId;

            Vector3 currentHandPosition = Vector3.zero;
            InteractionSourceInfo sourceKind;
            inputSource.TryGetSourceKind(inputSourceId, out sourceKind);
            switch (sourceKind)
            {
            case InteractionSourceInfo.Hand:
                inputSource.TryGetGripPosition(inputSourceId, out currentHandPosition);
                break;

            case InteractionSourceInfo.Controller:
                inputSource.TryGetPointerPosition(inputSourceId, out currentHandPosition);
                break;
            }
            prevHandPosition = currentHandPosition;
        }
        //gameObject.SendMessageUpwards("OnSelect", SendMessageOptions.DontRequireReceiver);
    }
Exemple #6
0
        public void OnManipulationUpdated(ManipulationEventData eventData)
        {
            if (isTransformEnabled)
            {
                _currentInputSource.TryGetPointerPosition(_currentInputSourceId, out _newHandPosition);

                _handDistance = Vector3.Magnitude(_newHandPosition - _handPosition);

                if (isDragging)
                {
                    _dragFactor = (Mathf.Abs(_handDistance) * 10);
                    drag(eventData.CumulativeDelta);
                }

                if (isScaling)
                {
                    _scaleFactor = (Mathf.Abs(_handDistance) * 10);
                    scale(eventData.CumulativeDelta);
                }

                if (isRotating)
                {
                    _rotationFactor = (Mathf.Abs(_handDistance) * 10);
                    Quaternion rotation = new Quaternion(eventData.CumulativeDelta.x * _rotationFactor, eventData.CumulativeDelta.y * _rotationFactor, eventData.CumulativeDelta.z * _rotationFactor, 0.0f);
                    rotate(rotation);
                }
            }
        }
    /// <summary>
    /// ドラッグした時
    /// </summary>
    private void OnSourceDraged()
    {
        if (!isDraged)
        {
            return;
        }
        text[7].text = "ゆびをおろしました: " + canSettings;

        if (canSettings)
        {
            Vector3 pos;
            currentInputSouce.TryGetPointerPosition(id, out pos);
            time += Time.deltaTime;

            if (time < 20)
            {
                text[7].text = "カウントしています: " + time.ToString();
            }

            if (time >= 10)
            {
                text[7].text = "エディットモードを開始します";
                Debug.Log("エディットモードを開始します");
                SettingsCanvas.SetActive(true);
                IsEditingPlaced = true;
                SetSettingsEnable(true);
            }
        }

        //TODO:
        if (!canSettings)
        {
            return;
        }
    }
Exemple #8
0
        void UpdateRotation()
        {
            currentInputSource.TryGetPointerPosition(currentInputSourceId, out newHandPosition);

            dot = Vector3.Dot(defaultHandPosition - newHandPosition, Camera.main.transform.right);

            map.transform.RotateAround(map.transform.position, map.transform.up, dot * modifier);
        }
    //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();
    }
        /// <summary>
        /// Hand position
        /// </summary>
        /// <returns></returns>
        private Vector3 GetCurrentHandPosition()
        {
            Vector3 handPosition;

#if UNITY_2017_2_OR_NEWER
            mCurrentInputSource.TryGetGripPosition(mCurrentInputSourceId, out handPosition);
#else
            mCurrentInputSource.TryGetPointerPosition(mCurrentInputSourceId, out handPosition);
#endif
            return(handPosition);
        }
Exemple #11
0
        public static Vector3 GetHandPos(IInputSource currentInputSource, uint currentInputSourceId)
        {
#if UNITY_2017_2_OR_NEWER
            Vector3 pos = Vector3.zero;
            InteractionSourceInfo sourceKind;
            currentInputSource.TryGetSourceKind(currentInputSourceId, out sourceKind);
            switch (sourceKind)
            {
            case InteractionSourceInfo.Hand:
                currentInputSource.TryGetGripPosition(currentInputSourceId, out pos);
                break;

            case InteractionSourceInfo.Controller:
                currentInputSource.TryGetPointerPosition(currentInputSourceId, out pos);
                break;
            }
#else
            currentInputSource.TryGetPointerPosition(currentInputSourceId, out pos);
#endif
            return(pos);
        }
    public void StartScaling()
    {
        if (!IsScalingEnabled)
        {
            return;
        }

        if (isScaling)
        {
            return;
        }

        InputManager.Instance.PushModalInputHandler(gameObject);

        isScaling = 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

        startPosition = inputPosition;
        startScale    = transform.localScale.x;

        StartedScaling.RaiseEvent();
    }
Exemple #13
0
        /// <summary>
        /// Start the gesture
        /// </summary>
        /// <param name="ticker"></param>
        /// <param name="type"></param>
        private void HandleStartGesture()
        {
            InputManager.Instance.ClearModalInputStack();

            // Add self as a modal input handler, to get all inputs during the manipulation
            InputManager.Instance.PushModalInputHandler(gameObject);

            mCurrentInputSource   = mTempInputSource;
            mCurrentInputSourceId = mTempInputSourceId;

            mStartHeadPosition = CameraCache.Main.transform.position;
            mStartHeadRay      = CameraCache.Main.transform.forward;

            Vector3 handPosition;

            mCurrentInputSource.TryGetPointerPosition(mCurrentInputSourceId, out handPosition);

            mStartHandPosition   = handPosition;
            mCurrentHandPosition = handPosition;
            Control.ManipulationUpdate(mStartHandPosition, mStartHandPosition, mStartHeadPosition, mStartHeadRay, GestureManipulationState.Start);
            HandleCursor(true);
        }
Exemple #14
0
        public void OnManipulationStarted(ManipulationEventData eventData)
        {
            if (!isTransformEnabled)
            {
                return;
            }

            if (isScaling)
            {
                return;
            }

            if (isDragging)
            {
                return;
            }

            if (isRotating)
            {
                return;
            }

            isScaling  = isKeywordScale;
            isDragging = isKeywordDrag;
            isRotating = isKeywordRotate;

            // put the game object onto the model stack
            InputManager.Instance.PushModalInputHandler(gameObject);

            _currentInputSource   = eventData.InputSource;
            _currentInputSourceId = eventData.SourceId;

            _previousPosition = transform.position;
            _previousScale    = transform.localScale;
            _previousRotation = transform.rotation;

            // Find position of hand
            _currentInputSource.TryGetPointerPosition(_currentInputSourceId, out _handPosition);
        }
Exemple #15
0
        /// <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();
        }
Exemple #16
0
        /// <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();
        }