From 179f2cef0dcef23ac8babb05d3b6ba18a0eae47c Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 2 Jul 2021 18:22:06 +0900 Subject: [PATCH] =?UTF-8?q?GameManager=E4=BF=AE=E6=AD=A3/=E6=B8=A9?= =?UTF-8?q?=E5=BA=A6=E7=8A=B6=E6=85=8B=E9=80=9A=E7=9F=A5=E3=81=ABRx?= =?UTF-8?q?=E4=BD=BF=E7=94=A8/=E3=82=B3=E3=83=BC=E3=83=B3=E5=91=A8?= =?UTF-8?q?=E3=82=8A=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 | 49 ++++-- .../Scenes/Cooking/Scripts/ThermalControl.cs | 22 +-- popcorn/Assets/PopcornGameManager.cs | 145 +++--------------- 3 files changed, 74 insertions(+), 142 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs index a3b6f838..37525440 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/CornManager.cs @@ -1,20 +1,45 @@ using System; using UnityEngine; -namespace MyGame.Scenes.Main +public class CornManager : MonoBehaviour { - public class CornManager : MonoBehaviour - { - [SerializeField] private Transform cornSpawnTarget; - [SerializeField] private Corn cornPrefab; - [SerializeField] private int cornSpawnCount = 20; + [SerializeField] private Transform cornSpawnTarget; + [SerializeField] private Corn cornPrefab; + [SerializeField] private int cornSpawnCount = 20; + [SerializeField] private float cornGrowSpeed; + [SerializeField] private float cornHotGrowSpeed; + + private Corn[] cornArray; - private void Start() + private void Start() + { + } + + public void Initialize() + { + cornArray = new Corn[cornSpawnCount]; + } + + public void GenerateCorn() + { + for (int i = 0; i < cornSpawnCount; i++) { - for (int i = 0; i < cornSpawnCount; i++) - { - Instantiate(cornPrefab, cornSpawnTarget); - } + cornArray[i] = Instantiate(cornPrefab, cornSpawnTarget); } } -} \ No newline at end of file + + public void ChangeGrowSpeed(ThermalCondition condition) + { + switch (condition) + { + case ThermalCondition.Cold: + break; + case ThermalCondition.Yellow: + break; + case ThermalCondition.Hot: + break; + default: + throw new ArgumentOutOfRangeException(nameof(condition), condition, null); + } + } +} diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/ThermalControl.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/ThermalControl.cs index 83475fc8..e22bb371 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/ThermalControl.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/ThermalControl.cs @@ -1,4 +1,5 @@ using System; +using UniRx; using Unity.Mathematics; using UnityEngine; @@ -29,17 +30,25 @@ public class ThermalControl : MonoBehaviour [SerializeField] private float coldValue = 0.32f; [SerializeField] private float hotValue = 0.67f; + public IReadOnlyReactiveProperty Condition => condition; + private ReactiveProperty condition; + private void Start() { temperature = 0f; + condition = new ReactiveProperty(ThermalCondition.Cold); thermoMeter.SetScale(coldValue, hotValue); + + condition.DistinctUntilChanged().Subscribe(x => + { + Debug.Log($"cond :{x} temp: {temperature}"); + }).AddTo(this); } private ThermalCondition prevCond; private void Update() - { - var cond = GetCondition(); + { panSpeed = panController.Delta.magnitude * panFactor; if (panSpeed > deadZone) { @@ -47,7 +56,7 @@ public class ThermalControl : MonoBehaviour } else { - if (cond == ThermalCondition.Hot) + if (condition.Value == ThermalCondition.Hot) { temperature += hotIncreaseSpeed * Time.deltaTime; } @@ -58,12 +67,7 @@ public class ThermalControl : MonoBehaviour } temperature = Mathf.Clamp01(temperature); thermoMeter.SetValue(temperature); - - if (cond != prevCond) - { - Debug.Log($"cond :{cond} temp: {temperature}"); - prevCond = cond; - } + condition.Value = GetCondition(); } public ThermalCondition GetCondition() diff --git a/popcorn/Assets/PopcornGameManager.cs b/popcorn/Assets/PopcornGameManager.cs index a8f9b56a..ddffa74e 100644 --- a/popcorn/Assets/PopcornGameManager.cs +++ b/popcorn/Assets/PopcornGameManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using UniRx; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; @@ -8,143 +9,45 @@ using UnityEngine.UI; public class PopcornGameManager : MonoBehaviour { [SerializeField] private GameObject startingGuide; - [SerializeField] private PowerMeter powerMeter; - [SerializeField] private Text powerResultText; + // [SerializeField] private Text powerResultText; [SerializeField] private Text gameResultText; - [SerializeField] private PanController panController; + + [SerializeField] private ThermalControl thermalControl; + [SerializeField] private ThermoMeter thermoMeter; + [SerializeField] private CornManager cornManager; private Action tapAction; private bool isProgress; - private int gameCount; - private int failCount; - private bool isPerfect; - private readonly int maxGameCount = 3; - private readonly int maxFailCount = 2; // Start is called before the first frame update void Start() { - powerResultText.text = ""; gameResultText.text = ""; - startingGuide.SetActive(true); - powerMeter.StopMove(); + // startingGuide.SetActive(true); isProgress = false; - panController.enabled = false; + cornManager.Initialize(); - // タップしたら案内非表示&ゲーム開始 - tapAction = () => + thermalControl.Condition.DistinctUntilChanged().Subscribe(x => { - startingGuide.SetActive(false); - // panController.enabled = true; - GameStart(); - }; + cornManager.ChangeGrowSpeed(x); + }).AddTo(this); + GameReset(); + + // タップ後スタート + GameStart(); + } + + private void Update() + { + } + + private void GameReset() + { + cornManager.GenerateCorn(); } private void GameStart() { - gameCount = 0; - failCount = 0; - isPerfect = true; - powerMeter.StartMove(); - tapAction = () => - { - isProgress = true; - powerMeter.StopMove(); - gameCount++; - var pos = powerMeter.GetCurrentPosisiton(); - Debug.Log($"tap! {pos}"); - // 判定 - CheckQuality(pos); - - this.CallWaitForSeconds(1f, () => - { - powerResultText.text = ""; - // 失敗 - if (failCount >= maxFailCount) - { - gameResultText.text = "失敗!"; - powerMeter.gameObject.SetActive(false); - tapAction = () => { }; - panController.enabled = false; - this.CallWaitForSeconds(2f, () => - { - gameResultText.text = "タップでリスタート"; - tapAction = () => { - { - SceneManager.LoadScene("Main"); - }}; - isProgress = false; - }); - return; - } - - // 成功 - if (gameCount >= maxGameCount) - { - gameResultText.text = "成功!"; - if (isPerfect) - { - gameResultText.text = "大成功!"; - } - powerMeter.gameObject.SetActive(false); - tapAction = () => { }; - panController.enabled = false; - this.CallWaitForSeconds(2f, () => - { - gameResultText.text = "タップでリスタート"; - tapAction = () => { - { - SceneManager.LoadScene("Main"); - }}; - isProgress = false; - }); - return; - } - isProgress = false; - powerMeter.StartMove(); - }); - }; - } - - private void CheckQuality(float pos) - { - //Perfect=0.45~0.5 - //Good=0.3 - if (pos <= 0.05f) - { - powerResultText.text = "パーフェクト"; - return; - } - if (pos <= 0.2) - { - powerResultText.text = "グッド"; - isPerfect = false; - return; - } - powerResultText.text = "ミス!"; - isPerfect = false; - failCount++; - } - - // Update is called once per frame - void Update() - { - if(Input.GetMouseButtonDown(0)) - { - if (!isProgress) - { - tapAction.Invoke(); - } - } - } - - private bool CheckTap(Vector2 position){ - var eventSystem = EventSystem.current; - var eventDataCurrentPosition = new PointerEventData(eventSystem); - eventDataCurrentPosition.position = position; - List raycastResults = new List(); - eventSystem.RaycastAll(eventDataCurrentPosition, raycastResults); - return raycastResults.Count == 0; } }