Ejemplo n.º 1
0
        /// <summary>
        /// 开启主相机绕指定点旋转 注意:不要设置在有自转的Transform下
        /// </summary>
        /// <param name="cameraRotateCenter">相机对准物体</param>
        /// <param name="speed"></param>
        public void StartCameraRotateWithCenter(Transform cameraCenter, float duration = 0.5f)
        {
            StopCameraRotateWithCenter();

            if (mainCamera == null)
            {
                mainCamera = MUtility.MainCamera;
            }

            cameraLookToCenter = cameraCenter.gameObject;

            tween =

                //朝向开启再旋转
                mainCamera.transform.DOLookAt(cameraLookToCenter.transform.position, duration).OnComplete(() =>
            {
                dragMouseOrbit = new DragMouseOrbit(cameraCenter, mainCamera.transform);

                EventCameraRotate.AddListener(RotateCameraToCenter);

                mBehaviour = new MBehaviour(ExecutionPriority.High);

                mBehaviour.OnUpdate_MBehaviour(() =>
                {
                    RotateCameraToCenter(inputPointPos);
                });


                isRotateCameraWithCenter = true;

                isRotateCameraWithCenterInitialization = true;

                RotateAndZoomManager.IsDone_StartCameraAroundCenter_Initialization = true;
            });
        }
