Example #1
0
    /// <summary>
    /// 构造函数,实例化manager对象时,同时实例化字典,添加所有状态
    /// </summary>
    /// <param name="playercontroller"></param>
    public RoleFSMStateManager(RoleBehaviour playercontroller)
    {
        currentplayerController        = playercontroller;
        roleStateDic                   = new Dictionary <RoleState, RoleStateBase>();
        roleStateDic[RoleState.Idle]   = new RoleStateIdle(this);
        roleStateDic[RoleState.Run]    = new RoleStateRun(this);
        roleStateDic[RoleState.Attack] = new RoleStateAttack(this);
        roleStateDic[RoleState.Hurt]   = new RoleStateHurt(this);
        roleStateDic[RoleState.Die]    = new RoleStateDie(this);
        roleStateDic[RoleState.Fight]  = new RoleStateFight(this);

        if (roleStateDic.ContainsKey(currentRoleStateEnum))
        {
            currentRoleState = roleStateDic[currentRoleStateEnum];
        }
    }
Example #2
0
    /// <summary>
    /// 实现状态动画切换的功能
    /// </summary>
    /// <param name="state"></param>
    public void ChangeState(RoleState newState)
    {
        //切换状态和当前相同时,返回不做操作
        if (currentRoleStateEnum == newState)
        {
            return;
        }
        if (currentRoleState != null)
        {
            //执行状态切换三步走
            currentRoleState.OnLeaveState();
        }
        //把当前状态改成新传的值
        currentRoleStateEnum = newState;
        currentRoleState     = roleStateDic[currentRoleStateEnum];

        currentRoleState.OnEnterState();
    }