/// <summary> /// Enters the specified state. It will also enter all necessary children state. /// </summary> /// <param name="args"> The arguments passed in the transition. The state's constructor will be chosen to match the arguments specified. /// If args is null, the default constructor will be used.</param> public void Enter(object[] args) { // create an instance of the actual state // call enter on it if (m_StateClass != null) { m_State = (BaseFSMState)System.Activator.CreateInstance(m_StateClass, args); m_State._InternalSetOwnerLogic(this); m_State.SetupDefinition(ref m_StateType, ref m_ChildrenTypes); m_State.Enter(); } // create an instance of the necessary child state machines // call enter on them for (int i = 0; i < m_ChildrenTypes.Count; i++) { FSMStateMachineLogic childSM = new FSMStateMachineLogic(m_ChildrenTypes[i], m_OwnerSM, this); m_ChildSMs.Add(childSM); childSM.Enter(null); if (m_StateType == FSMStateType.Type_OR) { // just add the first child and exit break; } // else add all the children } }
public void Exit() { for (int i = 0; i < this.m_ChildSMs.Count; i++) { this.m_ChildSMs[i].Exit(); } if (this.m_State != null) { this.m_State.Exit(); } this.m_OwnerSM = null; this.m_Parent = null; this.m_State = null; this.m_ChildSMs.Clear(); }
/// <summary> /// Exits the specified state. All children states will be exited before calling exit on m_State /// </summary> public void Exit() { for (int i = 0; i < m_ChildSMs.Count; i++) { m_ChildSMs[i].Exit(); } if (m_State != null) { m_State.Exit(); } // reset all the data in case user is holding on to the object m_OwnerSM = null; m_Parent = null; m_State = null; m_ChildSMs.Clear(); }
public void Enter(object[] args) { if (this.m_StateClass != null) { this.m_State = (BaseFSMState)Activator.CreateInstance(this.m_StateClass, args); this.m_State._InternalSetOwnerLogic(this); this.m_State.SetupDefinition(ref this.m_StateType, ref this.m_ChildrenTypes); this.m_State.Enter(); } for (int i = 0; i < this.m_ChildrenTypes.Count; i++) { FSMStateMachineLogic fSMStateMachineLogic = new FSMStateMachineLogic(this.m_ChildrenTypes[i], this.m_OwnerSM, this); this.m_ChildSMs.Add(fSMStateMachineLogic); fSMStateMachineLogic.Enter(null); if (this.m_StateType == FSMStateType.Type_OR) { break; } } }