Ejemplo n.º 1
0
    ////给一些屏幕操作提示
    //private void OnGUI()
    //{
    //    GUILayout.Label(paramStateTip+strGUITip, _guiStyle);
    //}

    /// <summary>
    /// 鼠标滑屏引起的旋转只会相应当前帧
    /// </summary>
    /// <returns></returns>
    private IEnumerator nextFrameStopRotate()
    {
        yield return(new WaitForFixedUpdate());

        if (_cmdRotate == MoveCmdType.MouseRotateLeft || _cmdRotate == MoveCmdType.MouseRotateRight)
        {
            _cmdRotate = MoveCmdType.None;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        ////测试代码 .如果新的状态在范围内,需要直接定位到近距离
        //if(isInArea != PositionTool.isInBoxArea(tranCube, colliderRoomArea))
        //{
        //    Debug.LogError("范围状态发生变化!!isInBoxArea?" + PositionTool.isInBoxArea(tranCube, colliderRoomArea) + ",old=" + isInArea);
        //    isInArea = PositionTool.isInBoxArea(tranCube, colliderRoomArea);
        //}

        float rotateSpeeedUse = rotateSpeed;

        if (Input.GetKeyDown(KeyCode.W))
        {
            Logger.Log("向前走");
            _cmdMove = MoveCmdType.MoveForward;
            //StartCoroutine(waitSetNormalMoveState(MoveCmdType.MoveForward));
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            Logger.Log("往后退");
            _cmdMove = MoveCmdType.MoveBack;
            //StartCoroutine(waitSetNormalMoveState(MoveCmdType.MoveBack));
        }

        //判断鼠标是否滑动屏幕了
        if (_cmdRotate == MoveCmdType.None)
        {
            if (first == VecMax)
            {
                first = Input.mousePosition;
            }
            else
            {
                //记录鼠标拖动的位置
                second = Input.mousePosition;// Event.current.mousePosition;
                //讨论左右滑动
                if (second.x < first.x)
                {
                    //拖动的位置的x坐标比按下的位置的x坐标小时,响应向左事件
                    Logger.Log("鼠标左滑");
                    _cmdRotate = MoveCmdType.MouseRotateLeft;
                    StopCoroutine(nextFrameStopRotate());
                    StartCoroutine(nextFrameStopRotate());
                    rotateSpeeedUse *= mouseRotateRate;
                }
                else if (second.x > first.x)
                {
                    //拖动的位置的x坐标比按下的位置的x坐标大时,响应向右事件
                    Logger.Log("鼠标右滑");
                    _cmdRotate = MoveCmdType.MouseRotateRight;
                    StopCoroutine(nextFrameStopRotate());
                    StartCoroutine(nextFrameStopRotate());
                    rotateSpeeedUse *= mouseRotateRate;
                }
                else if (second.y < first.y) // //讨论鼠标上下移动 鼠标下滑动,距离越远,改动俯仰的程度应该越大,不然镜头扭不动了
                {
                    followCom.height -= FollowPlayer.HEIGHT_MOVE_SUB_BASE * getActionSpeed();
                    followCom.height  = Mathf.Max(followCom.height, 0); //视角不能钻到地下!
                }
                else if (second.y > first.y)                            //鼠标上滑动
                {
                    followCom.height += FollowPlayer.HEIGHT_MOVE_SUB_BASE * getActionSpeed();
                }
                first = second;
            }
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            Logger.Log("向左转");
            _cmdRotate = MoveCmdType.RotateLeft;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            Logger.Log("向右转");
            _cmdRotate = MoveCmdType.RotateRight;
        }

        //判定是否终止标记
        if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S))
        {
            Logger.Log("松开前后操作键,终止位移");
            _cmdMove         = MoveCmdType.None;
            moveSpeedAddBase = 1f;
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
        {
            Logger.Log("松开左右操作键,终止旋转");
            _cmdRotate = MoveCmdType.None;
            first      = VecMax;
            second     = VecMax;
        }

        //最后根据当前的指令决定怎么运动!
        DoMove(moveSpeed * getActionSpeed());//23点47分刚刚加入,远距离就改为较快的移动速度
        DORotate(rotateSpeeedUse);

        UpdateCemeraDistanceState();

        //刷新当前参数:
        paramStateTip = "当前视距:" + followCom.distance + ",当前视野高度:" + followCom.height + "\n";
        CanvasCtrl.Instance.UpdateLog(paramStateTip + strGUITip);
    }