mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:47:37 +02:00
Improved inputs (A SHIT MORE DYNAMIC BETWEEN GAMES) and a whole lot cleaner code in general
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user