コード例 #1
0
    //-----------------------------------------------------------

    private void Update()
    {
        if (_animator)
        {
            //相机没有锁住物体时
            if (camcon.LockState == false)
            {
                //根据Dmag值来调节混合动画,线性插值可以防止走路跟奔跑的动作过渡太过突然
                _animator.SetFloat("forward",
                                   _inputState.DMag * Mathf.Lerp(_animator.GetFloat("forward"), (_inputState.isrun ? 2.0f : 1.0f), 0.1f));
                _animator.SetFloat("Right", 0);
            }
            else //相机锁住物体时,即聚焦模式,移动动作变更
            {
                //将旋转量从世界空间转变到局部空间
                Vector3 localDvec = transform.InverseTransformVector(_inputState.Dvec);
                _animator.SetFloat("forward", localDvec.z);
                _animator.SetFloat("Right", localDvec.x);
            }

            //触发锁定
            if (_inputState.islock)
            {
                camcon.LockUnLock();
            }

            if (_rigidbodyrig.velocity.magnitude > 1)
            {
                _animator.SetTrigger("Roll");
            }

            //触发跳跃
            if (_inputState.isjump)
            {
                _animator.SetTrigger("jump");
                IsAttack = false;
            }

            //轻攻击操作
            //rb : 右手攻击 ,lb :左手攻击
            if ((_inputState.rb || _inputState.lb) &&
                (CheckState("Ground") ||
                 CheckStateTag("attackL") ||
                 CheckStateTag("attackR")) && IsAttack)
            {
                if (_inputState.rb)
                {
                    _animator.SetBool("mirror", false);
                    _animator.SetTrigger("attack");
                }

                //左手持剑下也可以攻击
                else if (_inputState.lb && !leftIsShield)
                {
                    _animator.SetBool("mirror", true);
                    _animator.SetTrigger("attack");
                }
            }

            //重攻击操作
            if ((_inputState.rt || _inputState.lt) &&
                (CheckState("Ground") ||
                 CheckStateTag("attackL") ||
                 CheckStateTag("attackR")) && IsAttack)
            {
                if (_inputState.rt)
                {
                    print("do heavy attack");
                }
                //左手操作,如果持剑,进行重攻击。如果持盾,进行盾反
                else
                {
                    if (!leftIsShield)
                    {
                        print("do heavy attack");
                    }
                    else
                    {
                        _animator.SetTrigger("counterback");
                    }
                }
            }

            //特殊攻击
            if (_inputState.isFontStab)
            {
                OnACtion.Invoke();
            }

            //装备盾牌的情况下
            if (leftIsShield)
            {
                float CurrentWeight = 0;
                //只有处于Ground动画状态才能举盾
                if (CheckState("Ground"))
                {
                    _animator.SetBool("Defense", _inputState.isdefense);
                    if (_inputState.isdefense == true)
                    {
                        CurrentWeight = 1;
                        _animator.SetLayerWeight(_animator.GetLayerIndex("Defense"),
                                                 Mathf.SmoothDamp(_animator.GetLayerWeight(_animator.GetLayerIndex("Defense")), CurrentWeight,
                                                                  ref _currentValue, 0.1f));
                    }
                    else
                    {
                        _animator.SetLayerWeight(_animator.GetLayerIndex("Defense"),
                                                 Mathf.SmoothDamp(_animator.GetLayerWeight(_animator.GetLayerIndex("Defense")), 0, ref _currentValue,
                                                                  0.1f));
                    }
                } //非Ground动画状态强制取消举盾动作
                else
                {
                    _animator.SetBool("Defense", false);
                    _animator.SetLayerWeight(_animator.GetLayerIndex("Defense"),
                                             Mathf.SmoothDamp(_animator.GetLayerWeight(_animator.GetLayerIndex("Defense")), 0, ref _currentValue, 0.1f));
                }
            }
            //非举盾状态下将Ddfense层的权重拉到0
            else
            {
                _animator.SetLayerWeight(_animator.GetLayerIndex("Defense"),
                                         Mathf.SmoothDamp(_animator.GetLayerWeight(_animator.GetLayerIndex("Defense")), 0, ref _currentValue, 0.1f));
            }


            //未锁定某一对象
            if (camcon.LockState == false)
            {
                //只有摇杆值不为0时才进行角色方向变更
                if (_inputState.DMag > 0.1f)
                {
                    //利用线性插值使角色旋转变得平滑
                    playerModel.transform.forward =
                        Vector3.Slerp(playerModel.transform.forward, _inputState.Dvec, 0.3f);
                }

                //移动速度的计算
                if (!isLockmoving)
                {
                    _movingVec = _inputState.DMag * playerModel.transform.forward * walkSpeed *
                                 (_inputState.isrun ? runSpeed : 1.0f);
                }
            }

            else //处于锁定状态
            {
                //模型指向角色控制柄
                playerModel.transform.forward = transform.forward;
                if (!isLockmoving)
                {
                    //由于锁定状态下forward被锁死,所以要根据旋转Dvec来调整移动
                    _movingVec = _inputState.Dvec * walkSpeed;
                }
            }
        }//if(_animator)_End

        if (_inputState.isStart && !isOpenBGUIForm)
        {
            UIFormsMgr.GetInstance().ShowUIForm("BG_UI");
            Cursor.lockState = CursorLockMode.None;
            isOpenBGUIForm   = true;
        }
        else
        if (_inputState.isStart && isOpenBGUIForm)
        {
            UIFormsMgr.GetInstance().CloseUIForm("BG_UI");
            Cursor.lockState = CursorLockMode.Locked;
            isOpenBGUIForm   = false;
        }
    }//Update_End
コード例 #2
0
 private void Awake()
 {
     UIFormsMgr.GetInstance().ShowUIForm("Main_UI");
 }