Пример #1
0
 /// <summary>
 /// 强制进入某个状态
 /// </summary>
 /// <param name="state"></param>
 /// <param name="objs"></param>
 public virtual void SetActionState(State state, params object[] objs)
 {
     if (CurrActionLayerState != null)
     {
         CurrActionLayerState.OnLeave();
     }
     CurrActionLayerState = state;
     CurrActionLayerState.OnEnter(this, objs);
 }
Пример #2
0
    /// <summary>
    /// 每帧的LateUpdate回调
    /// </summary>
    public virtual void LateUpdate()
    {
        if (null != CurrMotionLayerState)
        {
            CurrMotionLayerState.OnLateUpdate();
        }

        if (null != CurrActionLayerState)
        {
            CurrActionLayerState.OnLateUpdate();
        }
    }
Пример #3
0
    /// <summary>
    /// 跳转状态
    /// </summary>
    /// <param name="newState"></param>
    /// <param name="objs"></param>
    public void ChangeState(State newState, params object[] objs)
    {
        //判断状态合法性
        if (!CheckNewStateAvaliable(newState))
        {
            return;
        }

        //缓存上一个状态
        if (null != CurrActionLayerState)
        {
            if (!CurrActionLayerState.CanTransitionTo(newState.PlayerState))
            {
                return;
            }

            CurrActionLayerState.OnLeave();
            PreviousActionLayerState = CurrActionLayerState;
        }

        CurrActionLayerState = newState;
        CurrActionLayerState.OnEnter(this, objs);
    }
Пример #4
0
    /// <summary>
    /// 检索状态合法性
    /// </summary>
    /// <param name="newState"></param>
    /// <returns></returns>
    private bool CheckNewStateAvaliable(State newState)
    {
        if (null == newState || EnumState.NoneState == newState.PlayerState || (null != CurrActionLayerState && CurrActionLayerState.PlayerState == newState.PlayerState && !CurrActionLayerState.AllowSameTransition()))
        {
            string warningMsg = "尝试切换到空状态,错误的使用 to state:" + newState == null ? "null" : newState.ToString();

            //待后期需要关掉此层打印
            Debug.LogWarning(warningMsg);
            return(false);
        }
        return(true);
    }