/// <summary> /// Add the specific transtion condition to the list /// </summary> public void AddFSMTransitionCondition(IFSMTransitionCondition fSMTransitionCondition) { if (m_FSMTransitionConditionList.Contains(fSMTransitionCondition) == false) { m_FSMTransitionConditionList.Add(fSMTransitionCondition); } else { Debug.LogErrorFormat("The fsmTransition : {0} aleady have the fSMTransitionCondition : {1}", this.m_FSMTransitionName, fSMTransitionCondition.ToString()); } }
/// <summary> /// Remove the specific transtion condition from the list /// </summary> public void RemoveFSMTransitionCondition(IFSMTransitionCondition fSMTransitionCondition) { if (m_FSMTransitionConditionList.Contains(fSMTransitionCondition) == true) { m_FSMTransitionConditionList.Remove(fSMTransitionCondition); } else { Debug.LogErrorFormat("The fsmTransition : {0} do not have the fSMTransitionCondition : {1}", this.m_FSMTransitionName, fSMTransitionCondition.ToString()); } }
/// <summary> /// The constructor of the transition class /// </summary> public FSMTransition(FSMState fsmState, FSMState nextFSMState, IFSMTransitionCondition[] fsmTransitionConditionArray) { this.m_FSMTransitionName = string.Format("{0}->{1}", fsmState.FSMStateName, nextFSMState.FSMStateName); this.m_NextFSMState = nextFSMState; for (int i = 0; i < fsmTransitionConditionArray.Length; i++) { IFSMTransitionCondition fsmTransitionCondition = fsmTransitionConditionArray[i]; this.AddFSMTransitionCondition(fsmTransitionCondition); } }
/// <summary> /// The Initialize function before the finite state machine system running /// </summary> public void OnInitialize() { m_Entry = new FSMEntry("FSMEntry"); IFSMTransitionCondition[] entryFSMTransitionConditionArray = new IFSMTransitionCondition[1] { new FSMDefaultTransitionCondition() }; m_Entry.AddTransition(m_DefaultFSMState, entryFSMTransitionConditionArray); AddState(m_Entry); this.m_CurrentFSMState = m_Entry; }
/// <summary> /// Check every condition in the list /// </summary> public bool CheckTransitionList() { bool ifAllMatch = true; for (int i = 0; i < this.m_FSMTransitionConditionList.Count; i++) { IFSMTransitionCondition fsmTransitionConditionList = this.m_FSMTransitionConditionList[i]; if (fsmTransitionConditionList.CheckCondition() == false) { ifAllMatch = false; break; } } return(ifAllMatch); }