Пример #1
0
        /// <summary>
        /// 进入某一个状态(机),并根据该状态(机)的模式进行相应的处理 by吴江
        /// </summary>
        /// <param name="_event"></param>
        /// <param name="_toEnter"></param>
        /// <param name="_toExit"></param>
        public void EnterStates(Event _event, State _toEnter, State _toExit)
        {
            currentStates.Add(_toEnter);
            if (machine != null && machine.logDebugInfo)
            {
                Debug.Log("FSM Debug: Enter State - " + _toEnter.name + " at " + Time.time);
            }
            _toEnter.OnEnter(_toExit, _toEnter, _event);

            if (_toEnter.children.Count != 0)
            {
                if (_toEnter.mode == State.Mode.Exclusive)//如果为指定初始化模式
                {
                    if (_toEnter.initState != null)
                    {
                        _toEnter.EnterStates(_event, _toEnter.initState, _toExit);
                    }
                    else
                    {
                        Debug.LogError("FSM error: can't find initial state in " + _toEnter.name);
                    }
                }
                else
                { // if ( _toEnter.mode == State.Mode.Parallel )  如果为遍历模式
                    for (int i = 0; i < _toEnter.children.Count; ++i)
                    {
                        _toEnter.EnterStates(_event, _toEnter.children[i], _toExit);
                    }
                }
            }
        }