From e7960e1c1e6f9a6b9154968175a9aa470dd91308 Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 21 Jul 2022 17:42:50 +0900 Subject: [PATCH] =?UTF-8?q?Rx=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/MiniGame/Scripts/GameManager.cs | 3 +- .../MyGame/Scenes/MiniGame/Scripts/Player.cs | 62 ++++++++++++------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs index 00b8680a..6fa9da6b 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs @@ -292,8 +292,7 @@ namespace MyGame.Scenes.MiniGame.Scripts SoundManager.Instance.ChangeVolumeUniqueBGM(1f); stageManager.ResetStage(); player.transform.position = characterBeginPos; - player.Stay(); - player.ResetCount(); + player.ResetPlayer(); scoreCount.Value = 0; headerView.ChangeTimeCount(timeLimit); resultManager.Reset(); diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs index 881bdadc..48e6cf5a 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs @@ -31,25 +31,51 @@ namespace MyGame.Scenes.MiniGame.Scripts private bool isFlying; private bool isResult; private bool isHit; + private bool isHole; + private bool isWall; + private float currentFallSpeed; public bool IsHit => isHit; private readonly BoolReactiveProperty isHitStay = new BoolReactiveProperty(); - private IDisposable hitDisposable; + private readonly CompositeDisposable hitCompositeDisposable = new CompositeDisposable(); private IDisposable jumpHoldDisposable; private Coroutine jumpCoroutine; private Coroutine jumpFallCoroutine; private Vector3 basePos; - private int count; + private readonly ReactiveProperty count = new ReactiveProperty(); public IObservable OnHitItem => itemHitCollider.OnTriggerEnter2DAsObservable().TakeUntilDestroy(this); public IObservable OnHitObstacle => obstacleHitCollider.OnTriggerEnter2DAsObservable().TakeUntilDestroy(this); private void Start() { isHitStay.AddTo(this); + count.AddTo(this); + hitCompositeDisposable.AddTo(this); animator = GetComponent(); basePos = transform.localPosition; + + count.Subscribe(x => + { + level1.SetActive(x >= level1Value); + level2.SetActive(x >= level2Value); + level3.SetActive(x >= level3Value); + }).AddTo(this); } - public void Stay(bool force = false) + public void ResetPlayer() + { + Stay(); + ResetCount(); + isJump = false; + isFall = false; + isFlying = false; + isHit = false; + isHitStay.Value = false; + isHole = false; + isWall = false; + isResult = false; + } + + private void Stay(bool force = false) { if (!force && isHit) { @@ -79,7 +105,6 @@ namespace MyGame.Scenes.MiniGame.Scripts return; } - SoundManager.Instance.PlaySE("se_minigame_Jump"); animator?.Play("Brother_pink_jump", 0, 0); isJump = true; isFall = false; @@ -166,7 +191,7 @@ namespace MyGame.Scenes.MiniGame.Scripts Instantiate(hitEffectPrefab, hitPos, Quaternion.identity, transform.parent); animator?.Play("Brother_pink_FallDown"); isHit = true; - hitDisposable?.Dispose(); + hitCompositeDisposable?.Clear(); // ヒット以外動作停止 this.SafeStopCoroutine(jumpCoroutine); @@ -198,10 +223,10 @@ namespace MyGame.Scenes.MiniGame.Scripts isJump = false; isFall = false; isFlying = false; - this.CallWaitForSeconds(hitTime, () => + Observable.Timer(TimeSpan.FromSeconds(hitTime)).Subscribe(_ => { }, () => { isHitStay.Value = true; - this.CallWaitForSeconds(hitWaitTime, () => + Observable.Timer(TimeSpan.FromSeconds(hitWaitTime)).Subscribe(_ => { }, () => { isHit = false; isHitStay.Value = false; @@ -213,9 +238,9 @@ namespace MyGame.Scenes.MiniGame.Scripts { Stay(); } - }); - }); - }).AddTo(this); + }).AddTo(hitCompositeDisposable); + }).AddTo(hitCompositeDisposable); + }).AddTo(hitCompositeDisposable); }); } @@ -233,21 +258,12 @@ namespace MyGame.Scenes.MiniGame.Scripts public void AddCount() { SoundManager.Instance.PlaySE("se_minigame_ItemGet"); - count++; - UpdateCount(); + count.Value++; } - - private void UpdateCount() + + private void ResetCount() { - level1.SetActive(count >= level1Value); - level2.SetActive(count >= level2Value); - level3.SetActive(count >= level3Value); - } - - public void ResetCount() - { - count = 0; - UpdateCount(); + count.Value = 0; } } } \ No newline at end of file