示例#1
0
    public void updataAIRoleControl(float h, float tmpv, int fireSoft)
    {
        if (aniCon == null)
        {
            aniCon = this.gameObject.GetComponent <IbaseAnimator>();
        }

        roleState lState = aniCon.getRoleNowState();

        roleState lHopeState = getHopeState(h, tmpv, fireSoft, lState); //按键判断是否改变状态

        // bool isChangeToJump = false;
        if ((lState != lHopeState)
            // && (oldRoleState != lHopeState)
            )  //避免重复执行
        {
            //  if (lHopeState == roleState.jump) //切换成跳跃状态
            //      isChangeToJump = true;
            oldRoleState = lHopeState;
            aniCon.PlayState(lHopeState);
        }

        /*
         * if ((lHopeState == roleState.stand)|| (lHopeState == roleState.run)) { //移动停止时再检测敌人
         * { //移动停止时再检测敌人
         *  if (enemyObj != null) {
         *      getNowNewEnemyFromLst();
         *   }
         * }
         */
        //return isChangeToJump;
    }
示例#2
0
    //判断当前动画是否正在播, 播至最后一帧或播放其它动画返回false
    public bool isInPlayEntry(roleState stateName)
    {
        string            entryName = getStateStrName(stateName);
        bool              res       = false;
        AnimatorStateInfo info      = animator.GetCurrentAnimatorStateInfo(0);

        if (info.IsName(entryName))
        {
            //动画播到最后一帧 或未开始
            //if ((info.normalizedTime >= 1.0f) || (info.normalizedTime < 0.0f))
            if (info.normalizedTime >= 1.0f) //动画播到最后一帧
            {
                res = false;
            }
            else //未开始或正在播
            {  //动画正在播
                res = true;
            }
        }
        else
        {
            res = false;
        }

        return(res);
    }
示例#3
0
    public roleState getRoleNowState()
    { //获得角色当前状态
        roleState res = roleState.stand;

        if (m_animationController != null)
        {
            if (m_animationController.IsPlaying(csDefault))
            {
                res = roleState.stand;
            }
            else if (m_animationController.IsPlaying(csRun))
            {
                res = roleState.run;
            }
            else if (
                m_animationController.IsPlaying(csAttack1) ||
                m_animationController.IsPlaying(csAttack2)
                //|| m_animationController.IsPlaying(csAttack3)
                )
            {
                res = roleState.attack;
            }
            else if (m_animationController.IsPlaying(csAttackEnd)) //攻击动画未播完
            {
                if (m_animationController[csAttackEnd].normalizedTime < 1.0f)
                {
                    res = roleState.attack;
                    //  Debug.Log(" roleState is attackEnd");
                }
                else
                {
                    res          = roleState.init;
                    oldRoleState = res;
                    //   Debug.Log("need set roleState init");
                }
            }
            else if (m_animationController.IsPlaying(csJump))
            {
                //if (m_animationController[csJump].normalizedTime < 1.0f)
                //{
                res = roleState.jump;
                Debug.Log(" roleState is jump");
                //}
                //else
                //{
                //    res = roleState.init;
                //    Debug.Log("need set roleState init");
                //}
            }
            else
            {
                res          = roleState.init;
                oldRoleState = res;
                // Debug.Log("need set roleState default init");
            }
        }

        return(res);
    }
示例#4
0
    private string getStateStrName(roleState entryName)
    {
        string statestr = strStand;

        switch (entryName)
        {
        case roleState.init:
        {
            statestr = strStand;
        }
        break;

        case roleState.stand:
        {
            statestr = strStand;
        }

        break;

        case roleState.run:
        {
            statestr = strRun;
        }
        break;

        case roleState.attack:
        {
            statestr = strAttack;
        }
        break;

        case roleState.attack2:
        {
            statestr = strAttack2;
        }
        break;

        case roleState.def:
        {
            statestr = strDef;
        }
        break;

        case roleState.die:
        {
            statestr = strDie;
        }
        break;

        default:
        {
            statestr = strStand;
        }
        break;
        }

        return(statestr);
    }
