private void UpdateOnMusicStart() { int fm = 0; int ssg = 0; int pcm = 0; int pc = 0; for (int i = 0; i < FMPPartWork.MaxChannelCount; i++) { var unit = _gwork.Mode[i]; switch (unit) { case FMPSoundUnit.FM: { fm++; pc++; } break; case FMPSoundUnit.SSG: { ssg++; pc++; } break; case FMPSoundUnit.PCM: { pcm++; pc++; } break; } _propParts[i].SetSoundUnit(unit); } _propActiveChannelCount.Value = pc; _propFMChannelCount.Value = fm; _propSSGChannelCount.Value = ssg; _propPCMChannelCount.Value = pcm; _propMusicTitle.Value = FMPControl.GetTextData(FMPText.Title); _propMusicCreator.Value = FMPControl.GetTextData(FMPText.Creator); _observeMusicStart.OnNext(Unit.Default); }
public void Awake() { _fmpInfo = null; var handle = GetActiveWindow(); if (handle != System.IntPtr.Zero) { _fmpListener = new FMPMessageListener(); _fmpListener.FMPMessageEvent += (s, e) => { switch (e.Message) { case FMPMessage.StartFMP: { _fmpInfo = FMPControl.GetFMPInfo(); } break; case FMPMessage.EndFMP: { _fmpInfo = null; } break; } }; _fmpListener.AssignHandle(handle); } _fmpInfo = FMPControl.GetFMPInfo(); _currentSceneType = SceneType.Unspecified; this.UpdateAsObservable().Subscribe(_ => FMPWork.Update(_fmpInfo)).AddTo(this); FMPWork.MusicTitle.SubscribeToText(_musicTitle).AddTo(this); FMPWork.MusicCreator.SubscribeToText(_musicCreator).AddTo(this); FMPWork.Status .Select(value => (value != FMPStat.None && (value & FMPStat.Play) != 0) ? "Pause" : "Play") .SubscribeToText(_playOrPauseButton.GetComponentInChildren <UnityEngine.UI.Text>()) .AddTo(this); try { var musics = System.IO.Directory.GetFiles(Application.streamingAssetsPath, "*.owi"); if (musics != null && musics.Length > 0) { int index = 0; _nextMusicButton.OnClickAsObservable().Select(_ => musics[(index++) % musics.Length]) .ObserveOn(Scheduler.ThreadPool) .Subscribe(value => { FMPControl.MusicLoadAndPlay(value); }).AddTo(this); } } catch { } _playOrPauseButton.OnClickAsObservable().Subscribe(_ => { if ((FMPWork.Status.Value & (FMPStat.Pause | FMPStat.Play)) != 0) { FMPControl.MusicPause(); } else { FMPControl.MusicPlay(); } }).AddTo(this); FMPWork.Progress.Subscribe(value => _playProgress.value = value).AddTo(this); FMPWork.PlayTime .Select(value => (new System.DateTime(value.Ticks)).ToString(_timeFormat)) .SubscribeToText(_playTime).AddTo(this); FMPWork.MusicStartEvent.Subscribe(_ => { var sb = new System.Text.StringBuilder(); if (FMPWork.FMChannelCount.Value > 0) { sb.AppendFormat("FM: {0}ch\n", FMPWork.FMChannelCount.Value); } if (FMPWork.SSGChannelCount.Value > 0) { sb.AppendFormat("SSG: {0}ch\n", FMPWork.SSGChannelCount.Value); } if (FMPWork.PCMChannelCount.Value > 0) { sb.AppendFormat("PCM: {0}ch\n", FMPWork.PCMChannelCount.Value); } sb.AppendFormat("Total: {0}ch", FMPWork.ActiveChannelCount); _channelCountInfo.text = sb.ToString(); }).AddTo(this); Observable.Create <Tuple <int, int> >(observer => { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); return(FMPWork.AverageCalorie.Zip( FMPWork.InstantCalorie, (value1, value2) => { return new Tuple <int, int>(value1, value2); }).Subscribe(value => { if (sw.ElapsedMilliseconds > 1000) { observer.OnNext(value); sw.Reset(); sw.Start(); } })); }) .Select(value => { return(string.Format("Calorie\nAvg {0}\nInstant {1}", value.Item1, value.Item2)); }) .SubscribeToText(_calorieInfo) .AddTo(this); ChangeSubScene(SceneType.LevelMeter2011); }