public bool IsHaveState(StrHash name) { if (!children.TryGetValue(name, out IState inState)) { return(false); } return(true); }
/// <summary> /// Create a new state builder with a specified parent state, parent builder, /// and name for the new state. /// </summary> /// <param name="parentBuilder">The parent builder, or what we will return /// when .End is called.</param> /// <param name="parentState">The parent of the new state to create.</param> /// <param name="name">Name of the state to add.</param> public StateBuilder(TParent parentBuilder, AbstractState parentState, StrHash name) { this.parentBuilder = parentBuilder; // New-up state of the prescrbed type. state = new T(); parentState.AddChild(state, name); }
/// <summary> /// Push another state from the existing dictionary of children to the top of the state stack. /// </summary> public void PushState(StrHash stateName) { // Find the new state and add it IState newState; if (!children.TryGetValue(stateName, out newState)) { throw new ApplicationException("Tried to change to state \"" + stateName + "\", but it is not in the list of children."); } activeChildren.Push(newState); newState.Enter(); }
/// <summary> /// Create a new state as a child of the current state. /// </summary> public void AddChild(IState newState, StrHash stateName) { try { children.Add(stateName, newState); newState.Parent = this; newState.Hash = stateName; } catch (ArgumentException) { throw new ApplicationException("State with name \"" + stateName + "\" already exists in list of children."); } }
public bool IsInState(StrHash name) { if (activeChildren.Count == 0) { return(false); } IState inState; if (!children.TryGetValue(name, out inState)) { return(false); } return(inState == activeChildren.Peek()); }
/// <summary> /// Pops the current state from the stack and pushes the specified one on. /// </summary> public void ChangeState(StrHash stateName) { // Try to find the specified state. IState newState; if (!children.TryGetValue(stateName, out newState)) { throw new ApplicationException("Tried to change to state \"" + stateName + "\", but it is not in the list of children."); } // Exit and pop the current state if (activeChildren.Count > 0) { activeChildren.Pop().Exit(); } // Activate the new state activeChildren.Push(newState); newState.Enter(); }
public void AddState(StrHash name, State state) { rootState.AddChild(state, name); }
/// <summary> /// Create a new state with a specified name and add it as a /// child of the root state. /// </summary> /// <param name="stateName">Name for the new state</param> /// <returns>Builder used to configure the new state</returns> public IStateBuilder <State, StateMachineBuilder> State(StrHash stateName) { return(new StateBuilder <State, StateMachineBuilder>(this, rootState, stateName)); }
/// <summary> /// Create a new state of a specified type with a specified name and add it as a /// child of the root state. /// </summary> /// <typeparam name="T">Type of the state to add</typeparam> /// <param name="stateName">Name for the new state</param> /// <returns>Builder used to configure the new state</returns> public IStateBuilder <T, StateMachineBuilder> State <T>(StrHash stateName) where T : AbstractState, new() { return(new StateBuilder <T, StateMachineBuilder>(this, rootState, stateName)); }
public IStateBuilder <T, TParent> TimeOut(float timeOut, StrHash newState) { state.SetTimeOutAction(timeOut, () => state.Parent.ChangeState(newState)); return(this); }
public IStateBuilder <T, TParent> Event(string identifier, StrHash stateName) { state.SetEvent <EventArgs>(identifier, _ => state.Parent.ChangeState(stateName)); return(this); }
/// <summary> /// Create a child state with the default handler type. /// </summary> /// <param name="name"></param> /// <returns>A state builder object for the new child state</returns> public IStateBuilder <State, IStateBuilder <T, TParent> > State(StrHash name) { return(new StateBuilder <State, IStateBuilder <T, TParent> >(this, state, name)); }
/// <summary> /// Create a named child state with a specified handler type. /// </summary> /// <typeparam name="NewStateT">Handler type for the new state</typeparam> /// <param name="name">String for identifying state in parent</param> /// <returns>A new state builder object for the new child state</returns> public IStateBuilder <NewStateT, IStateBuilder <T, TParent> > State <NewStateT>(StrHash name) where NewStateT : AbstractState, new() { return(new StateBuilder <NewStateT, IStateBuilder <T, TParent> >(this, state, name)); }