diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs index fd4f4164..fdcca4d2 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs @@ -197,72 +197,85 @@ namespace MyGame.Scenes.MiniGame.Scripts { return; } - + + jumpCompositeDisposable.Clear(); + hitCompositeDisposable.Clear(); + var cachePosY = transform.localPosition.y; + var groundPos = isHole ? cachePosY : basePos.y; + var diffHeight = cachePosY - basePos.y; + + // Hitアニメーション中に穴に落ちた場合ズサーのみ if (isHit && isHole) { endHitSubject.OnNext(Unit.Default); - } - else - { - Instantiate(hitEffectPrefab, hitPos, Quaternion.identity, transform.parent); - SoundManager.Instance.PlaySE("se_minigame_Collide"); + HitFallDown(groundPos); + return; } isHit = true; isHitStop = true; - hitCompositeDisposable.Clear(); - jumpCompositeDisposable.Clear(); - + Instantiate(hitEffectPrefab, hitPos, Quaternion.identity, transform.parent); + SoundManager.Instance.PlaySE("se_minigame_Collide"); animator?.Play("Brother_pink_FallDown", 0, 0f); animator.speed = 0f; - var hitStopTimer = Observable.Timer(TimeSpan.FromSeconds(isHit && isHole ? 0f : hitStopTime)).Share(); + var hitStopTimer = Observable.Timer(TimeSpan.FromSeconds(hitStopTime)).Share(); hitStopTimer.Subscribe(_ => { isHitStop = false; animator.speed = currentSpeedMultiply; }).AddTo(hitCompositeDisposable); - - var cachePosY = transform.localPosition.y; - var diffHeight = cachePosY - basePos.y; - var groundPos = isHole ? cachePosY : basePos.y; + + // HitStop後、Hit跳ね返りアニメーション + if (isHole) + { + hitStopTimer.Subscribe(_ => + { + HitFallDown(groundPos); + }).AddTo(hitCompositeDisposable); + return; + } + var hitJumpCoroutine = MonoBehaviourExtensions.DoCallLerp(diffHeight <= 0f ? 0f : hitJumpTime / currentSpeedMultiply, t => { transform.SetLocalPositionY(cachePosY + hitAnimationCurve.Evaluate(t)); }); - - // HitStop後、Hit跳ね返りアニメーション hitStopTimer.SelectMany(hitJumpCoroutine).Subscribe(_ => { - // 落下時間不定によりアニメ再生停止 - animator.speed = 0f; + HitFallDown(groundPos); + }).AddTo(hitCompositeDisposable); + } + + private void HitFallDown(float groundPos) + { + // 落下時間不定によりアニメ再生停止 + animator.speed = 0f; + currentFallSpeed = 0f; + FallDown(groundPos, () => + { + // 31フレームまでが落下32からズサー + SoundManager.Instance.PlaySE("se_minigame_FallDown"); + animator?.PlayInFixedTime("Brother_pink_FallDown", 0, .52f); + animator.speed = currentSpeedMultiply; currentFallSpeed = 0f; - FallDown(groundPos, () => + isJump = false; + isFall = false; + Observable.Timer(TimeSpan.FromSeconds(hitTime / currentSpeedMultiply)).Subscribe(_ => { }, () => { - // 31フレームまでが落下32からズサー - SoundManager.Instance.PlaySE("se_minigame_FallDown"); - animator?.PlayInFixedTime("Brother_pink_FallDown", 0, .5f); - animator.speed = currentSpeedMultiply; - currentFallSpeed = 0f; - isJump = false; - isFall = false; - Observable.Timer(TimeSpan.FromSeconds(hitTime / currentSpeedMultiply)).Subscribe(_ => { }, () => + isHitStay = true; + Observable.Timer(TimeSpan.FromSeconds(hitWaitTime)).Subscribe(_ => { }, () => { - isHitStay = true; - Observable.Timer(TimeSpan.FromSeconds(hitWaitTime)).Subscribe(_ => { }, () => + endHitSubject.OnNext(Unit.Default); + isHit = false; + isHitStay = false; + if (isResult) { - endHitSubject.OnNext(Unit.Default); - isHit = false; - isHitStay = false; - if (isResult) - { - Result(); - } - else - { - Stay(); - } - }).AddTo(hitCompositeDisposable); + Result(); + } + else + { + Stay(); + } }).AddTo(hitCompositeDisposable); }).AddTo(hitCompositeDisposable); }).AddTo(hitCompositeDisposable);