예제 #1
0
		public void DoTransition(Transition transition)
		{
			if (transition.Value == Transition.Null)
				Debug.LogError("(ERROR) Finite State Machine: Transition is set to <null>");
			else
			{
				StateID id = currentState.GetCurrentState(transition);
				if (id.Value == StateID.Null)
					Debug.LogError("(ERROR) Finite State Machine: State " + id.ToString() + " does not have target state " + transition.ToString() + " for transition.");
				else
				{
					currentStateID = id;
					foreach(BaseFSMState s in states)
					{
						if (s.ID == currentStateID)
						{
							currentState.DoBeforeLeavingState();
							currentState = s;
							currentState.DoBeforeEnteringState();
							break;
						}
					}
				}
			}
		}
예제 #2
0
		public void AddState(BaseFSMState state)
		{
			if (state == null)
				Debug.LogError("(ERROR) Finite State Machine: State cannot be <null>");
			else
			{
				foreach(BaseFSMState s in states)
				{
					if (state.ID == s.ID)
					{
						Debug.LogError("(ERROR) Finite State Machine: State  + " + state.ID.ToString() + " was already added.");
						return;
					}
				}

				states.Add (state);
				if (states.Count == 1)
				{
					currentState = state;
					currentStateID = state.ID;
				}
			}
		}