public override void UpdateCallback(float deltaTime) { //检测是否正在过渡 if (_isTransition) { if (_t.TransitionCallback()) { DoTransition(_t); _isTransition = false; } return; } base.UpdateCallback(deltaTime); if (_currentState == null) { _currentState = _defaultState; } List <ITransition> ts = _currentState.Transitions; int count = ts.Count; for (int i = 0; i < count; i++) { ITransition t = ts[i]; if (t.ShouldBegin()) { _isTransition = true; _t = t; return; } } _currentState.UpdateCallback(deltaTime); }
/// <summary> /// 重写 由SUNState 中继承来的UpdateCallback方法,从而加入每帧判断是否满足过度条件的逻辑 /// </summary> /// <param name="deltaTime">Delta time.</param> public override void UpdateCallback(float deltaTime) { if (_isTransition) { if (_t.TransitionCallback()) { DoTransition(_t); _isTransition = false; } //如果处于过度状态,不应该执行以下任何的操作 return; } //如果没有处在过度状态 base.UpdateCallback(deltaTime); if (_currentState == null) { _currentState = _defaultState; } //检测每个状态是否满足转换条件如果满足的话,替换当前状态 List <ITransition> ts = _currentState.Transitions; int count = ts.Count; for (int i = 0; i < count; i++) { ITransition t = ts [i]; if (t.ShouldBegin()) { _isTransition = true; //这里就不能直接过度到目标状态了 //DoTransition (t); _t = t; return; } } //让当前状态每帧更新 _currentState.UpdateCallback(deltaTime); }