Improved inputs (A SHIT MORE DYNAMIC BETWEEN GAMES) and a whole lot cleaner code in general

This commit is contained in:
Braedon
2022-01-17 00:00:26 -05:00
parent e735f1ccaf
commit 6a05f31506
16 changed files with 405 additions and 774 deletions

View File

@ -40,21 +40,22 @@ namespace RhythmHeavenMania.Util
FindJukebox().GetComponent<AudioSource>().volume = volume;
}
public static void PlayOneShot(string name)
public static void PlayOneShot(string name, bool relyOnBeat = true)
{
GameObject oneShot = new GameObject("oneShot");
AudioSource aus = oneShot.AddComponent<AudioSource>();
aus.playOnAwake = false;
Sound snd = oneShot.AddComponent<Sound>();
snd.relyOnBeat = relyOnBeat;
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
snd.clip = clip;
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
}
public static void PlayOneShotGame(string name)
public static void PlayOneShotGame(string name, bool relyOnBeat = true)
{
if (GameManager.instance.currentGame == name.Split('/')[0])
PlayOneShot($"games/{name}");
PlayOneShot($"games/{name}", relyOnBeat);
}
}

View File

@ -15,6 +15,8 @@ namespace RhythmHeavenMania.Util
private float startTime;
public bool relyOnBeat = true;
private void Start()
{
audioSource = GetComponent<AudioSource>();
@ -23,32 +25,45 @@ namespace RhythmHeavenMania.Util
audioSource.PlayScheduled(Time.time);
startTime = Conductor.instance.songPosition;
if (!relyOnBeat)
{
StartCoroutine(NotRelyOnBeatSound());
}
}
private void Update()
{
if (Conductor.instance.isPaused && !Conductor.instance.isPlaying && pauseTimes == 0)
if (relyOnBeat)
{
audioSource.Pause();
pauseTimes = 1;
print("paused");
}
else if (Conductor.instance.isPlaying && !Conductor.instance.isPaused && pauseTimes == 1)
{
audioSource.Play();
print("played");
pauseTimes = 0;
}
if (Conductor.instance.isPaused && !Conductor.instance.isPlaying && pauseTimes == 0)
{
audioSource.Pause();
pauseTimes = 1;
print("paused");
}
else if (Conductor.instance.isPlaying && !Conductor.instance.isPaused && pauseTimes == 1)
{
audioSource.Play();
print("played");
pauseTimes = 0;
}
else if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
{
Destroy(this.gameObject);
else if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
{
Destroy(this.gameObject);
}
if (Conductor.instance.songPosition > startTime + clip.length)
{
Destroy(this.gameObject);
}
}
}
if (Conductor.instance.songPosition > startTime + clip.length)
{
Destroy(this.gameObject);
}
IEnumerator NotRelyOnBeatSound()
{
yield return new WaitForSeconds(clip.length);
Destroy(this.gameObject);
}
}
}