From dbe8f7dcf328c2dd48f0e0185ff244bed85be949 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Fri, 17 Feb 2023 19:45:18 +0100 Subject: [PATCH] New animation helper function and rhythm rally scaled animations (#285) --- .../Games/LaunchParty/LaunchPartyRocket.cs | 19 +++++-------------- Assets/Scripts/Games/RhythmRally/Paddlers.cs | 6 +++--- .../Scripts/Games/RhythmRally/RhythmRally.cs | 6 +++--- Assets/Scripts/Games/Ringside/Ringside.cs | 15 +++------------ Assets/Scripts/Games/TapTrial/TapTrial.cs | 15 +++------------ .../Games/WorkingDough/WorkingDough.cs | 14 ++------------ Assets/Scripts/Util/AnimationHelpers.cs | 10 ++++++++++ 7 files changed, 29 insertions(+), 56 deletions(-) diff --git a/Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs b/Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs index c5861fd3..854f6b23 100644 --- a/Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs +++ b/Assets/Scripts/Games/LaunchParty/LaunchPartyRocket.cs @@ -37,7 +37,7 @@ namespace HeavenStudio.Games.Scripts_LaunchParty Jukebox.PlayOneShotGame("launchParty/miss"); Jukebox.PlayOneShotGame("launchParty/rocket_endBad"); string leftOrRight = (UnityEngine.Random.Range(1, 3) == 1) ? "Left" : "Right"; - if (!isPlaying(anim, "RocketBarelyLeft") && !isPlaying(anim, "RocketBarelyRight")) anim.Play("RocketBarely" + leftOrRight, 0, 0); + if (!anim.IsPlayingAnimationName("RocketBarelyLeft") && !anim.IsPlayingAnimationName("RocketBarelyRight")) anim.Play("RocketBarely" + leftOrRight, 0, 0); game.ScoreMiss(0.5); } } @@ -167,7 +167,7 @@ namespace HeavenStudio.Games.Scripts_LaunchParty void JustFamilyRocket(PlayerActionEvent caller, float state) { noInput = true; - if (isPlaying(anim, "RocketBarelyLeft") || isPlaying(anim, "RocketBarelyRight")) + if (anim.IsPlayingAnimationName("RocketBarelyLeft") || anim.IsPlayingAnimationName("RocketBarelyRight")) { number.SetActive(false); anim.SetBool("CanRise", false); @@ -213,7 +213,7 @@ namespace HeavenStudio.Games.Scripts_LaunchParty void JustPartyCracker(PlayerActionEvent caller, float state) { noInput = true; - if (isPlaying(anim, "RocketBarelyLeft") || isPlaying(anim, "RocketBarelyRight")) + if (anim.IsPlayingAnimationName("RocketBarelyLeft") || anim.IsPlayingAnimationName("RocketBarelyRight")) { number.SetActive(false); anim.SetBool("CanRise", false); @@ -257,7 +257,7 @@ namespace HeavenStudio.Games.Scripts_LaunchParty void JustBell(PlayerActionEvent caller, float state) { noInput = true; - if (isPlaying(anim, "RocketBarelyLeft") || isPlaying(anim, "RocketBarelyRight")) + if (anim.IsPlayingAnimationName("RocketBarelyLeft") || anim.IsPlayingAnimationName("RocketBarelyRight")) { number.SetActive(false); anim.SetBool("CanRise", false); @@ -301,7 +301,7 @@ namespace HeavenStudio.Games.Scripts_LaunchParty void JustBowlingPin(PlayerActionEvent caller, float state) { noInput = true; - if (isPlaying(anim, "RocketBarelyLeft") || isPlaying(anim, "RocketBarelyRight")) + if (anim.IsPlayingAnimationName("RocketBarelyLeft") || anim.IsPlayingAnimationName("RocketBarelyRight")) { number.SetActive(false); anim.SetBool("CanRise", false); @@ -355,15 +355,6 @@ namespace HeavenStudio.Games.Scripts_LaunchParty }); } - bool isPlaying(Animator anim, string stateName) - { - if (anim.GetCurrentAnimatorStateInfo(0).IsName(stateName) && - anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f) - return true; - else - return false; - } - void Nothing(PlayerActionEvent caller) {} } } diff --git a/Assets/Scripts/Games/RhythmRally/Paddlers.cs b/Assets/Scripts/Games/RhythmRally/Paddlers.cs index 614fc2fa..1e5ce343 100644 --- a/Assets/Scripts/Games/RhythmRally/Paddlers.cs +++ b/Assets/Scripts/Games/RhythmRally/Paddlers.cs @@ -30,7 +30,7 @@ namespace HeavenStudio.Games.Scripts_RhythmRally if (PlayerInput.Pressed() && !game.IsExpectingInputNow(InputType.STANDARD_DOWN)) { // Play "whoosh" sound here - playerAnim.Play("Swing", 0, 0); + playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ; } } @@ -51,7 +51,7 @@ namespace HeavenStudio.Games.Scripts_RhythmRally bounceBeat = game.serveBeat + game.targetBeat + 0.5f; } - playerAnim.Play("Swing", 0, 0); + playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ; MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Return", hitBeat), new MultiSound.Sound("rhythmRally/ReturnBounce", bounceBeat) }); BounceFX(bounceBeat); game.ball.SetActive(true); @@ -61,7 +61,7 @@ namespace HeavenStudio.Games.Scripts_RhythmRally { MissBall(); Jukebox.PlayOneShot("miss"); - playerAnim.Play("Swing", 0, 0); + playerAnim.DoScaledAnimationAsync("Swing", 0.5f); ; game.missCurve.KeyPoints[0].Position = game.ball.transform.position; game.missCurve.transform.localScale = new Vector3(-state, 1f, 1f); diff --git a/Assets/Scripts/Games/RhythmRally/RhythmRally.cs b/Assets/Scripts/Games/RhythmRally/RhythmRally.cs index f3b48169..945490cd 100644 --- a/Assets/Scripts/Games/RhythmRally/RhythmRally.cs +++ b/Assets/Scripts/Games/RhythmRally/RhythmRally.cs @@ -346,10 +346,10 @@ namespace HeavenStudio.Games if (currentBeat >= bop.startBeat && currentBeat < bop.startBeat + bop.length && !inPose) { if (!playerPrepping && (playerAnim.IsAnimationNotPlaying() || playerState.IsName("Idle") || playerState.IsName("Beat"))) - playerAnim.Play("Beat", 0, 0); + playerAnim.DoScaledAnimationAsync("Beat", 0.5f); if (!opponentPrepping && !opponentServing && !tossing && (opponentAnim.IsAnimationNotPlaying() || opponentState.IsName("Idle") || opponentState.IsName("Beat"))) - opponentAnim.Play("Beat", 0, 0); + opponentAnim.DoScaledAnimationAsync("Beat", 0.5f); } } @@ -398,7 +398,7 @@ namespace HeavenStudio.Games break; } - opponentAnim.Play("Swing", 0, 0); + opponentAnim.DoScaledAnimationAsync("Swing", 0.5f); MultiSound.Play(new MultiSound.Sound[] { new MultiSound.Sound("rhythmRally/Serve", serveBeat), new MultiSound.Sound("rhythmRally/ServeBounce", bounceBeat) }); paddlers.BounceFX(bounceBeat); diff --git a/Assets/Scripts/Games/Ringside/Ringside.cs b/Assets/Scripts/Games/Ringside/Ringside.cs index 3bbc05a4..d4b8b949 100644 --- a/Assets/Scripts/Games/Ringside/Ringside.cs +++ b/Assets/Scripts/Games/Ringside/Ringside.cs @@ -196,7 +196,7 @@ namespace HeavenStudio.Games { if (cond.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1)) { - if (isPlaying(wrestlerAnim, "Idle") && shouldBop) + if (wrestlerAnim.IsPlayingAnimationName("Idle") && shouldBop) { if (UnityEngine.Random.Range(1, 18) == 1) { @@ -214,7 +214,7 @@ namespace HeavenStudio.Games wrestlerAnim.DoScaledAnimationAsync("YeMiss", 0.25f); Jukebox.PlayOneShotGame($"ringside/confusedanswer"); - if (isPlaying(reporterAnim, "IdleReporter")) reporterAnim.Play("IdleLate", 0, 0); + if (reporterAnim.IsPlayingAnimationName("IdleReporter")) reporterAnim.Play("IdleLate", 0, 0); } if (PlayerInput.AltPressed() && !IsExpectingInputNow(InputType.STANDARD_ALT_DOWN) && !shouldNotInput) { @@ -611,7 +611,7 @@ namespace HeavenStudio.Games int randomNumber = UnityEngine.Random.Range(1, 200); if (randomNumber == 1) { - if (isPlaying(reporterAnim, "IdleReporter")) + if (reporterAnim.IsPlayingAnimationName("IdleReporter")) { reporterAnim.DoScaledAnimationAsync("BlinkReporter", 0.5f); } @@ -821,14 +821,5 @@ namespace HeavenStudio.Games } public void Nothing(PlayerActionEvent caller){} - - bool isPlaying(Animator anim, string stateName) - { - if (anim.GetCurrentAnimatorStateInfo(0).IsName(stateName) && - anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f) - return true; - else - return false; - } } } diff --git a/Assets/Scripts/Games/TapTrial/TapTrial.cs b/Assets/Scripts/Games/TapTrial/TapTrial.cs index 363779b9..5eb1b896 100644 --- a/Assets/Scripts/Games/TapTrial/TapTrial.cs +++ b/Assets/Scripts/Games/TapTrial/TapTrial.cs @@ -129,9 +129,9 @@ namespace HeavenStudio.Games { if (Conductor.instance.ReportBeat(ref lastReportedBeat)) { - if (isPlaying(monkeys[0], "Idle")) monkeys[0].DoScaledAnimationAsync("Bop", 0.5f); - if (isPlaying(monkeys[1], "Idle")) monkeys[1].DoScaledAnimationAsync("Bop", 0.5f); - if (isPlaying(player.anim, "Idle")) player.anim.DoScaledAnimationAsync("Bop", 0.5f); + if (monkeys[0].IsPlayingAnimationName("Idle")) monkeys[0].DoScaledAnimationAsync("Bop", 0.5f); + if (monkeys[1].IsPlayingAnimationName("Idle")) monkeys[1].DoScaledAnimationAsync("Bop", 0.5f); + if (player.anim.IsPlayingAnimationName("Idle")) player.anim.DoScaledAnimationAsync("Bop", 0.5f); } else if (Conductor.instance.songPositionInBeats < lastReportedBeat) { @@ -489,15 +489,6 @@ namespace HeavenStudio.Games } #endregion - bool isPlaying(Animator anim, string stateName) - { - if (anim.GetCurrentAnimatorStateInfo(0).IsName(stateName) && - anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f) - return true; - else - return false; - } - //this is the orig way for input handling //public void CreateTap(float beat, int type = 0) //{ diff --git a/Assets/Scripts/Games/WorkingDough/WorkingDough.cs b/Assets/Scripts/Games/WorkingDough/WorkingDough.cs index c803c031..02e767a7 100644 --- a/Assets/Scripts/Games/WorkingDough/WorkingDough.cs +++ b/Assets/Scripts/Games/WorkingDough/WorkingDough.cs @@ -345,7 +345,7 @@ namespace HeavenStudio.Games { new BeatAction.Action(spawnBeat, delegate { - if (!instance.isPlaying(instance.ballTransporterLeftNPC.GetComponent(), "BallTransporterLeftOpened") && !instance.intervalStarted && instance.ballTriggerSetInterval) + if (!instance.ballTransporterLeftNPC.GetComponent().IsPlayingAnimationName("BallTransporterLeftOpened") && !instance.intervalStarted && instance.ballTriggerSetInterval) { instance.ballTransporterLeftNPC.GetComponent().Play("BallTransporterLeftOpen", 0, 0); instance.ballTransporterRightNPC.GetComponent().Play("BallTransporterRightOpen", 0, 0); @@ -449,7 +449,7 @@ namespace HeavenStudio.Games { new BeatAction.Action(beat, delegate { - if (!instance.isPlaying(instance.ballTransporterLeftNPC.GetComponent(), "BallTransporterLeftOpened")) + if (!instance.ballTransporterLeftNPC.GetComponent().IsPlayingAnimationName("BallTransporterLeftOpened")) { instance.ballTransporterLeftNPC.GetComponent().Play("BallTransporterLeftOpen", 0, 0); instance.ballTransporterRightNPC.GetComponent().Play("BallTransporterRightOpen", 0, 0); @@ -797,15 +797,5 @@ namespace HeavenStudio.Games } void Nothing (PlayerActionEvent caller) {} - - //Function to make life for my fingers and my and your eyes easier - bool isPlaying(Animator anim, string stateName) - { - if (anim.GetCurrentAnimatorStateInfo(0).IsName(stateName) && - anim.GetCurrentAnimatorStateInfo(0).normalizedTime < 1.0f) - return true; - else - return false; - } } } diff --git a/Assets/Scripts/Util/AnimationHelpers.cs b/Assets/Scripts/Util/AnimationHelpers.cs index 761b4c4d..1bfd40fa 100644 --- a/Assets/Scripts/Util/AnimationHelpers.cs +++ b/Assets/Scripts/Util/AnimationHelpers.cs @@ -9,6 +9,16 @@ namespace HeavenStudio.Util float compare = anim.GetCurrentAnimatorStateInfo(0).speed; return anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= compare && !anim.IsInTransition(0); } + /// + /// Returns true if animName is currently playing on animator + /// + /// Animator to check + /// name of animation to look out for + public static bool IsPlayingAnimationName(this Animator anim, string animName) + { + float compare = anim.GetCurrentAnimatorStateInfo(0).speed; + return anim.GetCurrentAnimatorStateInfo(0).IsName(animName) && anim.GetCurrentAnimatorStateInfo(0).normalizedTime < compare; + } /// /// Sets animator's progress on an animation based on current song beat between startTime and length