public void ChangeSubMachine(int id) { HSMSubStateMachine newSubMachine = null; if (!_subMachineDic.TryGetValue(id, out newSubMachine)) { return; } if (null == newSubMachine) { return; } if (null != _currentSubMachine) { _currentSubMachine.Exit(); } _currentSubMachine = newSubMachine; _currentSubMachine.Enter(); if (null != _currentState) { _currentState.Exit(); _currentState = null; } }
public void Clear() { foreach (var kv in _subMachineDic) { AbstractNode node = kv.Value; HSMSubStateMachine subMachine = (HSMSubStateMachine)node; //UnityEngine.Debug.LogError("Clear:" + subMachine.NodeId); subMachine.Clear(); } ExitState(); }
private void ExitState() { if (null != _currentState) { _currentState.Exit(); _currentState = null; } if (null != _currentSubMachine) { _currentSubMachine.Exit(); _currentSubMachine = null; } }
public bool ChangeDestinationNode(HSMState state) { bool result = false; if (null == state) { return(result); } if (_stateDic.ContainsKey(state.NodeId)) { ChangeState(state.NodeId); result = true; return(result); } else { HSMSubStateMachine parentSubMachine = state.ParentSubMachine; int toSubMachineId = -1; while (null != parentSubMachine) { int id = parentSubMachine.NodeId; if (_subMachineDic.ContainsKey(id)) { toSubMachineId = id; parentSubMachine = null; break; } parentSubMachine = parentSubMachine.ParentSubMachine; } if (toSubMachineId >= 0) { if (null != _currentSubMachine && _currentSubMachine.NodeId != toSubMachineId) { ChangeSubMachine(toSubMachineId); } if (null != _currentSubMachine && _currentSubMachine.NodeId == toSubMachineId) { result = _currentSubMachine.StateMachineTransition.ChangeDestinationNode(state); } } } return(result); }
public virtual void SetParentSubMachine(AbstractNode node) { _parentSubMachine = (HSMSubStateMachine)node; }