/// <summary> /// Invokes the <paramref name="callback"/> after every elapsed <paramref name="timeout"/>. /// </summary> /// <param name="resouceResourceTrackingScheduler">The <see cref="IResourceTrackingScheduler"/> on which the timeout event will be executed.</param> /// <param name="callback">The callback which to invoke on timeout.</param> /// <param name="timeout">The timeout which to wait before <paramref name="callback"/> should be executed.</param> /// <returns>Returns a <see cref="ITimer"/> which controls the timer.</returns> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public static ITimer SetInterval(this IResourceTrackingScheduler resouceResourceTrackingScheduler, Action callback, TimeSpan timeout) { // validate arguments if (resouceResourceTrackingScheduler == null) throw new ArgumentNullException("resouceResourceTrackingScheduler"); if (callback == null) throw new ArgumentNullException("callback"); // create the timer which will schedule the callback var timer = new TimerControl(timeout, timeout); var token = timer.Token; // create a resource managed by the event loop var untrack = resouceResourceTrackingScheduler.TrackResource(token, timer); // dispose the timer if cancelled token.Register(() => { // untrack the resource untrack(token); // dispose the timer timer.Dispose(); }); // set the timer timer.Set(() => resouceResourceTrackingScheduler.Schedule(callback)); // return the timer return timer; }
//*************************************************************// void Awake () { _meInstance = this; _myText = transform.Find ( "number" ).GetComponent < TextMesh > (); _secondsPassed = 0; //TimerControl.getInstance ().startTimer ( true ); }
/// <summary> /// Adjusts the current setting in the direction specified. /// </summary> /// <param name="adjustmentDirection">The adjustment direction for the current setting.</param> private void AdjustSetting(SettingAdjustmentDirection adjustmentDirection) { if (!this.isInSettingMode) { throw new InvalidOperationException("Attempting to adjust a setting while not in setting mode"); } SettingCategory currentSettingCategory = GetSettingCategory(this.ItemBeingSet); switch (currentSettingCategory) { case SettingCategory.Time: TimeSpan timeSpan = CalculateTimeIncrement(this.ItemBeingSet); if (adjustmentDirection == SettingAdjustmentDirection.Increment) { this.settings.Offset = this.settings.Offset.Add(timeSpan); } else { this.settings.Offset = this.settings.Offset.Subtract(timeSpan); } break; case SettingCategory.Shuffle: this.settings.Shuffle = !this.settings.Shuffle; MediaPlayer.IsShuffled = this.settings.Shuffle; break; case SettingCategory.AlbumArt: this.settings.AlbumArt = !this.settings.AlbumArt; break; // Timer handling case SettingCategory.Timer: if (this.ItemBeingSet == SettingItem.Timer) { if (adjustmentDirection == SettingAdjustmentDirection.Increment) { this.currentlySelectedTimerControl++; if (this.currentlySelectedTimerControl == TimerControl.Last) { this.currentlySelectedTimerControl = TimerControl.Reset; } } else { if (this.currentlySelectedTimerControl <= TimerControl.Reset) { this.currentlySelectedTimerControl = TimerControl.Pause; } else { this.currentlySelectedTimerControl--; } } } break; case SettingCategory.Playlist: if (this.playlists.Count > 0) { if (this.ItemBeingSet == SettingItem.Playlist) { if (adjustmentDirection == SettingAdjustmentDirection.Increment) { this.currentlySelectedPlaylistIndex++; if (this.currentlySelectedPlaylistIndex >= this.playlists.Count) { this.currentlySelectedPlaylistIndex = -1; } } else { this.currentlySelectedPlaylistIndex--; if (this.currentlySelectedPlaylistIndex < -1) { this.currentlySelectedPlaylistIndex = this.playlists.Count - 1; } } } } break; case SettingCategory.Background: if (this.pictures.Count > 0) { if (this.ItemBeingSet == SettingItem.Background) { if (adjustmentDirection == SettingAdjustmentDirection.Increment) { this.currentlySelectedPictureIndex++; if (this.currentlySelectedPictureIndex >= this.pictures.Count) { this.currentlySelectedPictureIndex = -1; } } else { this.currentlySelectedPictureIndex--; if (this.currentlySelectedPictureIndex < -1) { this.currentlySelectedPictureIndex = this.pictures.Count - 1; } } if (this.currentlySelectedPictureIndex == -1) { this.settings.Background = ""; } else { this.settings.Background = pictures[currentlySelectedPictureIndex].Name; } } else { this.settings.Background = ""; this.currentlySelectedPictureIndex = -1; } } this.UpdateBackgroundPictureResource(); break; } }
void Awake() { instance = this; labels = GetComponentsInChildren <TextMesh>(); }