public void AddState(RunState runstate) { if(mRunStates.Contains(runstate)) { Debug.LogError("Runstate already added: " + runstate); return; } mRunStates.Add(runstate); runstate.OnAdded(); Debug.Log("Run state added: " + runstate); }
public bool GoNext(RunState runstate) { // if(!mRunStates.Contains(runstate)) // AddState(runstate); nextRunState = runstate; if(nextRunState!=null) { return DoNextState(); } else { Debug.LogError("No runstate to go to!"); return false; } }
private bool DoNextState() { if (currentRunState == nextRunState){ Debug.LogError(this.ToString() + ": ERROR: Already in state " + currentRunState.ToString()); return false; } if (nextRunState != null) { Debug.Log("CHANGING TO: " + nextRunState); Debug.Log("CHANGING FROM: " + currentRunState); previousRunState = currentRunState; currentRunState = nextRunState; nextRunState = null; if (previousRunState!=null) previousRunState.OnDisabled(); // fire disable event if(RunStateDisabledMethods!=null) RunStateDisabledMethods(previousRunState); currentRunState.OnEnabled(); // fire enable event if(RunStateEnabledMethods!=null) RunStateEnabledMethods(currentRunState); // fire change event if(RunStateChangeEventMethods!= null) RunStateChangeEventMethods(currentRunState); // // report to consol (this may be delayed and NOT read out in order!) // if(previousRunState!=null) // Debug.Log (this.ToString() + ": RunState changed from " + previousRunState.ToString() + " to " + currentRunState.GetType().ToString()); // else // Debug.Log (this.ToString() + ": RunState changed from null to " + currentRunState.GetType().ToString()); return true; } else { Debug.LogError(this.ToString() + ": ERROR: The next Runstate has not been defined!"); return false; } }
private void ReportStateChange(RunState newRunState) { // if(previousRunState!=null) // Debug.Log (this.ToString() + ": State changed from " + previousRunState.ToString() + " to " + newRunState.GetType().ToString()); // else // Debug.Log (this.ToString() + ": State changed to " + newRunState.GetType().ToString()); Debug.Log("CURRENT RUNSTATE: " + currentRunState); }
public void RemoveState(RunState runstate) { if(!mRunStates.Contains(runstate)) { Debug.LogError("Runstate not added: " + runstate); return; } mRunStates.Remove(runstate); runstate.OnRemoved(); Debug.LogError("Runstate removed: " + runstate); }