public void MoveNext(GamePhase type) { if (currentState != null) { Debug.Log("MoveNext first state " + currentState.ToString()); currentState.OnExit(); } if (type != GamePhase.ResumeGame) { try { String commentary = "State manager go to the state " + type.ToString(); } catch (Exception e) { Debug.Log(e.Message); } GameManager.instance.SetCurrentState(type); Visual.instance.DisableVisualElementsOnStateEnter(); GameLogicEvents.CopyGameActorsToCurrentGame(); SaveLoadHelper.Save(SaveLoadHelper.defaultPrefixString); GameManager.instance.RemoveStateComponentsFromActor(); Visual.instance.UpdateCounters(); } currentState = dictionary[type]; Visual.instance.disableInput(false); currentState.OnEnter(); }
public static void RegisterMainPackageStates(List <MainStates> states, iState package) { foreach (var state in states) { PackageCache.Add(state, package); } }
/// <summary> /// Initializes a StateMachine with a default state defined by owner. Initialization /// includes a reference value identifying the state. /// </summary> /// <param name="defaultState">Default state.</param> /// <param name="stateRef">A StateRef value identifying the state.</param> public StateMachine(iState defaultState, StateRef stateRef) { l_validStates = new Dictionary <StateRef, iState> (); l_validStates.Add(stateRef, defaultState); i_currentState = defaultState; sr_currentStateRef = stateRef; }
public void UseDone(iState user) { if (User == user) { Locked = false; User = null; } }
/// <summary> /// Initializes a state machine in the pre-start state (used for gameplay scenes with a countdown) with a defined target "first" state. /// </summary> /// <param name="stateRefIn">The StateRef pointing to our desired state</param> public StateMachine(StateRef stateRefIn) { iState prestart = new PreStartState(stateRefIn); l_validStates = new Dictionary <StateRef, iState>(); l_validStates.Add(StateRef.PRESTART_STATE, prestart); i_currentState = prestart; sr_currentStateRef = StateRef.PRESTART_STATE; }
public void RegisterMainPackageStates(iState package) { List <MainStates> states = new List <MainStates>() { MainStates.Login }; StateManagerService.RegisterMainPackageStates(states, package); }
public void Use(iState user, bool islock = false) { Locked = islock; if (User != null) { User.LostAsset(this); } User = user; }
public void AddTransition(iState from, iState to, Func <bool> predicate) { if (_transitions.TryGetValue(from.GetType(), out var transitions) == false) { transitions = new List <Transition>(); _transitions[from.GetType()] = transitions; } transitions.Add(new Transition(to, predicate)); }
public void ChangeState(iState <T> newState) { if (currentState != null) { currentState.ExitState(owner); } currentState = newState; currentState.EnterState(owner); }
public void SetState(iState state) { if (state == _CurrentState) { return; } _CurrentState?.OnExit(); _CurrentState = state; _transitions.TryGetValue(_CurrentState.GetType(), out _CurrentTransitions); if (_CurrentTransitions == null) { _CurrentTransitions = EmptyTransitions; } _CurrentState.OnEnter(); }
private iState mState; //当前状态 public void SetState(iState state) { mState = state; }
public static string ExtStatus(this iState value) { string[] values = { "Waiting...", "Playing...", "Pausing...", "Previsious...", "Next..." }; return(values[(int)value]); }
static void Main(string[] args) { _args = args; _lineSb = new StringBuilder(); //Parse Args and determine if this is a CLI or Console mode. if (args.Length > 0 && !_argsRead) { _isCLI = true; foreach (var a in args) { _lineSb.Append(a + " "); } _line = _lineSb.ToString(); _argsRead = true; _args = new string[0]; } else { _readLine = true; _argsRead = true; } Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("={ "); Console.ForegroundColor = ConsoleColor.White; Console.Write("Dice CLI"); Console.ForegroundColor = ConsoleColor.Green; Console.Write(" }="); Console.ForegroundColor = ConsoleColor.White; //if this is a console app then we want to show them how to get help. if (!_isCLI) { Console.WriteLine(""); Console.WriteLine("Type: 'help' for a list of commands"); Console.WriteLine(""); Console.Write(">"); } else { Console.WriteLine(""); Console.WriteLine(""); } _networkService = new NetworkService(); _networkService.Initialize(); var apiUrl = System.Configuration.ConfigurationManager.AppSettings["apiUrl"]; var consolePackage = new HelpState(); consolePackage.RegisterMainPackageStates(consolePackage); var mainLoop = new MainLoopState(); mainLoop.RegisterMainPackageStates(mainLoop); var login = new LoginState(_networkService, apiUrl); login.RegisterMainPackageStates(login); var autoMove = new AutoMoveState(_networkService); autoMove.RegisterMainPackageStates(autoMove); do { //if we are a console app, read the command that is entered. if (_args.Length == 0 && _readLine) { if (!_isTypedTextHidden) { //Read the line input from the console. _line = Console.ReadLine(); } else { //Read the line in a different way. ConsoleKeyInfo key; do { key = Console.ReadKey(true); if (key.Key != ConsoleKey.Enter) { var s = string.Format("{0}", key.KeyChar); _lineSb.Append(s); } } while (key.Key != ConsoleKey.Enter); _line = _lineSb.ToString(); } } //Set read line to true, not it will only be false if we came from a CLI. _readLine = true; var loopReturn = false; if (StateManagerService.IsIdle()) { //If we are idle then we want to check for commands. StateManagerService.SetState(_line); _currentPackage = StateManagerService.GetPackage(); _isTypedTextHidden = _currentPackage.SetState(_line); loopReturn = _currentPackage.Loop(); } else { //If we are not idle, then we want to process the _line for arguments. //get the correct package for the state we are in _currentPackage = StateManagerService.GetPackage(); //process the package state _isTypedTextHidden = _currentPackage.SetState(_line); //do package loop, which contains logic to do stuff. loopReturn = _currentPackage.Loop(); } //if this is a CLI then we just want to exit. if (!_isCLI) { //Prompt or exit. if (!loopReturn) { Console.Write(">"); } else { _line = null; } } else { _line = null; } } while (_line != null); _networkService.Deinitialize(); }
public void PushInNextFrame(iState state, iContext context = null) { nextState = state; nextStateContext = context; }
/// <summary> /// Adds a new state to the list with a reference to the state. /// </summary> /// <returns><c>true</c>, if state was added</returns> /// <param name="newState">New state.</param> /// <param name="stateRef">State reference.</param> public bool AddState(iState newState, StateRef stateRef) { l_validStates.Add(stateRef, newState); return(true); }
public void AddAnyTransition(iState state, Func <bool> predicate) { _AnyTransitions.Add(new Transition(state, predicate)); }
public StateMachine(T owner) { this.owner = owner; currentState = null; }
public void PushState(iState state, iContext context = null) { _stateMachine.PushInNextFrame(state, context); }
public Transition(iState to, Func <bool> condition) { To = to; Condition = condition; }