Exemplo n.º 1
0
    IEnumerator WaitEndOfAttack()
    {
        //等待一帧,让怪兽开始播放攻击动画
        //yield return null;

        while (true)
        {
            //if (ANIM.IsInTransition(0))
            //{
            //    yield return null;
            //}
            //获取当前的动画信息
            AnimatorStateInfo asi = ANIM.GetCurrentAnimatorStateInfo(0);
            //判定当前动画是否是idle动画
            if (asi.fullPathHash == Animator.StringToHash("Base Layer.Idle"))
            {
                break;
            }
            //else if (asi.fullPathHash == Animator.StringToHash("Base Layer.Locomotion"))
            //{
            //    yield return null;
            //}
            //else if (asi.fullPathHash == Animator.StringToHash("Base Layer.Attack"))
            //{

            //    yield return null;
            //}
            else
            {
                yield return(null);
            }
        }

        //代表攻击完毕, 需要转回去
        ANIM.SetFloat("Speed", 1.0f);
        //标识旋转方向
        m_eTurn = eTurnDirection.eTurn_Right;
        //标识旋转状态
        m_eState = eMonsterState.Monster_Turn;
        //标识旋转终点
        m_qCurStateQuaternion = m_qBirthQuaternion;
    }
Exemplo n.º 2
0
    void RunAttackRun()
    {
        if (CheckEndOfMove())
        {
            return;
        }

        //计算当前运动的百分比进度
        m_fCurentPercentage = CalculateCurPercentage();
        switch (m_eState)
        {
        case eMonsterState.Monster_RunAway:
        {
            /*
             * 怪兽运动进度, 是否是第一次播放攻击动画 : 只有满足上述两个条件,当前运动进度 > 设定运动进度 && 是第一次进行攻击 -> 执行攻击逻辑
             * */
            if (m_fCurentPercentage > m_fPercentage && m_bIsFirstAttack)
            {
                m_bIsFirstAttack = false;
                //设置转身模式
                m_eState = eMonsterState.Monster_Turn;
                //设置转身朝向
                m_eTurn = eTurnDirection.eTurn_Left;
                //设置当前状态旋转终点
                m_qCurStateQuaternion = m_qTurnQuaternion;
                return;
            }

            //播放前进动画
            ANIM.SetFloat("Speed", 1.0f);
            //修改怪兽位置
            MoveMononster();
            break;
        }

        case eMonsterState.Monster_Dead:
        {
            //判定透明度
            if (m_alpha <= 0)
            {
                Destroy(gameObject);
                return;
            }

            if (null == m_sDeadShader)
            {
                m_sDeadShader             = Shader.Find("Custom/SimpleAlpha");
                m_smr.materials[0].shader = m_sDeadShader;
            }

            m_smr.materials[0].SetFloat("_TransVal", m_alpha);
            m_alpha -= Time.deltaTime * 0.5f;
            transform.Translate(new Vector3(0f, 2 * Time.deltaTime, 0f));

            break;
        }

        case eMonsterState.Monster_Attack:
        {
            //获取当前的动画信息
            asi = ANIM.GetCurrentAnimatorStateInfo(0);
            //判定当前动画是否是idle动画
            if (asi.fullPathHash == Animator.StringToHash("Base Layer.Idle"))
            {
                //代表攻击完毕, 需要转回去
                ANIM.SetFloat("Speed", 1.0f);
                //标识旋转方向
                m_eTurn = eTurnDirection.eTurn_Right;
                //标识旋转状态
                m_eState = eMonsterState.Monster_Turn;
                //标识旋转终点
                m_qCurStateQuaternion = m_qBirthQuaternion;
                return;
            }
            break;
        }

        case eMonsterState.Monster_Turn:
        {
            //旋转怪兽到制定位置 -> Lerp的原理 : Beizier Line.
            transform.rotation = Quaternion.Lerp(transform.rotation, m_qCurStateQuaternion, 10 * Time.deltaTime);
            //判定当前旋转是否到达指定角度
            if (Mathf.Abs(transform.rotation.eulerAngles.y - m_qCurStateQuaternion.eulerAngles.y) < 0.1f)
            {
                //左转
                if (m_eTurn == eTurnDirection.eTurn_Left)
                {
                    //设置当前状态为攻击状态
                    m_eState = eMonsterState.Monster_Attack;
                    //播放攻击动画
                    ANIM.SetTrigger("Base Layer.Attack");
                    //AudioManager.PlayAudio(gameObject, eAudioType.Audio_Skill, "BI_sound");
                    //开启协程等待攻击结束
                    //StartCoroutine(WaitEndOfAttack());
                }
                //右转
                else
                {
                    m_eState = eMonsterState.Monster_RunAway;
                }
            }
            break;
        }
        }
    }