Ejemplo n.º 1
0
    /// <summary>
    /// 状态机改变状态
    /// </summary>
    /// <param name="stateEnum"></param>
    /// <returns></returns>
    public bool ChangeState(AIStateEnum stateEnum)
    {
        if (!stateMap.ContainsKey(stateEnum))
        {
            Debug.Log("没有这个状态");
            return(false);
        }

        if (state != null && state.type == stateEnum)
        {
            return(false);
        }
        //如果当前正在执行状态,停止当前状态并退出
        if (state != null)
        {
            state.ExitState();
            aiAttribute.StopAllCoroutines();
        }

        InputManager.Clear();

        state = stateMap[stateEnum];
        state.EnterState();
        aiAttribute.StartCoroutine(state.ExcuteState());

        return(true);
    }
Ejemplo n.º 2
0
    protected void setAIState(AIStateEnum newState)
    {
        if (State == newState)
        {
            return;
        }
        State = newState;
        switch (State)
        {
        case AIStateEnum.NPC_NORMAL:
            break;

        case AIStateEnum.NPC_MOVE:
            break;

        case AIStateEnum.MPC_CHASE:
            break;

        case AIStateEnum.NPC_ATTACK:
            break;

        default:
            break;
        }
    }
Ejemplo n.º 3
0
    public override IEnumerator ExcuteState()
    {
        //要转换的状态
        AIStateEnum nextState = AIStateEnum.None;

        dir = aiAttribute.GetPlayerDir();

        npcAnim.SetRunDir(dir);

        npcAnim.StartRunAnim();

        while (nextState == AIStateEnum.None)
        {//只要还没退出
            nextState = CheckNextState();

            dir = aiAttribute.GetPlayerDir();

            //播放动画
            npcAnim.SetRunDir(dir);
            //移动留到FixedUpdate后执行
            yield return(new WaitForFixedUpdate());

            //主角移动
            Move();

            yield return(0);
        }

        npcAnim.StopRunAnim();

        aiAttribute.GetComponent <PlayerController>().stateMachine.ChangeState(nextState);

        yield return(null);
    }
Ejemplo n.º 4
0
        //TODO:状态机检测是否可以进入 其它状态
        public bool ChangeState(AIStateEnum s)
        {
            Log.AI("Change State " + GetAttr().gameObject + " state " + s);

            if (state != null && !state.CheckNextState(s))
            {
                return(false);
            }

            if (!stateMap.ContainsKey(s))
            {
                //Debug.LogError("Who Not Has Such State "+GetAttr().gameObject+" state "+s);
                Log.Sys("gameObject No State " + GetAttr().gameObject + " state " + s);
                return(false);
            }

            if (state != null && state.type == s)
            {
                return(false);
            }

            if (state != null)
            {
                state.ExitState();
            }
            state = stateMap [s];
            state.EnterState();
            attribute.StartCoroutine(state.RunLogic());
            return(true);
        }
Ejemplo n.º 5
0
 public override bool CanChangeState(AIStateEnum next)
 {
     if (next == AIStateEnum.COMBAT || next == AIStateEnum.CAST_SKILL)
     {
         return(true);
     }
     return(base.CanChangeState(next));
 }
Ejemplo n.º 6
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.KNOCK_BACK)
     {
         return(false);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 7
0
    /// <summary>
    /// 封装触发改变状态的事件
    /// </summary>
    public void TriggerChangeState(AIStateEnum state)
    {
        EventArgs args = new EventArgs(EveType.ChangeState);

        args.message = state;

        TriggerEvent(args);
    }
Ejemplo n.º 8
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (reliveOk && next == AIStateEnum.IDLE)
     {
         return(true);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 9
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.IDLE)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
 //检测输入shoot命令
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.COMBAT || next == AIStateEnum.CAST_SKILL)
     {
         GetAttr().StartCoroutine(SkillState());
         return(false);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 11
0
    public override void OnEvent(EventArgs args)
    {
        if (args.type == EveType.ChangeState)
        {
            AIStateEnum state = args.GetMessage <AIStateEnum>();

            stateMachine.ChangeState(state);
        }
    }
Ejemplo n.º 12
0
 //先进入MOVE_SHOOT 层状态机,再将状态注入
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.COMBAT || next == AIStateEnum.CAST_SKILL)
     {
         //进入MoveShoot状态机 再压入Combat命令
         GetAttr().StartCoroutine(MoveShoot());
         return(false);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 13
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.CAST_SKILL)
     {
         return(false);
     }
     if (next == AIStateEnum.COMBAT)
     {
         return(false);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 14
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.IDLE)
     {
         return(true);
     }
     if (next == AIStateEnum.COMBAT)
     {
         GetAttr().StartCoroutine(SkillState());
         return(false);
     }
     return(false);
 }
