From 64a109da4801a87dffdcdb75ce57c8deea56d3d3 Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 28 Jul 2022 11:13:59 +0900 Subject: [PATCH] =?UTF-8?q?add=20BGM=E3=82=B9=E3=83=94=E3=83=BC=E3=83=89?= =?UTF-8?q?=E5=A4=89=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/MiniGame/Scripts/GameManager.cs | 11 ++++++- .../MyGame/Scenes/MiniGame/Scripts/Player.cs | 33 +++++++++++-------- .../Scripts/Managers/SoundManager.cs | 6 ++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs index 3c0592da..5d1b6d63 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/GameManager.cs @@ -138,6 +138,7 @@ namespace MyGame.Scenes.MiniGame.Scripts resultManager.OnClose.ThrottleFirst(TimeSpan.FromMilliseconds(.2f)).Subscribe(_ => { SoundManager.Instance.ChangeVolumeUniqueBGM(1f); + SoundManager.Instance.ChangePitchBGM(1f); UpdatePlayCount(); scoreUpdate.OnNext(Unit.Default); menuState.Value = MenuState.StageSelect; @@ -165,7 +166,6 @@ namespace MyGame.Scenes.MiniGame.Scripts break; case GameState.Success: SoundManager.Instance.PlaySE("se_minigame_End"); - stageManager.StopTimer(); player.Result(); break; case GameState.Failure: @@ -220,6 +220,13 @@ namespace MyGame.Scenes.MiniGame.Scripts state.Value = GameState.Success; }).AddTo(this); + player.CurrentSpeedMultiply.SkipLatestValueOnSubscribe() + .Where(_ => state.Value == GameState.Play) + .Subscribe(x => + { + SoundManager.Instance.ChangePitchBGM(x); + }).AddTo(this); + player.OnHitItem.Where(_ => state.Value == GameState.Play).Subscribe(x => { if (!x.TryGetComponent(out var item)) @@ -267,6 +274,7 @@ namespace MyGame.Scenes.MiniGame.Scripts switch (item.ItemType) { case StageItem.Type.Obstacle: + stageManager.StopTimer(); player.Hit(closestPoint); break; case StageItem.Type.Item1: @@ -299,6 +307,7 @@ namespace MyGame.Scenes.MiniGame.Scripts .Subscribe(x => { resultManager.ShowResult(scoreCount.Value, placeList, stageData); + SoundManager.Instance.ChangePitchBGM(1f); }).AddTo(gameCompositeDisposable); resultManager.OnRetry.ThrottleFirst(TimeSpan.FromSeconds(.2f)).Subscribe(_ => diff --git a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs index fdcca4d2..e802b561 100644 --- a/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs +++ b/popcorn/Assets/MyGame/Scenes/MiniGame/Scripts/Player.cs @@ -40,7 +40,8 @@ namespace MyGame.Scenes.MiniGame.Scripts private bool isResult; private bool isHitStop; private float currentFallSpeed; - private float currentSpeedMultiply; + private readonly ReactiveProperty currentSpeedMultiply = new(); + public IReadOnlyReactiveProperty CurrentSpeedMultiply => currentSpeedMultiply; public bool IsHit => isHit; private readonly CompositeDisposable jumpCompositeDisposable = new CompositeDisposable(); private readonly CompositeDisposable hitCompositeDisposable = new CompositeDisposable(); @@ -55,6 +56,7 @@ namespace MyGame.Scenes.MiniGame.Scripts private void Start() { count.AddTo(this); + currentSpeedMultiply.AddTo(this); jumpCompositeDisposable.AddTo(this); hitCompositeDisposable.AddTo(this); endHitSubject.AddTo(this); @@ -81,7 +83,7 @@ namespace MyGame.Scenes.MiniGame.Scripts isWall = false; isResult = false; isHitStop = false; - currentSpeedMultiply = 1f; + currentSpeedMultiply.Value = 1f; } private void Stay(bool force = false) @@ -95,11 +97,11 @@ namespace MyGame.Scenes.MiniGame.Scripts public void Move() { - if (isHitStay || isWall || isHitStop) + if (isHitStay || isWall) { return; } - transform.AddPositionX(speed * Time.deltaTime * currentSpeedMultiply); + transform.AddPositionX(speed * Time.deltaTime * currentSpeedMultiply.Value); if (isJump || isHit || isFall) { return; @@ -120,7 +122,7 @@ namespace MyGame.Scenes.MiniGame.Scripts isFall = false; var lastFrame = jumpAnimationCurve[jumpAnimationCurve.length - 1]; // 最高点までのジャンプ - var jumpTime = lastFrame.time / currentSpeedMultiply; + var jumpTime = lastFrame.time / currentSpeedMultiply.Value; var jumpCoroutine = MonoBehaviourExtensions.DoCallLerp(jumpTime, t => { transform.SetLocalPositionY(basePos.y + jumpAnimationCurve.Evaluate(t * lastFrame.time)); @@ -172,10 +174,10 @@ namespace MyGame.Scenes.MiniGame.Scripts else { animator.Play("Brother_pink_Glideing_Cancel"); - currentFallSpeed -= fallAcceleration * Time.deltaTime * currentSpeedMultiply; + currentFallSpeed -= fallAcceleration * Time.deltaTime * currentSpeedMultiply.Value; } - var newYPos = transform.localPosition.y + currentFallSpeed * Time.deltaTime * currentSpeedMultiply; + var newYPos = transform.localPosition.y + currentFallSpeed * Time.deltaTime * currentSpeedMultiply.Value; transform.SetLocalPositionY(Mathf.Max(basePos.y, newYPos)); }, () => { @@ -214,6 +216,8 @@ namespace MyGame.Scenes.MiniGame.Scripts isHit = true; isHitStop = true; + var cacheSpeedMultiply = currentSpeedMultiply.Value; + currentSpeedMultiply.Value = 0f; Instantiate(hitEffectPrefab, hitPos, Quaternion.identity, transform.parent); SoundManager.Instance.PlaySE("se_minigame_Collide"); animator?.Play("Brother_pink_FallDown", 0, 0f); @@ -223,7 +227,8 @@ namespace MyGame.Scenes.MiniGame.Scripts hitStopTimer.Subscribe(_ => { isHitStop = false; - animator.speed = currentSpeedMultiply; + currentSpeedMultiply.Value = cacheSpeedMultiply; + animator.speed = currentSpeedMultiply.Value; }).AddTo(hitCompositeDisposable); // HitStop後、Hit跳ね返りアニメーション @@ -236,7 +241,7 @@ namespace MyGame.Scenes.MiniGame.Scripts return; } - var hitJumpCoroutine = MonoBehaviourExtensions.DoCallLerp(diffHeight <= 0f ? 0f : hitJumpTime / currentSpeedMultiply, t => + var hitJumpCoroutine = MonoBehaviourExtensions.DoCallLerp(diffHeight <= 0f ? 0f : hitJumpTime / cacheSpeedMultiply, t => { transform.SetLocalPositionY(cachePosY + hitAnimationCurve.Evaluate(t)); }); @@ -256,11 +261,11 @@ namespace MyGame.Scenes.MiniGame.Scripts // 31フレームまでが落下32からズサー SoundManager.Instance.PlaySE("se_minigame_FallDown"); animator?.PlayInFixedTime("Brother_pink_FallDown", 0, .52f); - animator.speed = currentSpeedMultiply; + animator.speed = currentSpeedMultiply.Value; currentFallSpeed = 0f; isJump = false; isFall = false; - Observable.Timer(TimeSpan.FromSeconds(hitTime / currentSpeedMultiply)).Subscribe(_ => { }, () => + Observable.Timer(TimeSpan.FromSeconds(hitTime / currentSpeedMultiply.Value)).Subscribe(_ => { }, () => { isHitStay = true; Observable.Timer(TimeSpan.FromSeconds(hitWaitTime)).Subscribe(_ => { }, () => @@ -308,8 +313,8 @@ namespace MyGame.Scenes.MiniGame.Scripts .TakeWhile(_ => transform.localPosition.y > baseYPos) .Subscribe(_ => { - currentFallSpeed -= fallAcceleration * Time.deltaTime * currentSpeedMultiply; - var newYPos = transform.localPosition.y + currentFallSpeed * Time.deltaTime * currentSpeedMultiply; + currentFallSpeed -= fallAcceleration * Time.deltaTime * currentSpeedMultiply.Value; + var newYPos = transform.localPosition.y + currentFallSpeed * Time.deltaTime * currentSpeedMultiply.Value; transform.SetLocalPositionY(Mathf.Max(baseYPos, newYPos)); }, onComplete); } @@ -321,7 +326,7 @@ namespace MyGame.Scenes.MiniGame.Scripts public void SetSpeed(ScrollGameDifficulty difficulty) { - currentSpeedMultiply = difficulty switch + currentSpeedMultiply.Value = difficulty switch { ScrollGameDifficulty.Easy => 1f, ScrollGameDifficulty.Normal => normalSpeedMultiply, diff --git a/popcorn/Assets/USAYAUnityLib/Scripts/Managers/SoundManager.cs b/popcorn/Assets/USAYAUnityLib/Scripts/Managers/SoundManager.cs index 635898eb..10a8f80d 100644 --- a/popcorn/Assets/USAYAUnityLib/Scripts/Managers/SoundManager.cs +++ b/popcorn/Assets/USAYAUnityLib/Scripts/Managers/SoundManager.cs @@ -283,6 +283,12 @@ public class SoundManager : SingletonMonoBehaviour { bgmSource.Stop(); bgmSource.clip = null; } + + public void ChangePitchBGM(float pitch) + { + if (!bgmSource) return; + bgmSource.pitch = pitch; + } public void StopSE(string filePath){ var index = seSourceList.FindIndex(playing => playing.Name == filePath); if (index == -1) return;