Exemplo n.º 1
0
        /// <summary>
        /// Stops the state associated with the token. The token must be one that was
        /// returned when the state was started.
        /// </summary>
        /// <param name="token">The token of the state to stop.</param>
        /// <exception cref="ArgumentNullException">token</exception>
        /// <exception cref="InvalidOperationException">
        /// The given token is not from this state tracker
        /// or
        /// the given token is not active
        /// </exception>
        /// <exception cref="InvalidOperationException">Invalid token</exception>
        public void StopState(IStateToken <TStateData> token)
        {
            var timeState = token as TimeStateWrapper;

            if (timeState == null)
            {
                // This can happen when a user somehow
                // obtains a IStateToken<TStateData>
                // that was not returned by this tracker.
                throw new InvalidOperationException("Invalid token");
            }

            if (!tracker.ActiveTokens.Contains(timeState.token))
            {
                throw new InvalidOperationException("The token is not active.");
            }

            tracker.StopState(timeState.token);
        }
        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);
        }