From fe4816937339d174d0196909ac47cd3dd0a0417a Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 19 May 2022 15:07:46 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=9E=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E6=A9=9F=E8=83=BD=E9=95=B7=E6=8A=BC=E3=81=97=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marketing/Scripts/ShopCustomizeItem.cs | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopCustomizeItem.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopCustomizeItem.cs index 5ef2ca87..adfe0cc1 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopCustomizeItem.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopCustomizeItem.cs @@ -1,5 +1,6 @@ using System; using UniRx; +using UniRx.Triggers; using UnityEngine; using UnityEngine.UI; @@ -24,8 +25,8 @@ namespace MyGame.Scenes.marketing.Scripts [SerializeField] private Text unlockLevelText; [SerializeField] private Text priceText; [SerializeField] private Transform iconTarget; + float pressTime = .5f; - private IObservable ClickObservable => button.OnClickAsObservable().TakeUntilDestroy(this); public IObservable PurchaseObservable => purchaseSubject; private readonly Subject purchaseSubject = new Subject(); public IObservable SelectObservable => selectSubject; @@ -49,25 +50,43 @@ namespace MyGame.Scenes.marketing.Scripts selectedFrameObject.SetActive(state == ShopCustomizeItemState.Selected); unselectedObject.SetActive(state == ShopCustomizeItemState.Purchased); }).AddTo(this); - ClickObservable.ThrottleFirst(TimeSpan.FromSeconds(.2f)).Subscribe(_ => - { - switch (itemState.Value) + + button.OnPointerDownAsObservable() + .Select(_ => + Observable.Amb( + Observable.Timer(TimeSpan.FromSeconds(pressTime)).Select(x => true), + button.OnPointerUpAsObservable().Select(x => false)) + ) + .Switch() + .Subscribe(longPress => { - case ShopCustomizeItemState.Lock: - break; - case ShopCustomizeItemState.Unlock: - purchaseSubject.OnNext(Unit.Default); - break; - case ShopCustomizeItemState.Purchased: - selectSubject.OnNext(Unit.Default); - break; - case ShopCustomizeItemState.Selected: - detailSubject.OnNext(Unit.Default); - break; - default: - throw new ArgumentOutOfRangeException(); - } - }).AddTo(this); + if (longPress) + { + if (itemState.Value == ShopCustomizeItemState.Purchased) + { + detailSubject.OnNext(Unit.Default); + } + } + else + { + switch (itemState.Value) + { + case ShopCustomizeItemState.Lock: + break; + case ShopCustomizeItemState.Unlock: + purchaseSubject.OnNext(Unit.Default); + break; + case ShopCustomizeItemState.Purchased: + selectSubject.OnNext(Unit.Default); + break; + case ShopCustomizeItemState.Selected: + detailSubject.OnNext(Unit.Default); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + }).AddTo(this); } public void SetState(ShopCustomizeItemState state)