コード例 #1
0
        public bool ChangeState(string name)
        {
            State next = this.GetStateByName(name);

            if (next != null)
            {
                // save this state, in case you need to transition to it immediately after a non looping state
                _desired_state = next;
            }
            if (_current_transition != null)
            {
                // you can't change state if you're in a transition
                return(false);
            }
            else if (next == null)
            {
                Debug.LogError("Could not find the state: " + name.ToString());
                return(false);
            }
            else if (next != _current_state)
            {
                // find a transition to the next state and make it if possible
                Transition t = _current_state.GetTransitionTo(next);
                if (t != null)
                {
                    _current_transition = t;
                    _current_transition.Start(next);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }