예제 #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;
						}
					}
				}
			}
		}
		public void AddTransition(Transition transition, StateID id)
		{
			if (transition.Value == Transition.Null)
				Debug.LogError("(ERROR) Finite State Machine: Current transition is set to <null>");
			else if (id.Value == StateID.Null)
				Debug.LogError("(ERROR) Finite State Machine: Current transitions id is set to <null>");
			else if (transitions.ContainsKey(transition))
				Debug.LogError("(ERROR) Finite State Machine: State " + stateID.ToString() + " already has transition " + transition.ToString());
			else
				transitions.Add(transition, id);
		}
예제 #3
0
		public void DeleteState(StateID id)
		{
			if (id.Value == StateID.Null)
				Debug.LogError("(ERROR) Finite State Machine: State id is set to <null>");
			else
			{
				foreach(BaseFSMState s in states)
				{
					if (id == s.ID)
					{
						states.Remove(s);
						return;
					}
				}
				Debug.LogError("(ERROR) Finite State Machine: State " + id.ToString() + " was not found and can't be deleted.");
			}
		}
예제 #4
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;
				}
			}
		}