From 783b78e1acc9b19bc39afc3b3ce993e2020cee22 Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 8 Jul 2021 12:13:42 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E3=81=99=E3=81=B9=E3=81=A6=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=B3=E3=81=8C=E7=84=A6=E3=81=92=E3=82=8B?= =?UTF-8?q?=E3=81=A8=E5=A4=B1=E6=95=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs index cb88c7e7..9686fbf1 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs @@ -99,7 +99,7 @@ public class CornManager : MonoBehaviour { result.SetValueAndForceNotify(CornResult.Perfect); } - else if (x.Count(c => c == CornCondition.Spilled) == x.Count) // すべてのコーンが飛び出した + else if (x.Count(c => c == CornCondition.Simple) == 0) // すべてのコーンが飛び出した OR すべて焦げた { result.SetValueAndForceNotify(CornResult.Failure); } From 9bdb0e20db8bba9cf9e1a20eda964e719bcf4d21 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 9 Jul 2021 09:44:59 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E5=A4=B1=E6=95=97=E6=99=82=E3=81=AE?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/Cooking/Scripts/CornManager.cs | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs index 9686fbf1..9b6a45f0 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs @@ -16,6 +16,7 @@ public class CornManager : MonoBehaviour [SerializeField] private Transform cornSpawnTarget; [SerializeField] private Corn cornPrefab; [SerializeField] private int cornSpawnCount = 20; + [SerializeField] private int maxFailedCornCount = 10; [SerializeField, ReadOnly] private float baseGrowSpeed = 1f; [SerializeField] private float hotGrowSpeed; [SerializeField] private float baseCornPopTime = 5f; @@ -88,24 +89,35 @@ public class CornManager : MonoBehaviour cornConditions.Add(corn.Condition); } - // すべてのコーンがSeedではなくなったら通知 - Observable.CombineLatest(cornConditions) + var cornConditionsObservable = Observable.CombineLatest(cornConditions).Publish().RefCount(); + + // 焦げたコーンorフライパンを飛び出したコーンが設定値を超えるとFailure + cornConditionsObservable + .FirstOrDefault(x => x.Count(c => c == CornCondition.Burnt || c == CornCondition.Spilled) >= maxFailedCornCount) + .Subscribe(x => + { + if (x == null) return; + SetResult(CornResult.Failure); + }) + .AddTo(compositeDisposable); + + // すべてのコーンがSeedではなくなった場合 + cornConditionsObservable .FirstOrDefault(x => !x.Contains(CornCondition.Seed)) .Subscribe(x => { - cornGrowSpeed.Value = 0f; - isCompleted = true; + if (x == null) return; if (x.Count(c => c == CornCondition.Simple) == x.Count) // すべてのコーンがPopped { - result.SetValueAndForceNotify(CornResult.Perfect); + SetResult(CornResult.Perfect); } else if (x.Count(c => c == CornCondition.Simple) == 0) // すべてのコーンが飛び出した OR すべて焦げた { - result.SetValueAndForceNotify(CornResult.Failure); + SetResult(CornResult.Failure); } else { - result.SetValueAndForceNotify(CornResult.Good); + SetResult(CornResult.Good); } }).AddTo(compositeDisposable); } @@ -130,4 +142,11 @@ public class CornManager : MonoBehaviour throw new ArgumentOutOfRangeException(nameof(condition), condition, null); } } + + private void SetResult(CornResult resultValue) + { + cornGrowSpeed.Value = 0f; + isCompleted = true; + result.SetValueAndForceNotify(resultValue); + } } From a960f2170ae5b4c716feec082bec6126fe50aba7 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 9 Jul 2021 09:46:41 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=A8Dispose=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs | 3 +++ popcorn/Assets/PopcornGameManager.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs index 9b6a45f0..d7e2ebf2 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs @@ -41,6 +41,7 @@ public class CornManager : MonoBehaviour cornArray = new Corn[cornSpawnCount]; result.AddTo(this); cornGrowSpeed.AddTo(this); + compositeDisposable.AddTo(this); } public void RespawnCorn() @@ -63,6 +64,7 @@ public class CornManager : MonoBehaviour cornArray[i] = corn; corn.SetCornProperty(baseCornPopTime, cornBurntDuration); + // 進行速度の変更時、コーン速度変更 cornGrowSpeed.TakeWhile(_ => !isCompleted).Subscribe(x => { // コーンが弾けた後はRedの場合のみ焦げ進行する @@ -80,6 +82,7 @@ public class CornManager : MonoBehaviour .FirstOrDefault() .Subscribe(_ => { + // ThermalCondition.Hot以外では焦げ進行なし if (!isHot) { corn.ChangeGrowSpeed(0f); diff --git a/popcorn/Assets/PopcornGameManager.cs b/popcorn/Assets/PopcornGameManager.cs index 70fe4ba3..71da3599 100644 --- a/popcorn/Assets/PopcornGameManager.cs +++ b/popcorn/Assets/PopcornGameManager.cs @@ -35,6 +35,8 @@ public class PopcornGameManager : MonoBehaviour // Start is called before the first frame update void Start() { + compositeDisposable.AddTo(this); + thermalControl.Condition.Subscribe(x => { cornManager.ChangeGrowSpeed(x); From 86fd7c9b2c6b93b7edeb96784ea9da23d1149094 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 9 Jul 2021 10:04:02 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E3=83=AA=E3=82=B6=E3=83=AB=E3=83=88?= =?UTF-8?q?=E5=87=A6=E7=90=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popcorn/Assets/PopcornGameManager.cs | 79 ++++++++++++++++------------ 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/popcorn/Assets/PopcornGameManager.cs b/popcorn/Assets/PopcornGameManager.cs index 71da3599..f40163a9 100644 --- a/popcorn/Assets/PopcornGameManager.cs +++ b/popcorn/Assets/PopcornGameManager.cs @@ -31,7 +31,6 @@ public class PopcornGameManager : MonoBehaviour private readonly ReactiveProperty state = new ReactiveProperty(GameState.Guide); private readonly CompositeDisposable compositeDisposable = new CompositeDisposable(); - // Start is called before the first frame update void Start() { @@ -59,40 +58,6 @@ public class PopcornGameManager : MonoBehaviour } }).AddTo(this); - cornManager.Result.SkipLatestValueOnSubscribe().Subscribe(x => - { - state.Value = GameState.Result; - thermalControl.StopMeter(); - characterFlower.gameObject.SetActive(false); - characterSweat.gameObject.SetActive(false); - switch (x) - { - case CornResult.Perfect: - perfectResultObject.SetActive(true); - break; - case CornResult.Good: - - goodResultObject.SetActive(true); - break; - case CornResult.Failure: - failureResultObject.SetActive(true); - break; - default: - throw new ArgumentOutOfRangeException(nameof(x), x, null); - } - - // 再度画面タップでリセット - this.UpdateAsObservable() - .Select(_ => Input.GetMouseButton(0)) - .DistinctUntilChanged() - .Skip(1) - .FirstOrDefault(b => b) - .Subscribe(_ => - { - ResetGame(); - }).AddTo(this); - }).AddTo(this); - ResetGame(); } @@ -112,6 +77,49 @@ public class PopcornGameManager : MonoBehaviour private void ResetGame() { compositeDisposable.Clear(); + cornManager.Result.SkipLatestValueOnSubscribe() + .FirstOrDefault() + .DelayFrame(1) + .Subscribe(x => + { + state.Value = GameState.Result; + thermalControl.StopMeter(); + characterFlower.gameObject.SetActive(false); + characterSweat.gameObject.SetActive(false); + this.CallWaitForSeconds(1f, () => + { + + }); + // リザルト表示遅延 + Observable.Timer(TimeSpan.FromMilliseconds(1000)).Subscribe(a => + { + switch (x) + { + case CornResult.Perfect: + perfectResultObject.SetActive(true); + break; + case CornResult.Good: + goodResultObject.SetActive(true); + break; + case CornResult.Failure: + failureResultObject.SetActive(true); + break; + default: + throw new ArgumentOutOfRangeException(nameof(x), x, null); + } + // 再度画面タップでリセット + this.UpdateAsObservable() + .Select(_ => Input.GetMouseButton(0)) + .DistinctUntilChanged() + .Skip(1) + .FirstOrDefault(b => b) + .Subscribe(_ => + { + ResetGame(); + }).AddTo(compositeDisposable); + }).AddTo(compositeDisposable); + }).AddTo(compositeDisposable); + this.UpdateAsObservable() .Select(_ => Input.GetMouseButton(0)) .DistinctUntilChanged() @@ -121,6 +129,7 @@ public class PopcornGameManager : MonoBehaviour { StartGame(); }).AddTo(compositeDisposable); + ResetUI(); thermalControl.ResetMeter(); cornManager.RespawnCorn(); From 46feafdcb401f95e4ec28e87d8d46ed9637fca33 Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 9 Jul 2021 10:06:38 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E3=82=B7=E3=83=BC=E3=83=B3=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=89(=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E7=94=A8)=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popcorn/Assets/PopcornGameManager.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/popcorn/Assets/PopcornGameManager.cs b/popcorn/Assets/PopcornGameManager.cs index f40163a9..87c11ec3 100644 --- a/popcorn/Assets/PopcornGameManager.cs +++ b/popcorn/Assets/PopcornGameManager.cs @@ -4,7 +4,6 @@ using UniRx; using UniRx.Triggers; using UnityEngine; using UnityEngine.EventSystems; -using UnityEngine.SceneManagement; using UnityEngine.UI; public enum GameState @@ -59,6 +58,22 @@ public class PopcornGameManager : MonoBehaviour }).AddTo(this); ResetGame(); + +#if UNITY_EDITOR + this.UpdateAsObservable() + .Where(_ => Input.GetKeyDown(KeyCode.R)) + // 連打防止 + .ThrottleFirst(TimeSpan.FromSeconds(0.1f)) + .Subscribe(_ => UnityEngine.SceneManagement.SceneManager.LoadScene("Cooking")) + .AddTo(this); + + this.UpdateAsObservable() + .Where(_ => Input.GetKeyDown(KeyCode.E)) + // 連打防止 + .ThrottleFirst(TimeSpan.FromSeconds(0.1f)) + .Subscribe(_ => ResetGame()) + .AddTo(this); +#endif } private void ResetUI()