Exemplo n.º 1
0
        /// <summary>
        /// 获取用户输入,设置对应方向变量
        /// </summary>
        void ProcessInput()
        {
            float v = GameInput.GetInstance().Position.y;
            float h = GameInput.GetInstance().Position.x;

            mbMovingInput = v != 0 || h != 0;

            //GameDebug.LogError("v:" + v + " h:" + h);

            if (mbMovingInput)
            {
                Vector3 dir = Vector3.zero;

                if (Game.Instance.CameraControl != null && Game.Instance.CameraControl.Mode == CameraControl.EMode.CM_FOLLOW_FORCE_FOCUS)
                {
                    CameraControl camControl    = Game.Instance.CameraControl;
                    Vector3       cameraForward = camControl.transform.forward;
                    Vector3       right         = Vector3.zero;
                    Vector3       forward       = Vector3.zero;

                    if (h < 0.0f)
                    {
                        right = camControl.transform.right;
                    }
                    else if (h > 0.0f)
                    {
                        right = -camControl.transform.right;
                    }

                    if (v < 0.0f)
                    {
                        forward = cameraForward;
                    }
                    else if (v > 0.0f)
                    {
                        forward = -cameraForward;
                    }

                    dir = right + forward;
                }
                else
                {
                    dir.x = -h;
                    dir.z = -v;

                    if (Game.Instance.CameraControl != null && Game.Instance.CameraControl.SelectedChildCamera != null)
                    {
                        float cameraForward = Game.Instance.CameraControl.SelectedChildCamera.eulerAngles.y;

                        var rotation = Quaternion.Euler(0, cameraForward, 0);
                        dir = rotation * dir;
                    }
                }

                dir.Normalize();
                //dir.y = 0.0f;

                // 方向的细分限制

                /*float angle = Maths.Util.VectorToAngle(dir);
                 * float minAngle = Mathf.PI/16.0f;
                 * float angleF = Mathf.RoundToInt(angle/minAngle) * minAngle;
                 * dir = Maths.Util.AngleToVector(angleF);*/

                _walk(dir);

                mIsNoneInput = false;
            }
            else
            {
                mIsNoneInput = true;
            }

            if (false == mbMovingInput && mOwner.WalkMode == ActorMachine.EWalkMode.EWM_Dir && (mOwner.IsWalking()))
            {
                // 当非任务指引的时候才停止 并且也不在非跟随模式才停止
                if (TargetPathManager.Instance.IsNavigating == false)
                {
                    Actor localPlayer = Game.GetInstance().GetLocalPlayer();

                    if (localPlayer.GetAIEnable() == false)
                    {
                        TryWalkAlongStop();
                    }
                }
            }

            if (!mIsNoneInput)
            {
                Actor localPlayer = Game.GetInstance().GetLocalPlayer();
                if (localPlayer != null)
                {
                    ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_PLAYERCONTROLED, null);
                }
            }
        }
Exemplo n.º 2
0
 void LateUpdate()
 {
     GameInput.GetInstance().Update();
 }