[Unity] UniRx 初步研究心得 與 Enum 的交互使用
今天研究了一天 累!
寫個心得,直接看Code 巴:
//實際超做 Ex 獲勝視窗的UI //宣告 private bool canClicked = false; // 現在可否可以點擊 public enum Page { Idle, Player, Pet, END } private IReactiveProperty<Page> currentPage = new ReactiveProperty<Page>(Page.Idle); // 現在的頁面的 Observer // 滑鼠點擊 來控制頁面切換 var clickStream = Observable.EveryUpdate().Where(_ => Input.GetMouseButtonDown(0)); clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250))) .Where(xs => xs.Count >= 2) .Subscribe(xs => { if (canClicked) { // 確認��否能點�"� if (currentPage.Value == Page.Idle) { currentPage.Value = Page.Player; //�"�變頁面 } else if (currentPage.Value == Page.Player) { currentPage.Value = Page.Pet; } //canClicked = false; } }); var disposable = new SingleAssignmentDisposable(); disposable.Disposable = Observable.ReturnUnit() .Delay(TimeSpan.FromSeconds(0.3f)) .Do(_ => { titleText.DOText(I18n.get("Click To Continue"), 0.75f); canClicked = true; }) .Subscribe(_ => { Debug.Log("DONE"); disposable.Dispose(); }); } ); currentPage.Where(p => p == Page.Player) // 頁面為 Player 到這裡 .Do(_ => titleText.DOFade(0, 0.3f)) .Delay(TimeSpan.FromSeconds(0.3f)) .Do(_ => playerResultPanel.play(false)) .Delay(TimeSpan.FromSeconds(.9f)) .Do(_ => petResultPanel.show(akr.pets)) .SelectMany(petResultPanel.latch.AsObservable()) .Do(_ => { titleText.DOFade(1, 0.35f); titleText.DOText(I18n.get("Click To Close"), 0.75f); canClicked = true; }) .Subscribe(); currentPage.Where(p => p == Page.Pet) //頁面為Pet 進入到這裡 .Delay(TimeSpan.FromSeconds(0.3f)) .Do(_ => play(AnimUid.MoveOut)) .Subscribe();
留言
張貼留言