Пример #1
0
    public void Update()
    {
        #region 摄像机的Debug操作
        float step = 20 * Time.fixedDeltaTime;

        if (Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.LeftControl))
        {
            //SceneManager.Instance.GetCurScene().GetEffectManager().DarkenScene(new uint[] { PlayerController.Instance.GetControl() });
            //PlayCameraAnimation("base_gk03_^_^_path1");

            //(PlayerController.Instance.GetControlObj() as Player).ChangeAttach(AttachMountType.Wing, AssetConfig.WeaponPath + "weapon_wingemo", "chibang");
            //SceneManager.Instance.GetCurScene().StopDynamicToTarget();
            //ShakeCamera(10, 2);

            (PlayerController.Instance.GetControlObj() as VisualObject).AddEffect(516, null, float.NaN, AttachMountType.Wing);
        }
        if (Input.GetKey(KeyCode.J) && Input.GetKey(KeyCode.LeftControl))
        {
            //SceneManager.Instance.GetCurScene().PlayGameObjAnim("realistic_gk03_guanmen");
            //SceneManager.Instance.GetCurScene().PlayDynamicAnimation();
            //SceneManager.Instance.GetCurScene().GetEffectManager().RecoverScene();
        }

        if (allowRotate)
        {
            if (Input.GetKey(KeyCode.H))
            {
                mAngley -= step;
            }
            if (Input.GetKey(KeyCode.K))
            {
                mAngley += step;
            }
            if (Input.GetKey(KeyCode.U))
            {
                mAnglex += step;
            }
            if (Input.GetKey(KeyCode.J))
            {
                mAnglex -= step;
            }
            //if (Input.GetKey(KeyCode.P) && Input.GetKey(KeyCode.LeftAlt))
            //{
            //    PlayCameraEffect(5f, 0.8f);
            //}
            float mousestep = 10f;
            if (Input.GetKey(KeyCode.LeftShift))
            {
                mousestep = 50;
            }
            mousestep = (Input.GetAxis("Mouse ScrollWheel") * mousestep) * Time.deltaTime;
            if (mousestep != 0)
            {
                mDistance -= mousestep;
            }
        }

        #endregion


        bool switchFree = Input.GetKeyDown(KeyCode.I) && Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt);
        if (switchFree)
        {
            Free = !mFree;
        }
        if (mFree)
        {
            UpdateFreeCamera();
        }
        else if (!LockCamera)
        {
            if (mAnimatorPath != null)
            {
                /*
                 * 当有摄像机动画时
                 */
            }
            else
            {
                if (mCamera != null && mLookAt != null)
                {
                    if (mFollowPath != null)
                    {
                        UpdateFollowCamera(mLookAt.GetPosition());
                    }
                    else
                    {
                        float amentDistance = mDistance;
#if UNITY_STANDALONE_WIN || UNITY_EDITER
                        //                         if( ((float)Screen.width / (float)Screen.height) > 1.5f)
                        //                             amentDistance = mDistance + 3.5f;
#endif
                        if (mEffect.InUse)
                        {
                            mEffect.Update(Time.deltaTime);
                            amentDistance = mEffect.Distance;
                        }

                        //计算摄像机的位置和旋转
                        Vector3 oldPos = mCameraTransform.position;

                        Vector3 lookPos = mLookAt.GetPosition() + new Vector3(0, 1.5f, 0);

                        mCameraTransform.position = lookPos + new Vector3(0, amentDistance, 0);
                        mCameraTransform.LookAt(lookPos);
                        mCameraTransform.RotateAround(lookPos, Vector3.right, mAnglex);
                        mCameraTransform.RotateAround(lookPos, Vector3.up, mAngley);

                        Vector3 currentVelocity = Vector3.zero;

                        mCameraTransform.position += ShakeCamerPos();

                        if (!mInvalidInfo)
                        {
                            mCameraTransform.position = Vector3.SmoothDamp(oldPos, mCameraTransform.position, ref currentVelocity, 0.05f);
                        }
                        else
                        {
                            mInvalidInfo = false;
                        }
                    }
                }



                //#if UNITY_STANDALONE_WIN || UNITY_EDITER

                if (mCameraTest != null && mLookAt != null)
                {
                    mCameraTest.player_pos = mLookAt.GetPosition();
                    mCameraTest.dir_angle  = mLookAt.GetDirection() / Mathf.Deg2Rad;
                }
                //#endif
            }
        }
    }