mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 21:37:40 +02:00
BTSDS: Piano!!!
This commit is contained in:
@ -13,6 +13,8 @@ namespace RhythmHeavenMania.Util
|
||||
public bool scheduled;
|
||||
public double scheduledTime;
|
||||
|
||||
public bool looping;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private int pauseTimes = 0;
|
||||
@ -29,6 +31,7 @@ namespace RhythmHeavenMania.Util
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
audioSource.clip = clip;
|
||||
audioSource.pitch = pitch;
|
||||
audioSource.loop = looping;
|
||||
|
||||
if (beat == -1 && !scheduled)
|
||||
{
|
||||
@ -43,33 +46,59 @@ namespace RhythmHeavenMania.Util
|
||||
|
||||
startTime = Conductor.instance.songPosition;
|
||||
|
||||
if (!scheduled)
|
||||
if (!scheduled && !looping)
|
||||
StartCoroutine(NotRelyOnBeatSound());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (scheduled)
|
||||
if (playIndex < 1)
|
||||
{
|
||||
if (AudioSettings.dspTime > scheduledTime && playIndex < 1)
|
||||
if (scheduled)
|
||||
{
|
||||
StartCoroutine(NotRelyOnBeatSound());
|
||||
playIndex++;
|
||||
if (AudioSettings.dspTime > scheduledTime)
|
||||
{
|
||||
StartCoroutine(NotRelyOnBeatSound());
|
||||
playIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!playInstant)
|
||||
{
|
||||
if (Conductor.instance.songPositionInBeats > beat && playIndex < 1)
|
||||
else if (!playInstant)
|
||||
{
|
||||
audioSource.PlayScheduled(Time.time);
|
||||
playIndex++;
|
||||
if (Conductor.instance.songPositionInBeats > beat)
|
||||
{
|
||||
audioSource.PlayScheduled(Time.time);
|
||||
playIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator NotRelyOnBeatSound()
|
||||
{
|
||||
yield return new WaitForSeconds(clip.length);
|
||||
if (!looping) // Looping sounds are destroyed manually.
|
||||
{
|
||||
yield return new WaitForSeconds(clip.length);
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void KillLoop(float fadeTime)
|
||||
{
|
||||
StartCoroutine(FadeLoop(fadeTime));
|
||||
}
|
||||
|
||||
float loopFadeTimer = 0f;
|
||||
IEnumerator FadeLoop(float fadeTime)
|
||||
{
|
||||
float startingVol = audioSource.volume;
|
||||
|
||||
while (loopFadeTimer < fadeTime)
|
||||
{
|
||||
loopFadeTimer += Time.deltaTime;
|
||||
audioSource.volume = Mathf.Max((1f - (loopFadeTimer / fadeTime)) * startingVol, 0f);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user