HeavenStudioPlus/Assets/Scripts/Games/Fireworks/Rocket.cs

72 lines
2.5 KiB
C#
Raw Normal View History

2022-03-13 14:35:22 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Util;
2022-03-13 14:35:22 +00:00
2022-03-14 14:21:05 +00:00
namespace HeavenStudio.Games.Scripts_Fireworks
2022-03-13 14:35:22 +00:00
{
public class Rocket : PlayerActionObject
{
[SerializeField] ParticleSystem particleBarelyEffect;
[SerializeField] private List<ParticleSystem> particleEffects = new List<ParticleSystem>();
[SerializeField] ParticleSystem selectedParticleEffect;
[SerializeField] Animator anim;
2022-03-13 14:35:22 +00:00
public bool isSparkler;
private Fireworks game;
public float startBeat;
public bool applause;
private bool exploded;
private float startY;
2022-03-13 14:35:22 +00:00
void Awake()
2022-03-13 14:35:22 +00:00
{
game = Fireworks.instance;
startY = transform.position.y;
}
public void Init(float beat, int explosionToChoose)
{
startBeat = beat;
game.ScheduleInput(beat, isSparkler ? 1f : 3f, InputType.STANDARD_DOWN, Just, Out, Out);
anim.DoScaledAnimationAsync(isSparkler ? "Sparkler" : "Rocket", isSparkler ? 1f : 0.5f);
selectedParticleEffect = particleEffects[explosionToChoose];
2022-03-13 14:35:22 +00:00
}
void Update()
{
var cond = Conductor.instance;
float normalizedBeat = cond.GetPositionFromBeat(startBeat, isSparkler ? 1f : 3f);
if (!exploded && cond.isPlaying && !cond.isPaused)
{
EasingFunction.Function func = EasingFunction.GetEasingFunction(EasingFunction.Ease.Linear);
float newPosY = func(startY, 7f, normalizedBeat * (isSparkler ? 0.5f : 0.4f));
transform.position = new Vector3(transform.position.x, newPosY, transform.position.z);
}
if (normalizedBeat > 3f && !selectedParticleEffect.isPlaying) Destroy(gameObject);
}
void Just(PlayerActionEvent caller, float state)
{
if (state >= 1f || state <= -1f)
{
Jukebox.PlayOneShotGame("fireworks/miss");
particleBarelyEffect.Play();
anim.gameObject.SetActive(false);
return;
}
Success(caller);
2022-03-13 14:35:22 +00:00
}
void Success(PlayerActionEvent caller)
{
Jukebox.PlayOneShotGame("fireworks/explode_5");
selectedParticleEffect.Play();
anim.gameObject.SetActive(false);
if (applause) Jukebox.PlayOneShot("applause", caller.timer + caller.startBeat + 1f);
}
void Out(PlayerActionEvent caller) { }
2022-03-13 14:35:22 +00:00
}
}