diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/MiniGame.unity b/popcorn/Assets/MyGame/Scenes/MiniGame/MiniGame.unity index 57929a6c..516c6c64 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/MiniGame.unity +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/MiniGame.unity @@ -497,6 +497,8 @@ MonoBehaviour: headerView: {fileID: 2098933370} player: {fileID: 2498033716723453586} stageManager: {fileID: 1870432536} + resultManager: {fileID: 0} + isDebug: 0 --- !u!4 &1870432534 Transform: m_ObjectHideFlags: 0 diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs index 0299b86f..17884084 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs @@ -1,6 +1,7 @@ using System; using UniRx; using UniRx.Triggers; +using UnityEditor; using UnityEngine; namespace MyGame.Scenes.MiniGame.Scripts @@ -24,6 +25,10 @@ namespace MyGame.Scenes.MiniGame.Scripts [SerializeField] private HeaderView headerView; [SerializeField] private Player player; [SerializeField] private StageManager stageManager; + [SerializeField] private ResultManager resultManager; +#if UNITY_EDITOR + [SerializeField] private bool isDebug; +#endif private readonly ReactiveProperty menuState = new ReactiveProperty(); private readonly ReactiveProperty state = new ReactiveProperty(); @@ -55,7 +60,7 @@ namespace MyGame.Scenes.MiniGame.Scripts this.UpdateAsObservable() .Where(_ => menuState.Value == MenuState.Game) - .Where(_ => Input.GetMouseButtonDown(0)) + .Where(_ => Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) .Subscribe(_ => { state.Value = GameState.Play; @@ -74,15 +79,17 @@ namespace MyGame.Scenes.MiniGame.Scripts timerDisposable?.Dispose(); timerDisposable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1f)) .Select(time => (int)(timeLimit - time)) - .TakeWhile(time => time > 0) + .TakeWhile(time => time >= 0) .Subscribe(time => { headerView.ChangeTimeCount(time); }, () => { + state.Value = GameState.Success; }).AddTo(this); break; case GameState.Success: + resultManager.ShowResult(); break; case GameState.Failure: break; @@ -102,7 +109,7 @@ namespace MyGame.Scenes.MiniGame.Scripts player.Move(); // カメラ移動 cameraTransform.position = playerTransform.position.x * Vector3.right + cameraOffset; - if (Input.GetMouseButtonDown(0)) + if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) { player.Jump(); } @@ -116,6 +123,17 @@ namespace MyGame.Scenes.MiniGame.Scripts return; } x.enabled = false; +#if UNITY_EDITOR + var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); + sphere.GetComponent().material.color = Color.red; + sphere.transform.SetLocalScale(.4f); + sphere.transform.position = x.ClosestPoint(playerTransform.position); + sphere.transform.SetPositionZ(-5f); + if (item.ItemType == StageItem.Type.Obstacle && isDebug) + { + EditorApplication.isPaused = true; + } +#endif switch (item.ItemType) { case StageItem.Type.Item1: diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs index 490b03b6..7522b17b 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs @@ -1,6 +1,5 @@ using System; using UniRx; -using UniRx.Diagnostics; using UniRx.Triggers; using UnityEngine; @@ -14,6 +13,7 @@ namespace MyGame.Scenes.MiniGame.Scripts [SerializeField] private float hitTime = 1.5f; [SerializeField] private float hitWaitTime = 1f; private bool isJump; + private bool isPreHit; private readonly BoolReactiveProperty isHit = new BoolReactiveProperty(); private IDisposable hitDisposable; @@ -33,7 +33,7 @@ namespace MyGame.Scenes.MiniGame.Scripts public void Jump() { - if (isJump) + if (isJump || isPreHit) { return; } @@ -52,18 +52,27 @@ namespace MyGame.Scenes.MiniGame.Scripts // こける public void Hit() { + if (isPreHit) + { + return; + } + isPreHit = true; hitDisposable?.Dispose(); // ジャンプが終わるのを待つ - hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Debug("Hit").Subscribe(_ => + hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Subscribe(_ => { + var orgRotation = transform.localRotation; + var orgYAngle = orgRotation.eulerAngles.y; + transform.rotation = Quaternion.identity; this.CallLerp(hitTime, t => { - // transform.SetLocalPositionY(cachePos.y + Mathf.Sin(Mathf.PI * t) * jumpHeight); + transform.localRotation = Quaternion.AngleAxis(orgYAngle + t * (3f * 360), Vector3.up); }, () => { isHit.Value = true; this.CallWaitForSeconds(hitWaitTime, () => { + isPreHit = false; isHit.Value = false; }); });