From 38f17286b821feaa0a8511220cfa82124dbaa409 Mon Sep 17 00:00:00 2001 From: kimura Date: Tue, 30 Nov 2021 18:14:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AC=E3=83=99=E3=83=AB=E3=82=A2=E3=83=83?= =?UTF-8?q?=E3=83=97=E6=BC=94=E5=87=BA=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=81=A8?= =?UTF-8?q?=E3=83=8F=E3=83=BC=E3=83=88=E3=82=B2=E3=83=BC=E3=82=B8=E3=81=AE?= =?UTF-8?q?=E5=8B=95=E3=81=8D=E3=81=8C=E5=90=8C=E6=9C=9F=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/CornField/Scripts/CornField.cs | 23 ++++++++++++---- .../Scenes/Main/Scripts/KitchenManager.cs | 27 ++++++++++++++----- .../Scenes/marketing/Scripts/MarketManager.cs | 14 ++++++---- .../marketing/Scripts/ProductManagement.cs | 20 +++++++++++--- .../Scenes/marketing/Scripts/ShopLevelUp.cs | 7 +++++ .../Scenes/shopping/Scripts/Shopping.cs | 20 +++++++++++--- .../Assets/MyGame/Scripts/GameDataObserver.cs | 23 ++-------------- 7 files changed, 89 insertions(+), 45 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs index 501f0bd6..8b273e08 100644 --- a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornField.cs @@ -83,13 +83,26 @@ public class CornField : MonoBehaviour CoinManager.Instance.ChangeCoin(gameData.Coin); HeartMeter.Instance.Initialize(gameData.ViewedShopLevel, gameData.Heart); - GameDataObserver.Instance.ShopLevelUpdate - .Where(x => x && !isFertilizing) - .Subscribe(x => + + // ハートゲージがフルかつダイアログが開いていない場合レベルアップ + GameDataObserver.Instance.SceneCounter + .DistinctUntilChanged() + .CombineLatest(HeartMeter.Instance.FulledHeart, (count, fulled) => count == 1 && fulled) + .Where(x => x) + .DelaySubscription(TimeSpan.FromSeconds(.4f)) + .Subscribe(_ => { - LocalCacheManager.Save(ShopLevelUp.DataTag, gameData.ViewedShopLevel + 1); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + ShopLevelUp.ShowDialog(gameData.ViewedShopLevel + 1); }).AddTo(this); + + GameDataObserver.Instance.HeartObserver + .DistinctUntilChanged() + .Pairwise() + .Subscribe(pair => + { + HeartMeter.Instance.AddHeart(pair.Current - pair.Previous); + }).AddTo(this); + counterView.Initialize(gameData.CornSeed); additionView.Initialize(0); SetData(); diff --git a/popcorn/Assets/MyGame/Scenes/Main/Scripts/KitchenManager.cs b/popcorn/Assets/MyGame/Scenes/Main/Scripts/KitchenManager.cs index 2abae97f..5c7e5dc9 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/Scripts/KitchenManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Main/Scripts/KitchenManager.cs @@ -67,8 +67,7 @@ public class KitchenManager : MonoBehaviour DestroyImmediate(go); }).AddTo(this); }); - })); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + }); } else if (TutorialManager.Instance.Index == 6) { @@ -100,12 +99,28 @@ public class KitchenManager : MonoBehaviour CoinManager.Instance.ChangeCoin(gameData.Coin); HeartMeter.Instance.Initialize(gameData.ViewedShopLevel, gameData.Heart); - GameDataObserver.Instance.ShopLevelUpdate + + // ハートゲージがフルかつダイアログが開いていない場合レベルアップ + GameDataObserver.Instance.SceneCounter + .DistinctUntilChanged() + .CombineLatest(HeartMeter.Instance.FulledHeart, (count, fulled) => count == 1 && fulled) .Where(x => x) - .Subscribe(x => + .DelaySubscription(TimeSpan.FromSeconds(.4f)) + .Subscribe(_ => { - LocalCacheManager.Save(ShopLevelUp.DataTag, gameData.ViewedShopLevel + 1); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + if (gameData.isFirstPlay) + { + return; + } + ShopLevelUp.ShowDialog(gameData.ViewedShopLevel + 1); + }).AddTo(this); + + GameDataObserver.Instance.HeartObserver + .DistinctUntilChanged() + .Pairwise() + .Subscribe(pair => + { + HeartMeter.Instance.AddHeart(pair.Current - pair.Previous); }).AddTo(this); kitchenView.Initialize(); diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs index 3cc86422..6d09a24e 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/MarketManager.cs @@ -74,12 +74,16 @@ public class MarketManager : MonoBehaviour CoinManager.Instance.ChangeCoin(gameData.Coin); HeartMeter.Instance.Initialize(gameData.ViewedShopLevel, gameData.Heart); - GameDataObserver.Instance.ShopLevelUpdate - .Where(x => x && !market.IsPromotion.Value) - .Subscribe(x => + + // ハートゲージがフルかつダイアログが開いていない場合レベルアップ + GameDataObserver.Instance.SceneCounter + .DistinctUntilChanged() + .CombineLatest(HeartMeter.Instance.FulledHeart, (count, fulled) => count == 1 && fulled) + .Where(x => x) + .DelaySubscription(TimeSpan.FromSeconds(.4f)) + .Subscribe(_ => { - LocalCacheManager.Save(ShopLevelUp.DataTag, gameData.ViewedShopLevel + 1); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + ShopLevelUp.ShowDialog(gameData.ViewedShopLevel + 1); }).AddTo(this); productDataList = SpreadsheetDataManager.Instance.GetBaseDataList(Const.ProductDataSheet); diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ProductManagement.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ProductManagement.cs index 54078aa3..674995e1 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ProductManagement.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ProductManagement.cs @@ -40,12 +40,24 @@ public class ProductManagement : MonoBehaviour var gameData = GameDataManager.GameData; CoinManager.Instance.ChangeCoin(gameData.Coin); HeartMeter.Instance.Initialize(gameData.ViewedShopLevel, gameData.Heart); - GameDataObserver.Instance.ShopLevelUpdate + + // ハートゲージがフルかつダイアログが開いていない場合レベルアップ + GameDataObserver.Instance.SceneCounter + .DistinctUntilChanged() + .CombineLatest(HeartMeter.Instance.FulledHeart, (count, fulled) => count == 1 && fulled) .Where(x => x) - .Subscribe(x => + .DelaySubscription(TimeSpan.FromSeconds(.4f)) + .Subscribe(_ => { - LocalCacheManager.Save(ShopLevelUp.DataTag, gameData.ViewedShopLevel + 1); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + ShopLevelUp.ShowDialog(gameData.ViewedShopLevel + 1); + }).AddTo(this); + + GameDataObserver.Instance.HeartObserver + .DistinctUntilChanged() + .Pairwise() + .Subscribe(pair => + { + HeartMeter.Instance.AddHeart(pair.Current - pair.Previous); }).AddTo(this); // 補充方法設定 diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopLevelUp.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopLevelUp.cs index def4866f..e67bb793 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopLevelUp.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/ShopLevelUp.cs @@ -87,4 +87,11 @@ public class ShopLevelUp : MonoBehaviour LocalCacheManager.Remove(CallbackTag); } } + + public static void ShowDialog(int level, Action onComplete = null) + { + LocalCacheManager.Save(DataTag, level); + LocalCacheManager.Save(CallbackTag, onComplete); + TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + } } diff --git a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/Shopping.cs b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/Shopping.cs index 450333d9..15a1f73e 100644 --- a/popcorn/Assets/MyGame/Scenes/shopping/Scripts/Shopping.cs +++ b/popcorn/Assets/MyGame/Scenes/shopping/Scripts/Shopping.cs @@ -19,12 +19,24 @@ public class Shopping : MonoBehaviour var gameData = GameDataManager.GameData; CoinManager.Instance.ChangeCoin(gameData.Coin); HeartMeter.Instance.Initialize(gameData.ViewedShopLevel, gameData.Heart); - GameDataObserver.Instance.ShopLevelUpdate + + // ハートゲージがフルかつダイアログが開いていない場合レベルアップ + GameDataObserver.Instance.SceneCounter + .DistinctUntilChanged() + .CombineLatest(HeartMeter.Instance.FulledHeart, (count, fulled) => count == 1 && fulled) .Where(x => x) - .Subscribe(x => + .DelaySubscription(TimeSpan.FromSeconds(.4f)) + .Subscribe(_ => { - LocalCacheManager.Save(ShopLevelUp.DataTag, gameData.ViewedShopLevel + 1); - TransitionManager.Instance.LoadSceneAdditive(GameScenes.StoreLevel); + ShopLevelUp.ShowDialog(gameData.ViewedShopLevel + 1); + }).AddTo(this); + + GameDataObserver.Instance.HeartObserver + .DistinctUntilChanged() + .Pairwise() + .Subscribe(pair => + { + HeartMeter.Instance.AddHeart(pair.Current - pair.Previous); }).AddTo(this); // 一覧データ diff --git a/popcorn/Assets/MyGame/Scripts/GameDataObserver.cs b/popcorn/Assets/MyGame/Scripts/GameDataObserver.cs index bdc36c0c..5516f471 100644 --- a/popcorn/Assets/MyGame/Scripts/GameDataObserver.cs +++ b/popcorn/Assets/MyGame/Scripts/GameDataObserver.cs @@ -23,7 +23,8 @@ public class GameDataObserver : SingletonMonoBehaviour private readonly BoolReactiveProperty updateMissionAchieved = new BoolReactiveProperty(); public IReadOnlyReactiveProperty UpdateMissionAchieved => updateMissionAchieved; - public IObservable ShopLevelUpdate { get; private set; } + public IObservable HeartObserver => heartObserver; + public IObservable SceneCounter => sceneCounter; private void Start() { @@ -49,26 +50,6 @@ public class GameDataObserver : SingletonMonoBehaviour hasRecipeObserver.OnNext(gameData.MyRecipes.Length); deliveredBulkOrderObserver.OnNext(gameData.BulkOrderDeliveredCount); }).AddTo(this); - - ShopLevelUpdate = Observable.CombineLatest( - heartObserver.DistinctUntilChanged(), - sceneCounter.DistinctUntilChanged().Delay(TimeSpan.FromSeconds(.4f)), - (heart, sceneCount) => - { - var viewedLevel = GameDataManager.GameData.ViewedShopLevel; - if (viewedLevel == 0 && GameDataManager.GameData.isFirstPlay) - { - return false; - } - var currentLevel = levelList.LastOrDefault(data => data.heart <= heart)?.shopLevel ?? 1; - return currentLevel > viewedLevel && sceneCount == 1; - }) - .DistinctUntilChanged() - .Publish(false) - .RefCount(); -#if UNITY_EDITOR - // ShopLevelUpdate.Subscribe(x => { Debug.Log($"change:{x}"); }); -#endif // ミッション達成チェッカー var missionList = SpreadsheetDataManager.Instance.GetBaseDataList(Const.MissionDataSheet);