/// <summary> /// 失活action /// </summary> /// <param name="action"></param> void DeactiveAction(FSMBaseAction action) { if (_nextActions.ContainsKey(action.GetActionType())) { List <FSMSubsequenceAction> nextactions = _nextActions[action.GetActionType()]; foreach (FSMSubsequenceAction next in nextactions) { next._action.ListenEnd(); } } action.Deactive(); }
/// <summary> /// 添加Action /// </summary> /// <param name="action"></param> public void Addaction(FSMBaseAction action) { if (action == null) { return; } if (_actionSet.ContainsKey(action.GetActionType())) { return; } _actionSet.Add(action.GetActionType(), action); }
/// <summary> /// 初始化状态机 /// </summary> public void Initialize() { foreach (FSMBaseAction action in _actionSet.Values) { action.BuildRelation(); } _currentState = FSMWroldStateFactory.Creat(); _currentState.Initialize(); if (_actionSet.ContainsKey(_defaultAction)) { _currentAction = _actionSet[_defaultAction]; ActiveAction(_currentAction); } else { Debug.LogError("No This Action"); } }
/// <summary> /// 重置状态机 /// </summary> public void Reset() { if (_currentAction != null) { DeactiveAction(_currentAction); _currentAction = null; } if (_actionSet.ContainsKey(_defaultAction)) { _currentAction = _actionSet[_defaultAction]; } if (_currentAction == null) { Debug.LogError("No this Action"); } _isStop = false; _isTransform = true; _currentState = FSMWroldStateFactory.Creat(); }
/// <summary> /// 根据世界条件判断从当前Action 是否可以有过渡的Action 如果有就过渡 /// </summary> void TryGotoNextAction() { if (!_nextActions.ContainsKey(_currentAction.GetActionType())) { return; } List <FSMSubsequenceAction> nextactions = _nextActions[_currentAction.GetActionType()]; FSMSubsequenceAction tempAction = null; foreach (FSMSubsequenceAction sub in nextactions) { UpdateSubAction(sub, ref tempAction); } if (tempAction != null) { DeactiveAction(_currentAction); _currentAction = null; ActiveAction(tempAction._action); _currentAction = tempAction._action; } }
public FSMSubsequenceAction(FSMBaseAction action, FSMWorldState preconditions, int priority) { _action = action; _preconditions = preconditions; _priority = priority; }