public void ChangeState(Player player, LogicStateDef newState, params object[] args)
        {
            if (newState == LogicStateDef.NONE)
            {
                return;
            }

            if (newState == player._LogicState /* && newState != LogicStateDef.RUN*/)
            {
                return;
            }

            int changeMode = GetStateChangeMode(player, newState);

            if (changeMode == 0)
            {
                return;
            }

            if (player._LogicState != LogicStateDef.NONE)
            {
                //LoggerHelper.Debug(string.Format("Exit state {0}", player._LogicState.ToString()));
                StateList[player._LogicState].Exit(player, args);
            }

            //LoggerHelper.Debug(string.Format("Enter state {0}", newState.ToString()));
            player._LogicState = newState;
            StateList[newState].Enter(player, changeMode, args);
        }
        // 0不可以
        // 1正常切换
        // 2强制切换
        public int GetStateChangeMode(Player player, LogicStateDef newState)
        {
            if (StateMap[LogicStateDef.NONE].ContainsKey(newState))
            {
                return(StateMap[LogicStateDef.NONE][newState]);
            }

            if (StateMap[player._LogicState].ContainsKey(newState))
            {
                return(StateMap[player._LogicState][newState]);
            }

            return(0);
        }
예제 #3
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            ////Debug.Log("On StateEnter ");

            // 为了防止从AnyState再次进入状态导致动作抽风
            animator.SetInteger("action", (int)RepresentStateDef.NONE);

            // 获取当前状态
            RepresentStateDef representState = EntityRepresentStateName.GetStateByHash(stateInfo.shortNameHash);

            if (representState == RepresentStateDef.NONE)
            {
                return;
            }

            PlayerController representEntity = animator.gameObject.GetComponent <PlayerController>();

            if (representEntity == null)
            {
                representEntity = animator.gameObject.transform.parent.GetComponent <PlayerController>();
            }

            if (representEntity == null)
            {
                return;
            }

            Player entity = representEntity.player;

            entity._RepresentState = representState;             // 记录表现状态

            // 获取表现状态对应的逻辑状态
            LogicStateDef logicState = Represent2LogicMap.GetLogicState(representState);

            if (logicState == LogicStateDef.NONE)
            {
                return;
            }

            // 进入逻辑状态
            entity.ChangeState(logicState);
        }
예제 #4
0
 public void ChangeState(LogicStateDef newState, params object[] args)
 {
     _LogicStateManager.ChangeState(this, newState, args);
 }