Ejemplo n.º 15
0
    public override IEnumerator ExcuteState()
    {
        //要转换的状态
        AIStateEnum nextState = AIStateEnum.None;

        while (nextState == AIStateEnum.None)
        {//只要待转换的状态还是空
            nextState = CheckNextState();
            //不加这个unity会崩溃
            yield return(0);
        }

        yield return(0);
    }
Ejemplo n.º 16
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.COMBAT)
     {
         Log.AI("Combat receive attack again");
         attackPressTime = Time.time;
         pressAttack     = true;
         return(false);
     }
     if (next == AIStateEnum.CAST_SKILL)
     {
         return(true);
     }
     return(base.CheckNextState(next));
 }
Ejemplo n.º 17
0
        public void ChangeStateIgnoreCurState(AIStateEnum s)
        {
            if (state != null)
            {
                state.ExitState();
                if (stateCor.ContainsKey(state.type))
                {
                    attribute.StopCoroutine(stateCor[state.type]);
                }
            }
            state = stateMap[s];
            state.EnterState();
            var cor = attribute.StartCoroutine(state.RunLogic());

            stateCor[s] = cor;
        }
Ejemplo n.º 18
0
    public override IEnumerator ExcuteState()
    {
        //yield return new WaitForSeconds(0.1f);

        //要转换的状态
        AIStateEnum nextState = AIStateEnum.None;

        while (nextState == AIStateEnum.None)
        {//只要待转换的状态还是空
            nextState = CheckNextState();

            yield return(0);
        }

        yield return(0);
    }
Ejemplo n.º 19
0
        public bool ChangeStateForce(AIStateEnum s)
        {
            Log.AI("Change State Force " + GetAttr().gameObject + " state " + s);

            if (state != null && state.type == s)
            {
                return(false);
            }
            if (state != null)
            {
                state.ExitState();
            }
            state = stateMap [s];
            state.EnterState();
            attribute.StartCoroutine(state.RunLogic());
            return(true);
        }
Ejemplo n.º 20
0
 public override bool CheckNextState(AIStateEnum next)
 {
     if (next == AIStateEnum.DEAD)
     {
         return(true);
     }
     if (next == AIStateEnum.IDLE)
     {
         if (lastMsg != null)
         {
             if (lastMsg.type == MyAnimationEvent.MsgType.EXIT_STUNNED)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 21
0
 public override bool CanChangeState(AIStateEnum next)
 {
     if (next == AIStateEnum.COMBAT || next == AIStateEnum.CAST_SKILL)
     {
         if (!inSkill)
         {
             return(true);
         }
         else
         {
             if (GetAttr().IsMine())
             {
                 //Util.ShowMsg("正在攻击不能使用技能");
             }
             return(false);
         }
     }
     return(base.CanChangeState(next));
 }
Ejemplo n.º 22
0
        public static AIState CreateState(AIStateEnum s)
        {
            switch (s)
            {
            case AIStateEnum.IDLE:
                return(new IdleState());

            case AIStateEnum.COMBAT:
                return(new CombatState());

            case AIStateEnum.DEAD:
                return(new DeadState());

            case AIStateEnum.MOVE:
                return(new MoveState());

            default:
                return(null);
            }
        }
Ejemplo n.º 23
0
    /// <summary>
    /// 切换状态
    /// </summary>
    /// <param name="type"></param>
    /// <returns>是否可以进入新状态</returns>
    public bool ChangeState(AIStateEnum type)
    {
        // 无法进入新状态
        if (State != null && !State.CheckNextState(type))
        {
            return(false);
        }

        // 不包含该状态
        if (!StateDict.ContainsKey(type))
        {
            Log.Error("找不到状态 :" + Enum.GetName(typeof(AIStateEnum), type));
            return(false);
        }

        // 已为当前状态
        if (State != null && State.Type == type)
        {
            return(false);
        }

        // 退出当前状态
        if (State != null)
        {
            State.ExitState();
        }

        // 改变状态
        State = StateDict[type];
        State.EnterState();
        StartCoroutine(State.RunLogic());

        StateType = State.Type;

        return(true);
    }
Ejemplo n.º 24
0
 public virtual bool CheckNextState(AIStateEnum next)
 {
     return(true);
 }
Ejemplo n.º 25
0
 public override bool CheckNextState(AIStateEnum next)
 {
     return(false);
 }
Ejemplo n.º 26
0
 public virtual bool CanChangeState(AIStateEnum next)
 {
     return(CheckNextState(next));
 }