예제 #1
0
        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;
            }
        }
예제 #2
0
 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();
     }
 }
예제 #3
0
        public HSMState GetState(int stateId)
        {
            HSMState state = null;

            if (_stateDic.TryGetValue(stateId, out state))
            {
                return(state);
            }

            return(state);
        }
예제 #4
0
        private void ExitState()
        {
            if (null != _currentState)
            {
                _currentState.Exit();
                _currentState = null;
            }

            if (null != _currentSubMachine)
            {
                _currentSubMachine.Exit();
                _currentSubMachine = null;
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
 public void DoAction(int skillConfigIndex, HSMState toState)
 {
     Debug.Log("DoAction: skillConfigIndex:" + skillConfigIndex + "      nodeId:" + toState.NodeId);
 }