示例#5
0
文件: baseAI.cs 项目: fuzhoustone/csd
    //切换动作状态
    public void PlayAIState(roleState state)
    {
        if (aniCon == null)
        {
            aniCon = this.gameObject.GetComponent <IbaseAnimator>();
        }

        aniCon.PlayState(state);
    }
示例#6
0
 public void initData(GameObject paraObj)
 {
     paraObj.GetComponent <Rigidbody>().freezeRotation = true;
     m_animationController = paraObj.GetComponent <Animation>();
     oldRoleState          = roleState.stand;
     changeRoleState(roleState.stand);
     clearJumpTime();
     // state = stateStand;
     //  roleControl = paraObj.GetComponent<CharacterController>();
 }
示例#7
0
文件: baseAI.cs 项目: fuzhoustone/csd
    public bool isAIState(roleState state)
    {
        bool res = false;

        if (aniCon == null)
        {
            aniCon = this.gameObject.GetComponent <IbaseAnimator>();
        }

        res = aniCon.isInPlayEntry(state);

        return(res);
    }
示例#8
0
文件: baseAI.cs 项目: fuzhoustone/csd
    //根据输入按键来获得动作状态
    public roleState getHopeState(float h, float tmpv, int fireSoft, roleState nowState)
    {
        if (aniCon == null)
        {
            aniCon = this.gameObject.GetComponent <IbaseAnimator>();
        }

        // roleState nowState = aniCon.getRoleNowState();
        roleState res = roleState.init;

        if (nowState == roleState.die)
        {
            res = nowState;
            return(res);
        }

        if (enemyObj == null)                  //无攻击目标
        {
            if ((h == 0.0f) && (tmpv == 0.0f)) //没有输入
            {
                res = roleState.stand;
            }
            else
            {
                res = roleState.run;
            }
        }
        else
        {
            if (fireSoft == 1)
            {
                res = roleState.attack;
            }
            else if (fireSoft == 2)
            {
                res = roleState.attack2;
            }
            else if (fireSoft == 3)
            {
                res = roleState.def;
            }
            else
            {
                res = nowState;
            }
        }

        return(res);
    }
示例#9
0
    public bool isInPlayEntry(roleState stateName)
    {
        bool      res      = false;
        roleState nowState = getRoleNowState();

        if (nowState != stateName)
        {
            res = false;
        }
        else
        {
            res = true;
        }
        return(res);
    }
示例#10
0
    /*
     *  void Start()
     *  {
     *      initData();
     *  }
     */
    public void printRoleState(int pRoleState = -1)
    {
        roleState pState = (roleState)(pRoleState);

        if (pState == roleState.init)
        {
            //获取当前值打log
            pState = getRoleNowState();
        }
        else
        {
            //使用传入的值打log
        }

        Debug.Log("roleState is:" + pState.ToString());
    }
示例#11
0
    public roleState getRoleNowState()
    {
        roleState resState = roleState.init;

        //需把所有状态遍历一遍才可知
        if (animator == null)
        {
            return(resState);
        }

        AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);

        if (info.normalizedTime >= 1.0f)
        {
            resState = roleState.init;
        }
        else
        {
            if (info.IsName(strStand))
            {
                resState = roleState.stand;
            }
            else if (info.IsName(strRun))
            {
                resState = roleState.run;
            }
            else if (info.IsName(strAttack))
            {
                resState = roleState.attack;
            }
            else if (info.IsName(strAttack2))
            {
                resState = roleState.attack2;
            }
            else if (info.IsName(strDef))
            {
                resState = roleState.def;
            }
            else if (info.IsName(strDie))
            {
                resState = roleState.die;
            }
        }


        return(resState);
    }
示例#12
0
    public bool updataRoleControl(float h, float tmpv, bool isfire, bool isJump = false)
    {
        roleState lState = getRoleNowState();

        roleState lHopeState = getHopeState(h, tmpv, isfire, isJump); //按键判断是否改变状态

        bool isChangeToJump = false;

        if ((lState != lHopeState) &&
            (oldRoleState != lHopeState))     //避免重复执行
        {
            if (lHopeState == roleState.jump) //切换成跳跃状态
            {
                isChangeToJump = true;
            }
            oldRoleState = lHopeState;
            changeRoleState(lHopeState);
        }


        return(isChangeToJump);
    }
