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)