Ejemplo n.º 2
0
            /// <summary>
            /// 旋转动作
            /// </summary>
            /// <param name="handOperate">Hand operate.</param>
            public void OnRotate(HandOperate handOperate)
            {
                //如果左手以及处于旋转状态,则没必要进行下一步了
                if (!handOperate.IsRotating)
                {
                    if (IsRotate(handOperate) && Operate.InputHand.ScreenVector.magnitude > 5)
                    {
                        Operate.InputHand.HandStatus = MInputHandStatus.Rotate;

                        IsRotating = true;
                    }

                    if (Operate.InputHand.IsRotateStatus)
                    {
                        EventCameraRotate.SendListener(Operate.InputHand.ScreenVector);
                    }
                    else
                    {
                        if (IsRotating)
                        {
                            EventCameraRotate.SendListener(Vector3.zero);
                            IsRotating = false;
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// 关闭主相机 绕自身轴转
        /// </summary>
        public void StopCameraSelfRotate()
        {
            EventCameraRotate.RemoveListener(RotateCameraSelf);

            isSelfRotateCameraEnable = false;

            isCameraRotateSelfInitialization = false;
        }
Ejemplo n.º 4
0
            /// <summary>
            /// 具体实现,是旋转还是缩放
            /// </summary>
            /// <param name="inputHand"></param>
            /// <param name="IsRotate"></param>
            public void OnAchieve(MInputHand inputHand, bool IsRotate)
            {
                ////如果按下右键
                //if (Input.GetMouseButtonDown(0))
                //{
                //    IsDown = true;
                //    IsObserved = false;
                //}

                //if (Input.GetMouseButtonUp(0))
                //{
                //    IsDown = false;

                //    //已经存在旋转,并且在集合中记录
                //    if (IsObserved)
                //    {
                //        if (IsRotate)
                //            EventCameraRotate.SendListener(Vector3.zero);
                //        else
                //            EventCameraZoom.SendListener(0);
                //    }

                //    IsObserved = false;
                //    inputHand.HandStatus = MInputHandStatus.Idle;
                //}

                //按住右键旋转
                if (IsDown)
                {
                    //向量的模大于2.0时
                    if (!IsObserved && inputHand.ScreenVector.magnitude > 2.0f)
                    {
                        //将动作记录到集合中
                        inputHand.HandStatus = IsRotate ? MInputHandStatus.Rotate : MInputHandStatus.Zoom;

                        IsObserved = true;
                    }

                    //已经存在旋转,并且在集合中记录
                    if (IsObserved)
                    {
                        if (IsRotate)
                        {
                            Vector3 vector = inputHand.ScreenVector;
                            EventCameraRotate.SendListener(vector);
                        }
                        else
                        {
                            EventCameraZoom.SendListener(inputHand.ScreenVector.x / 1200);
                        }
                    }
                }
            }
Ejemplo n.º 5
0
 /// <summary>
 /// 相机绕点转的暂停和重启方法
 /// </summary>
 /// <param name="isenable"></param>
 public void PauseOrRestart_CameraRotateSelf(bool isenable)
 {
     if (!isCameraRotateSelfInitialization)
     {
         return;
     }
     if (isenable)
     {
         EventCameraRotate.AddListener(RotateCameraSelf);
     }
     else
     {
         EventCameraRotate.RemoveListener(RotateCameraSelf);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 相机绕点转的暂停和重启方法
 /// </summary>
 /// <param name="isenable"></param>
 public void PauseOrRestart(bool isenable)
 {
     if (!isRotateCameraWithCenterInitialization)
     {
         return;
     }
     if (isenable)
     {
         EventCameraRotate.AddListener(RotateCameraToCenter);
         mBehaviour.IsEnable = true;
     }
     else
     {
         EventCameraRotate.RemoveListener(RotateCameraToCenter);
         mBehaviour.IsEnable = false;
     }
 }
Ejemplo n.º 7
0
            /// <summary>
            /// 抬起时
            /// </summary>
            /// <param name="IsRotate"></param>
            public void OnUp(bool IsRotate)
            {
                IsDown = false;

                //已经存在旋转,并且在集合中记录
                if (IsObserved)
                {
                    if (IsRotate)
                    {
                        EventCameraRotate.SendListener(Vector3.zero);
                    }
                    else
                    {
                        EventCameraZoom.SendListener(0);
                    }
                }

                IsObserved = false;
            }
Ejemplo n.º 8
0
        /// <summary>
        /// 开启主相机 绕自身轴转
        /// </summary>
        public void StartCameraSelfRotate()
        {
            rotateCore = new RotateCore();

            if (mainCamera == null)
            {
                mainCamera = MUtility.MainCamera;
            }

            if (otherHelpCameraSelfRotate == null)
            {
                otherHelpCameraSelfRotate = new OtherRotateHelp(cameraSelfRotateXlimits, cameraSelfRotateYlimits, rotateCameraSelfSpeed);
            }

            EventCameraRotate.AddListener(RotateCameraSelf);

            isSelfRotateCameraEnable = true;

            isCameraRotateSelfInitialization = true;
        }
Ejemplo n.º 9
0
        public void StartCameraRotateWithCenter(Transform cameraCenter, Vector3 camerainitialpos, Quaternion camerainitialqua, float duration = 0.5f)
        {
            StopCameraRotateWithCenter();

            if (mainCamera == null)
            {
                mainCamera = MUtility.MainCamera;
            }

            cameraLookToCenter = cameraCenter.gameObject;

            //开启初始化相机位置和角度

            tween =

                mainCamera.transform.DOMove(camerainitialpos, duration / 3);

            mainCamera.transform.DORotate(camerainitialqua.eulerAngles, duration / 3).OnComplete(() =>
            {
                mainCamera.transform.DOLookAt(cameraCenter.transform.position, duration / 3).OnComplete(() =>
                {
                    dragMouseOrbit = new DragMouseOrbit(cameraCenter, mainCamera.transform);

                    EventCameraRotate.AddListener(RotateCameraToCenter);

                    mBehaviour = new MBehaviour(ExecutionPriority.High);

                    mBehaviour.OnUpdate_MBehaviour(() =>
                    {
                        RotateCameraToCenter(inputPointPos);
                    });

                    isRotateCameraWithCenter = true;

                    isRotateCameraWithCenterInitialization = true;

                    RotateAndZoomManager.IsDone_StartCameraAroundCenter_Initialization = true;
                });
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 停止主相机 绕点旋转 相机会 设置回到 MCKinectObject下
        /// </summary>
        public void StopCameraRotateWithCenter()
        {
            tween.Kill();

            if (mBehaviour != null)
            {
                mBehaviour.OnExcuteDestroy();
            }

            if (dragMouseOrbit != null)
            {
                dragMouseOrbit.ClearData();
            }

            EventCameraRotate.RemoveListener(RotateCameraToCenter);

            isRotateCameraWithCenter = false;

            isRotateCameraWithCenterInitialization = false;

            RotateAndZoomManager.IsDone_StartCameraAroundCenter_Initialization = false;
        }
Ejemplo n.º 11
0
    void ontest()
    {
        gameObject.AddGrabObject(onGrab);
        gameObject.RemoveGrabObject(onGrab);
        gameObject.RemoveGrabObjectAll();

        gameObject.AddReleaseObject(OnRelease);
        gameObject.RemoveReleaseObject(OnRelease);
        gameObject.RemoveReleaseObjectAll();

        gameObject.AddRayTargetEnter(OnTargetEnter);
        gameObject.RemoveRayTargetEnter(OnTargetEnter);
        gameObject.RemoveRayTargetEnter();


        gameObject.AddRayTargetExit(OnTargetExit);
        gameObject.RemoveRayTargetExit();
        gameObject.RemoveRayTargetExit(OnTargetExit);


        EventHandRay.AddListener(onRay);
        EventHandRay.RemoveListener(onRay);

        EventHandRays.AddListener(OnRays);
        EventHandRays.RemoveListener(OnRays);

        EventHandStart.AddListener(onstart);
        EventHandStart.RemoveListener(onstart);

        EventHandStop.AddListener(onstop);
        EventHandStop.RemoveListener(onstop);

        EventHandUIRay.AddListener(onRay);
        EventHandUIRay.RemoveListener(onRay);

        EventCameraZoom.AddListener(onzoom);
        EventCameraZoom.RemoveListener(onzoom);

        EventCameraRotate.AddListener(onrotate);
        EventCameraRotate.RemoveListener(onrotate);

        EventHandGrabObject.AddListener(ongrabobject);
        EventHandGrabObject.RemoveListener(ongrabobject);

        EventHandReleaseObject.AddListener(onreleaseobject);
        EventHandReleaseObject.RemoveListener(onreleaseobject);

        EventHandGrabObjectKey.AddListener(gameObject, onGrab);
        EventHandGrabObjectKey.RemoveListener(gameObject, onGrab);

        EventHandReleaseObjectKey.AddListener(gameObject, OnRelease);
        EventHandReleaseObjectKey.RemoveListener(gameObject, OnRelease);

        EventHandRayTarget.AddListener(onraytarget);
        EventHandRayTarget.RemoveListener(onraytarget);

        EventHandRayTargetEnter.AddListener(gameObject, OnTargetEnter);
        EventHandRayTargetEnter.RemoveListener(gameObject, OnTargetEnter);

        EventHandRayTargetExit.AddListener(gameObject, OnTargetExit);
        EventHandRayTargetExit.RemoveListener(gameObject, OnTargetExit);

        EventHandUIRayEnter.AddListener(gameObject, onuienter);
        EventHandUIRayEnter.RemoveListener(gameObject, onuienter);

        EventHandUIRayExit.AddListener(gameObject, onuiexit);
        EventHandUIRayExit.RemoveListener(gameObject, onuiexit);

        EventHandUIRay.AddListener(onRay);
        EventHandUIRay.RemoveListener(onRay);
    }
Ejemplo n.º 12
0
            /// <summary>
            /// 手势动作的判定,用户来实现旋转和缩放
            /// </summary>
            /// <param name="handOperate">Hand operate.</param>
            public void OnGestureAction(HandOperate handOperate, bool isRotate)
            {
                switch (MSwitchManager.CurrentMode)
                {
                case OperateModeType.Move:
                    break;

                case OperateModeType.Rotate:
                    EventCameraRotate.SendListener(Operate.InputHand.ScreenVector);
                    break;

                case OperateModeType.Zoom:
                    // EventCameraZoom.SendListener(Operate.InputHand.ScreenVector.x / 1200);
                    break;

                case OperateModeType.Tool:
                    break;

                default:
                    break;
                }
                #region old
                ////如果左手以及处于旋转状态,则没必要进行下一步了
                //if (!handOperate.IsActioning)
                //{
                //    if (IsAction(handOperate) && Operate.InputHand.ScreenVector.magnitude > 5)
                //    {
                //        if (isRotate)
                //            Operate.InputHand.HandStatus = MInputHandStatus.Rotate;
                //        else
                //            Operate.InputHand.HandStatus = MInputHandStatus.Zoom;

                //        IsActioning = true;
                //    }

                //    if (isRotate)
                //    {
                //        if (Operate.InputHand.IsRotateStatus)
                //        {
                //            EventCameraRotate.SendListener(Operate.InputHand.ScreenVector);
                //        }
                //        else
                //        {
                //            if (IsActioning)
                //            {
                //                EventCameraRotate.SendListener(Vector3.zero);
                //                IsActioning = false;
                //            }
                //        }
                //    }
                //    else
                //    {
                //        if (Operate.InputHand.IsZoomStatus)
                //        {
                //            EventCameraZoom.SendListener(Operate.InputHand.ScreenVector.x / 1200);
                //        }
                //        else
                //        {
                //            if (IsActioning)
                //            {
                //                EventCameraZoom.SendListener(0);
                //                IsActioning = false;
                //            }
                //        }
                //    }
                //}
                #endregion
            }
Ejemplo n.º 13
0
        /// <summary>
        /// 鼠标控制端的妹帧执行
        /// </summary>
        void OnMouseUpdate()
        {
            if (!IsEnable)
            {
                return;
            }

            //将他的屏幕坐标传递出去
            InputHands[0].OnUpdate(Input.mousePosition);

            if (Input.GetMouseButtonDown(0) && InputHands[0].IsIdleStatus)
            {
                InputHands[0].SetGrip();
            }

            if (Input.GetMouseButtonUp(0) && !(InputHands[0].IsRotateZoomStatus || InputHands[0].IsErrorStatus))
            {
                InputHands[0].SetIdle();
            }

            #region 旋转

            //如果按下右键
            if (Input.GetMouseButtonDown(1))
            {
                IsRotateDown = true;
                IsRotate     = false;
            }

            if (Input.GetMouseButtonUp(1))
            {
                IsRotateDown = false;

                //已经存在旋转,并且在集合中记录
                if (IsRotate)
                {
                    EventCameraRotate.SendListener(Vector3.zero);
                }

                IsRotate = false;
                InputHands[0].HandStatus = MInputHandStatus.Idle;
            }

            //按住右键旋转
            if (IsRotateDown)
            {
                //向量的模大于2.0时
                if (!IsRotate && InputHands[0].IsIdleStatus && InputHands[0].ScreenVector.magnitude > 2.0f)
                {
                    //将动作记录到集合中
                    InputHands[0].HandStatus = MInputHandStatus.Rotate;

                    IsRotate = true;
                }

                //已经存在旋转,并且在集合中记录
                if (IsRotate)
                {
                    EventCameraRotate.SendListener(InputHands[0].ScreenVector);
                }
            }
            #endregion

            #region 缩放

            //缩放
            if (Input.GetAxis("Mouse ScrollWheel") != 0)
            {
                float result = Input.GetAxis("Mouse ScrollWheel");

                if (!IsZoom && InputHands[0].IsIdleStatus)
                {
                    InputHands[0].HandStatus = MInputHandStatus.Zoom;
                    IsZoom = true;
                }

                //进行缩放
                if (IsZoom)
                {
                    EventCameraZoom.SendListener(result);
                }
            }
            else
            {
                //进行缩放
                if (IsZoom)
                {
                    EventCameraZoom.SendListener(0);
                    IsZoom = false;
                    InputHands[0].HandStatus = MInputHandStatus.Idle;
                }
            }
            #endregion

            if (operateObject != null)
            {
                switch (InputHands[0].HandStatus)
                {
                case MInputHandStatus.Grabing:

                    //需要处理偏移量
                    var     screenDevice = MUtility.MainWorldToScreenPoint(operateObject.GrabObject.transform.position);
                    Vector3 screenMouse  = InputHands[0].ScreenPoint;
                    Vector3 vPos         = MUtility.MainScreenToWorldPoint(new Vector3(screenMouse.x, screenMouse.y, screenDevice.z));

                    Vector3 position = vPos - offset;

                    EventUpdateObject.SendListener(operateObject.GrabObject, position, operateObject.GrabObject.transform.rotation, InputHands[0].HandIndex);

                    break;

                case MInputHandStatus.Idle:

                    this.operateObject = null;
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 鼠标控制端的妹帧执行
        /// </summary>
        void OnMouseUpdate()
        {
            //将他的屏幕坐标传递出去
            InputHands[0].OnUpdate(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                InputHands[0].SetGrip();
            }

            if (Input.GetMouseButtonUp(0))
            {
                InputHands[0].SetIdle();
            }

            //如果按下右键
            if (Input.GetMouseButtonDown(1))
            {
                IsRotateDown = true;
                IsRotate     = false;
            }

            if (Input.GetMouseButtonUp(1))
            {
                IsRotateDown = false;

                //已经存在旋转,并且在集合中记录
                if (IsRotate && ActionConstraint.IsBind(ActionConstraint.Camera_Rotate_Action))
                {
                    EventCameraRotate.SendListener(Vector3.zero);
                }

                IsRotate = false;

                ActionConstraint.RemoveBind(ActionConstraint.Camera_Rotate_Action);
            }

            //按住右键旋转
            if (IsRotateDown)
            {
                //向量的模大于2.0时
                if (!IsRotate && ActionConstraint.BindCount == 0 && InputHands[0].ScreenVector.magnitude > 2.0f)
                {
                    //将动作记录到集合中
                    ActionConstraint.AddBind(ActionConstraint.Camera_Rotate_Action);

                    IsRotate = true;
                }

                //已经存在旋转,并且在集合中记录
                if (IsRotate && ActionConstraint.IsBind(ActionConstraint.Camera_Rotate_Action))
                {
                    EventCameraRotate.SendListener(InputHands[0].ScreenVector);
                }
            }

            //缩放
            if (Input.GetAxis("Mouse ScrollWheel") != 0)
            {
                float result = Input.GetAxis("Mouse ScrollWheel");

                if (!IsZoom && ActionConstraint.BindCount == 0)
                {
                    ActionConstraint.AddBind(ActionConstraint.Camera_Zoom_Action);

                    IsZoom = true;
                }

                //进行缩放
                if (IsZoom && ActionConstraint.IsBind(ActionConstraint.Camera_Zoom_Action))
                {
                    EventCameraZoom.SendListener(result);
                }
            }
            else
            {
                //进行缩放
                if (IsZoom && ActionConstraint.IsBind(ActionConstraint.Camera_Zoom_Action))
                {
                    EventCameraZoom.SendListener(0);
                }

                IsZoom = false;

                if (ActionConstraint.BindCount > 0)
                {
                    ActionConstraint.RemoveBind(ActionConstraint.Camera_Zoom_Action);
                }
            }

            if (operateObject != null)
            {
                switch (InputHands[0].HandStatus)
                {
                case MInputHandStatus.Grabing:

                    //需要处理偏移量
                    var     screenDevice = MUtility.MainWorldToScreenPoint(operateObject.GrabObject.transform.position);
                    Vector3 screenMouse  = InputHands[0].ScreenPoint;
                    Vector3 vPos         = MUtility.MainScreenToWorldPoint(new Vector3(screenMouse.x, screenMouse.y, screenDevice.z));

                    Vector3 position = vPos - offset;

                    EventUpdateObject.SendListener(operateObject.GrabObject, position, operateObject.GrabObject.transform.rotation, InputHands[0].HandIndex);

                    break;

                case MInputHandStatus.Idle:

                    this.operateObject = null;
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 15
0
        void KinectRotateZoom()
        {
            if (MInputKinect.HandGrip(0))
            {
                handIndex   = 0;
                isRightGrip = true;
            }
            else if (MInputKinect.HandRelease(0))
            {
                isRightGrip = false;
            }

            if (MInputKinect.HandGrip(1))
            {
                handIndex  = 1;
                isLeftGrip = true;
            }
            else if (MInputKinect.HandRelease(1))
            {
                isLeftGrip = false;
                handIndex  = 0;
            }


            if (IsRotate)                                                            // 旋转
            {
                if ((isLeftGrip && !isRightGrip) || (isRightGrip && !isLeftGrip))
                {
                    if (!isTempRotate && ActionConstraint.BindCount == 0 && InputHands[0].ScreenVector.magnitude > 2.0f)
                    {
                        //将动作记录到集合中
                        ActionConstraint.AddBind(ActionConstraint.Camera_Rotate_Action);

                        isTempRotate = true;
                    }

                    //已经存在旋转,并且在集合中记录
                    if (isTempRotate && ActionConstraint.IsBind(ActionConstraint.Camera_Rotate_Action))
                    {
                        EventCameraRotate.SendListener(InputHands[handIndex].ScreenVector);
                    }
                }
                else
                {
                    EventCameraRotate.SendListener(Vector3.zero);
                }
            }


            if (IsZoom)                                                                 // 缩放
            {
                if (isRightGrip && isLeftGrip)
                {
                    if (!isTempZoom)
                    {
                        if (twoHandDistance != null)
                        {
                            twoHandDistance.TwoHandGrip();
                        }
                        isTempZoom = true;
                    }

                    if (twoHandDistance == null)
                    {
                        twoHandDistance = new TwoHandDistance();
                        twoHandDistance.TwoHandGrip();
                    }
                    else
                    {
                        float result = twoHandDistance.ZoomCameraToMoveFloat() / 10000;

                        if (result != 0 /* && isTempZoom *//*&& ActionConstraint.IsBind(ActionConstraint.Camera_Zoom_Action)*/)
                        {
                            EventCameraZoom.SendListener(result);
                        }
                    }
                }
                else if (!isRightGrip && !isLeftGrip && twoHandDistance != null)
                {
                    twoHandDistance.TwoHandIdle();
                    EventCameraZoom.SendListener(0);
                    isTempZoom = false;
                }
            }
        }
Ejemplo n.º 16
0
 internal override void OnLeave(IFsm <OperateSystem> fSM, bool v)
 {
     base.OnLeave(fSM, v);
     EventCameraRotate.SendListener(Vector3.zero);
 }