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 ChangeNode(int toNodeId) { // Debug.LogError("ChangeNode:" + toNodeId); if (IsState(toNodeId)) { HSMState toState = GetState(toNodeId); bool needChange = (null == _currentState || _currentState.NodeId != toState.NodeId); if (needChange) { if ((_autoTransitionState || toState.AutoTransition)) { ChangeState(toNodeId); } else { toState.ChangeToThisState(); } } } else if (IsSubMachine(toNodeId)) { bool needChange = ((null == _currentSubMachine) || (_currentSubMachine.NodeId != toNodeId)); ChangeSubMachine(toNodeId); } else if (null != _stateExit && _stateExit.NodeId == toNodeId) { ChangeExit(); } }
public HSMState GetState(int stateId) { HSMState state = null; if (_stateDic.TryGetValue(stateId, out state)) { return(state); } return(state); }
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 void DoAction(int skillConfigIndex, HSMState toState) { Debug.Log("DoAction: skillConfigIndex:" + skillConfigIndex + " nodeId:" + toState.NodeId); }