private IEnumerator SimulateAsyncOperationImpl() { float time = randomTimeGenerator.Next(); int currentEventID = eventID; var token = stateTracker.StartState(eventID++); GLDebug.Log("Event Info", "Event started (" + currentEventID + ") and will finish in " + time + " seconds."); yield return(new WaitForSeconds(time)); GLDebug.Log("Event Info", "Event stopped (" + currentEventID + ")."); stateTracker.StopState(token); }
/// <summary> /// Starts a state, and returns a token that can be used to stop it again. /// </summary> /// <param name="stateData">Custom state data. This is useful in cases /// where all the active states needs to be examined. For example, this data /// can be used to identify states externally.</param> /// <param name="currentTime">The current time.</param> /// <param name="maxTime">The maximum amount of time this state should survive past the current time.</param> /// <param name="onTimeOut">An action to call when this state times out.</param> /// <returns>A token that wraps the custom state data and can be used to stop /// the state started with this method.</returns> /// <remarks>For a state to time out, it is necessary for the Update method to /// be called regularly (for example, in a MonoBehaviours Update method).</remarks> public IStateToken <TStateData> StartState( TStateData stateData, float currentTime, float maxTime, Action onTimeOut) { var state = new TimedState { stateData = stateData, timeData = new TimeData() { startTime = currentTime, maxTime = maxTime, onTimeOut = onTimeOut } }; var token = tracker.StartState(state); return(new TimeStateWrapper { token = token }); }