示例#13
0
    public roleState getHopeState(float h, float tmpv, bool isfire, bool isKeyJump)
    {
        roleState nowState = getRoleNowState();
        roleState res      = roleState.init;

        /*
         * if (nowState == roleState.attack)
         * { //攻击状态中,不能被其它打断
         *  //roleState = roleState.attack;
         *  res = nowState;
         *  return res;
         * }
         */

        if (nowState == roleState.jump)
        { //跳跃状态中,累计时间未到不能切换
            res = nowState;

            if (jumpAllTime <= jumpTime) //跳跃上升中,  //继续保持跳跃
            {
                res = nowState;
                //跳跃的累计时间超过 跳跃时间, 落地切换成站立
            }
            else if (isJumpDownTouch == false) //下降中,继续保持跳跃动作
            {
                res = nowState;
            }
            else
            { //落地,改为站立动作
                clearJumpTime();
                res = roleState.stand;
            }


            return(res);
        }

        else if (nowState == roleState.die)
        {
            res = nowState;
            return(res);
        }

        //接下来都是能打断的状态
        roleState tmpState = roleState.init;

        if ((h == 0.0f) && (tmpv == 0.0f))
        {
            tmpState = roleState.stand;
        }
        else
        {
            tmpState = roleState.run;
        }

        if (isfire)
        {
            tmpState = roleState.attack;
        }
        else if (isKeyJump) //有跳跃按键
        {
            tmpState = roleState.jump;
        }

        res = tmpState;

        return(res);

        /*
         * //其它状态下,
         * if (isfire) {  //按下了攻击键
         *  if ((nowState == roleState.init) //攻击能打断的状态如下
         || (nowState == roleState.stand)
         || (nowState == roleState.run)
         ||     )
         ||     res = roleState.attack;
         || else
         ||     res = nowState;
         ||}
         ||else
         ||{
         || if (isKeyJump) //有跳跃按键
         || {
         ||     res = roleState.jump;
         || }
         || else //无跳跃
         || {
         ||     if ((h == 0.0f) && (tmpv == 0.0f))
         ||         res = roleState.stand;
         ||     else
         ||         res = roleState.run;
         || }
         ||}
         ||
         ||return res;
         */
    }
示例#14
0
    public void changeRoleState(roleState pState)
    {
        switch (pState)
        {
        case roleState.init:
        {
            m_animationController.wrapMode = WrapMode.Loop;
            m_animationController.Play(csDefault);
            //  Debug.LogWarning("change state to stand");
        }
        break;

        case roleState.stand:
        {
            m_animationController.wrapMode = WrapMode.Loop;
            m_animationController.Play(csDefault);
            // Debug.LogWarning("change state to stand");
        }

        break;

        case roleState.run:
        {
            m_animationController.wrapMode = WrapMode.Loop;
            m_animationController.Play(csRun);
            //   Debug.LogWarning("change state to run");
        }
        break;

        case roleState.attack:
        {
            m_animationController.wrapMode = WrapMode.Once;
            // App.Game.character.roleInstance.GetComponent<attcakStartEnd>().attackStart();
            m_animationController.PlayQueued(csAttack1);
            m_animationController.PlayQueued(csAttack2);
            m_animationController.PlayQueued(csAttackEnd);
            // m_animationController.PlayQueued("attack4");
            //   Debug.LogWarning("change state to attack");
        }
        break;

        case roleState.jump: {
            clearJumpTime();
            m_animationController.wrapMode = WrapMode.Loop;
            m_animationController.Play(csJump);
            //  Debug.LogWarning("change state to jump");
        }
        break;

        case roleState.die: {
            m_animationController.wrapMode = WrapMode.Once;
            m_animationController.Play(csDie);
            //  Debug.LogWarning("change state to die");
        }
        break;

        default:
        {
            Debug.LogWarning("change state to default");
        }
        break;
        }
    }
示例#15
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="state"></param>

    public void PlayState(roleState state)
    {
        changeRoleState(state);
    }
示例#16
0
    public void PlayState(roleState stateName)
    {
        string state = getStateStrName(stateName);

        animator.Play(state, mainLayer, 0.0f);  //从第0帧开始播
    }