New animation helper function and rhythm rally scaled animations (#285)

This commit is contained in:
Rapandrasmus 2023-02-17 19:45:18 +01:00 committed by GitHub
parent 93d53847e5
commit 14149b57e7
7 changed files with 29 additions and 56 deletions

View file

@ -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) {}
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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;
}
}
}

View file

@ -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)
//{

View file

@ -345,7 +345,7 @@ namespace HeavenStudio.Games
{
new BeatAction.Action(spawnBeat, delegate
{
if (!instance.isPlaying(instance.ballTransporterLeftNPC.GetComponent<Animator>(), "BallTransporterLeftOpened") && !instance.intervalStarted && instance.ballTriggerSetInterval)
if (!instance.ballTransporterLeftNPC.GetComponent<Animator>().IsPlayingAnimationName("BallTransporterLeftOpened") && !instance.intervalStarted && instance.ballTriggerSetInterval)
{
instance.ballTransporterLeftNPC.GetComponent<Animator>().Play("BallTransporterLeftOpen", 0, 0);
instance.ballTransporterRightNPC.GetComponent<Animator>().Play("BallTransporterRightOpen", 0, 0);
@ -449,7 +449,7 @@ namespace HeavenStudio.Games
{
new BeatAction.Action(beat, delegate
{
if (!instance.isPlaying(instance.ballTransporterLeftNPC.GetComponent<Animator>(), "BallTransporterLeftOpened"))
if (!instance.ballTransporterLeftNPC.GetComponent<Animator>().IsPlayingAnimationName("BallTransporterLeftOpened"))
{
instance.ballTransporterLeftNPC.GetComponent<Animator>().Play("BallTransporterLeftOpen", 0, 0);
instance.ballTransporterRightNPC.GetComponent<Animator>().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;
}
}
}

View file

@ -9,6 +9,16 @@ namespace HeavenStudio.Util
float compare = anim.GetCurrentAnimatorStateInfo(0).speed;
return anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= compare && !anim.IsInTransition(0);
}
/// <summary>
/// Returns true if animName is currently playing on animator
/// </summary>
/// <param name="anim">Animator to check</param>
/// <param name="animName">name of animation to look out for</param>
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;
}
/// <summary>
/// Sets animator's progress on an animation based on current song beat between startTime and length