diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs index cee24653..70d6017c 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/Market.cs @@ -31,6 +31,9 @@ public class Market : SingletonMonoBehaviour [SerializeField] private CustomerSetting customerSetting; [SerializeField] private CustomerController customerControllerPrefab; + // 暫定 + public float TastingCustomerInterval => customerFlow.TastingCustomerInterval; + public List DisplayFlavors => displayFlavors; private List displayFlavors = new List(); public List ShuffledOrder => shuffledOrder; @@ -59,7 +62,7 @@ public class Market : SingletonMonoBehaviour private int orderIndex; private int oneByOneIndex = 0; private GameData gameData; - + // Start is called before the first frame update void Start() { @@ -333,6 +336,22 @@ public class Market : SingletonMonoBehaviour BrotherPinkView.Instance.SetWalk(); } }).AddTo(this); + + isPromotion.Subscribe(x => + { + if (x) + { + BrotherPinkView.Instance.StartPromotion(); + } + else + { + BrotherPinkView.Instance.StopPromotion(); + if (gameData.TastingCount > 0 && shopState.Value == ShopState.Open) + { + BrotherPinkView.Instance.StartTasting(); + } + } + }).AddTo(this); } @@ -517,8 +536,7 @@ public class Market : SingletonMonoBehaviour isPromotion.Value = true; customerFlow.StartAdWalker(() => { - isPromotion.Value = false; - BrotherPinkView.Instance.StopPromotion(); + isPromotion.Value = false; }); } diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs index 24a1a9bc..8924bc89 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs @@ -17,6 +17,7 @@ public class MarketManager : MonoBehaviour [SerializeField] private MarketCartView cartView; [SerializeField] private BrotherBlueView blueView; [SerializeField] private IncreaseCustomerButtonView rewardButtonView; + [SerializeField] private MarketSignBoardView signBoardView; [SerializeField] private Transform pinkTarget; [SerializeField] private Transform coinPrefab; [SerializeField] private Transform rootTransform; @@ -108,6 +109,7 @@ public class MarketManager : MonoBehaviour cartView.SetStock(startStocks, false); BrotherPinkView.Instance.SetBrotherView(pinkTarget); + // 宣伝ボタン rewardButtonView.RewardButton.ThrottleFirst(TimeSpan.FromSeconds(.3f)).Subscribe(_ => { GetRewardDialog.ShowIncreaseCustomerDialog(() => @@ -153,21 +155,12 @@ public class MarketManager : MonoBehaviour { resetRefreshTimer.OnNext(Unit.Default); }).AddTo(this); - + market.IsPromotion.Subscribe(active => { - if (active) - { - SoundManager.Instance.PlayBGM("bgm_publicity"); - BrotherPinkView.Instance.StartPromotion(); - } - else - { - SoundManager.Instance.PlayBGM("bgm_marketing"); - } + SoundManager.Instance.PlayBGM(active ? "bgm_publicity" : "bgm_marketing"); }).AddTo(this); - // Customerの各アニメーション設定 foreach (var controller in market.CustomerControllerList) { @@ -230,19 +223,67 @@ public class MarketManager : MonoBehaviour .SkipWhile(_ => !gameData.FinishedFlags.HasFlag(TutorialFlag.FirstPlay)) .Subscribe(state => { - Debug.Log($"SetShopView"); SetShopView(state); }).AddTo(this); + + // 宣伝ボタン/試食表示切替 + var tastingComplete = new Subject().AddTo(this); + market.CurrentShopState + .CombineLatest(market.IsPromotion, tastingComplete, (shopState, isPromotion, _) => (shopState == ShopState.Open, isPromotion)) + .Subscribe(x => + { + var (isOpen, isPromotion) = x; + if (isOpen) + { + if (isPromotion) + { + // 宣伝ボタン表示 + rewardButtonView.gameObject.SetActive(true); + signBoardView.SetActiveTastingBoard(false); + } + else if (gameData.TastingCount > 0) + { + rewardButtonView.gameObject.SetActive(false); + signBoardView.SetActiveTastingBoard(true); + BrotherPinkView.Instance.StartTasting(); + BrotherPinkView.Instance.SetTastingCount(gameData.TastingCount); + signBoardView.SetTimer(gameData.TastingCount * (int)market.TastingCustomerInterval, () => + { + BrotherPinkView.Instance.SetTastingCount(gameData.TastingCount); + }, () => + { + // 試食タイマーが終わったら表示更新トリガー + tastingComplete.OnNext(Unit.Default); + BrotherPinkView.Instance.StopTasting(); + }); + } + else + { + BrotherPinkView.Instance.StopTasting(); + rewardButtonView.gameObject.SetActive(true); + signBoardView.SetActiveTastingBoard(false); + } + } + else + { + BrotherPinkView.Instance.StopTasting(); + rewardButtonView.gameObject.SetActive(false); + signBoardView.SetActiveTastingBoard(false); + } + }).AddTo(this); + // CombineLatest動かすのに必要 + tastingComplete.OnNext(Unit.Default); } private void SetShopView(ShopState state) { +#if UNITY_EDITOR + Debug.Log($"SetShopView"); +#endif ShopClosedCompositeDisposable.Clear(); switch (state) { case ShopState.Open: - // 宣伝ボタン表示 - rewardButtonView.gameObject.SetActive(true); BrotherPinkView.Instance.SetNormal(); blueView.OpenAction(); closeSign.SetActive(false); @@ -250,8 +291,6 @@ public class MarketManager : MonoBehaviour case ShopState.Busy: break; case ShopState.Close: - // 宣伝ボタン非表示 - rewardButtonView.gameObject.SetActive(false); if (market.CustomerList.Count(x => x.State.Value == CustomerState.Order) == 0) { BrotherPinkView.Instance.SetSleepy(); diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketSignBoardView.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketSignBoardView.cs index cae8e889..39576af3 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketSignBoardView.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketSignBoardView.cs @@ -1,3 +1,5 @@ +using System; +using UniRx; using UnityEngine; using UnityEngine.UI; @@ -5,15 +7,39 @@ namespace MyGame.Scenes.marketing.Scripts { public class MarketSignBoardView : MonoBehaviour { - private static readonly string remainTimeFormat = "残り{0:D2}:{1:D2}"; + private static readonly string remainTimeFormat = "残り{0:D2}:{1:D2}"; [SerializeField] private Text remainTimeText; [SerializeField] private GameObject normalBoardObject; [SerializeField] private GameObject tastingBoardObject; + private IDisposable timerDispose; + + // 宣伝中は宣伝優先で通常看板 + public void SetActiveTastingBoard(bool active) + { + normalBoardObject.SetActive(!active); + tastingBoardObject.SetActive(active); + } - public void SetTime(int seconds) + private void SetTime(int seconds) { seconds = Mathf.Max(0, seconds); remainTimeText.text = string.Format(remainTimeFormat, Mathf.Min(seconds / 60, 99), seconds % 60); } + + public void SetTimer(int remaining, Action onInterval = null, Action onComplete = null) + { + timerDispose?.Dispose(); + var timer = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1f)) + .Select(x => (int)(remaining - x)) + .TakeWhile(x => x >= 0); + timerDispose = timer.Subscribe(x => + { + SetTime(x); + onInterval?.Invoke(); + }, () => + { + onComplete?.Invoke(); + }).AddTo(this); + } } } \ No newline at end of file