Exemple #1
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;
                }
            }
        }
        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;
                }
            }
        }