mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-10 11:45:09 +00:00
BTSDS: Piano!!!
This commit is contained in:
parent
5711a1508b
commit
2ac602dbe6
5 changed files with 81 additions and 21 deletions
|
@ -224,7 +224,7 @@ namespace RhythmHeavenMania
|
||||||
SetCurrentEventToClosest(beat);
|
SetCurrentEventToClosest(beat);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < SoundObjects.Count; i++) Destroy(SoundObjects[i].gameObject);
|
KillAllSounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pause()
|
public void Pause()
|
||||||
|
@ -237,6 +237,13 @@ namespace RhythmHeavenMania
|
||||||
Conductor.instance.Stop(beat);
|
Conductor.instance.Stop(beat);
|
||||||
SetCurrentEventToClosest(beat);
|
SetCurrentEventToClosest(beat);
|
||||||
onBeatChanged?.Invoke(beat);
|
onBeatChanged?.Invoke(beat);
|
||||||
|
KillAllSounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void KillAllSounds()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < SoundObjects.Count; i++)
|
||||||
|
Destroy(SoundObjects[i].gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -184,5 +184,16 @@ namespace RhythmHeavenMania.Games.BuiltToScaleDS
|
||||||
shooterAnim.Play("Shoot", 0, 0);
|
shooterAnim.Play("Shoot", 0, 0);
|
||||||
elevatorAnim.Play("MakeRod", 0, 0);
|
elevatorAnim.Play("MakeRod", 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PlayPiano(float beat, float length, int semiTones)
|
||||||
|
{
|
||||||
|
var pianoPitch = Mathf.Pow(2f, (1f / 12f) * semiTones);
|
||||||
|
var pianoSource = Jukebox.PlayOneShotGame("builtToScaleDS/Piano", -1, pianoPitch, true);
|
||||||
|
|
||||||
|
BeatAction.New(gameObject, new List<BeatAction.Action>()
|
||||||
|
{
|
||||||
|
new BeatAction.Action(beat + length, delegate { Jukebox.KillLoop(pianoSource, 0.1f); })
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -352,9 +352,13 @@ namespace RhythmHeavenMania
|
||||||
new Param("type2", RotateMode.Fast, "Rotation Mode", "The rotation mode to use")
|
new Param("type2", RotateMode.Fast, "Rotation Mode", "The rotation mode to use")
|
||||||
} ),
|
} ),
|
||||||
}),
|
}),
|
||||||
new Minigame("builtToScaleDS", "Built To Scale (DS) \n<color=#eb5454>[WIP don't use]</color>", "00BB00", true, false, new List<GameAction>()
|
new Minigame("builtToScaleDS", "Built To Scale (DS)", "00BB00", true, false, new List<GameAction>()
|
||||||
{
|
{
|
||||||
new GameAction("spawn blocks", delegate { }, 1f, true)
|
new GameAction("spawn blocks", delegate { }, 1f, true),
|
||||||
|
new GameAction("play piano", delegate { BuiltToScaleDS.instance.PlayPiano(eventCaller.currentEntity.beat, eventCaller.currentEntity.length, eventCaller.currentEntity.type); }, 1f, true, new List<Param>()
|
||||||
|
{
|
||||||
|
new Param("type", new EntityTypes.Integer(-24, 24, 0), "Semitones", "The number of semitones up or down this note should be pitched")
|
||||||
|
} ),
|
||||||
}),
|
}),
|
||||||
new Minigame("tapTrial", "Tap Trial \n<color=#eb5454>[WIP don't use]</color>", "93ffb3", false, false, new List<GameAction>()
|
new Minigame("tapTrial", "Tap Trial \n<color=#eb5454>[WIP don't use]</color>", "93ffb3", false, false, new List<GameAction>()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace RhythmHeavenMania.Util
|
||||||
FindJukebox().GetComponent<AudioSource>().volume = volume;
|
FindJukebox().GetComponent<AudioSource>().volume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AudioSource PlayOneShot(string name, float beat = -1)
|
public static AudioSource PlayOneShot(string name, float beat = -1, float pitch = 1f, bool looping = false)
|
||||||
{
|
{
|
||||||
GameObject oneShot = new GameObject("oneShot");
|
GameObject oneShot = new GameObject("oneShot");
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ namespace RhythmHeavenMania.Util
|
||||||
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
AudioClip clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
||||||
snd.clip = clip;
|
snd.clip = clip;
|
||||||
snd.beat = beat;
|
snd.beat = beat;
|
||||||
|
snd.pitch = pitch;
|
||||||
|
snd.looping = looping;
|
||||||
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
|
// snd.pitch = (clip.length / Conductor.instance.secPerBeat);
|
||||||
|
|
||||||
GameManager.instance.SoundObjects.Add(oneShot);
|
GameManager.instance.SoundObjects.Add(oneShot);
|
||||||
|
@ -59,7 +61,7 @@ namespace RhythmHeavenMania.Util
|
||||||
return audioSource;
|
return audioSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AudioSource PlayOneShotScheduled(string name, double targetTime)
|
public static AudioSource PlayOneShotScheduled(string name, double targetTime, float pitch = 1f, bool looping = false)
|
||||||
{
|
{
|
||||||
GameObject oneShot = new GameObject("oneShotScheduled");
|
GameObject oneShot = new GameObject("oneShotScheduled");
|
||||||
|
|
||||||
|
@ -71,6 +73,8 @@ namespace RhythmHeavenMania.Util
|
||||||
var clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
var clip = Resources.Load<AudioClip>($"Sfx/{name}");
|
||||||
audioSource.clip = clip;
|
audioSource.clip = clip;
|
||||||
snd.clip = clip;
|
snd.clip = clip;
|
||||||
|
snd.pitch = pitch;
|
||||||
|
snd.looping = looping;
|
||||||
|
|
||||||
snd.scheduled = true;
|
snd.scheduled = true;
|
||||||
snd.scheduledTime = targetTime;
|
snd.scheduledTime = targetTime;
|
||||||
|
@ -81,25 +85,30 @@ namespace RhythmHeavenMania.Util
|
||||||
return audioSource;
|
return audioSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AudioSource PlayOneShotGame(string name, float beat = -1)
|
public static AudioSource PlayOneShotGame(string name, float beat = -1, float pitch = 1f, bool looping = false)
|
||||||
{
|
{
|
||||||
if (GameManager.instance.currentGame == name.Split('/')[0])
|
if (GameManager.instance.currentGame == name.Split('/')[0])
|
||||||
{
|
{
|
||||||
return PlayOneShot($"games/{name}", beat);
|
return PlayOneShot($"games/{name}", beat, pitch, looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime)
|
public static AudioSource PlayOneShotScheduledGame(string name, double targetTime, float pitch = 1f, bool looping = false)
|
||||||
{
|
{
|
||||||
if (GameManager.instance.currentGame == name.Split('/')[0])
|
if (GameManager.instance.currentGame == name.Split('/')[0])
|
||||||
{
|
{
|
||||||
return PlayOneShotScheduled($"games/{name}", targetTime);
|
return PlayOneShotScheduled($"games/{name}", targetTime, pitch, looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void KillLoop(AudioSource source, float fadeTime)
|
||||||
|
{
|
||||||
|
source.GetComponent<Sound>().KillLoop(fadeTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,6 +13,8 @@ namespace RhythmHeavenMania.Util
|
||||||
public bool scheduled;
|
public bool scheduled;
|
||||||
public double scheduledTime;
|
public double scheduledTime;
|
||||||
|
|
||||||
|
public bool looping;
|
||||||
|
|
||||||
private AudioSource audioSource;
|
private AudioSource audioSource;
|
||||||
|
|
||||||
private int pauseTimes = 0;
|
private int pauseTimes = 0;
|
||||||
|
@ -29,6 +31,7 @@ namespace RhythmHeavenMania.Util
|
||||||
audioSource = GetComponent<AudioSource>();
|
audioSource = GetComponent<AudioSource>();
|
||||||
audioSource.clip = clip;
|
audioSource.clip = clip;
|
||||||
audioSource.pitch = pitch;
|
audioSource.pitch = pitch;
|
||||||
|
audioSource.loop = looping;
|
||||||
|
|
||||||
if (beat == -1 && !scheduled)
|
if (beat == -1 && !scheduled)
|
||||||
{
|
{
|
||||||
|
@ -43,15 +46,17 @@ namespace RhythmHeavenMania.Util
|
||||||
|
|
||||||
startTime = Conductor.instance.songPosition;
|
startTime = Conductor.instance.songPosition;
|
||||||
|
|
||||||
if (!scheduled)
|
if (!scheduled && !looping)
|
||||||
StartCoroutine(NotRelyOnBeatSound());
|
StartCoroutine(NotRelyOnBeatSound());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
{
|
||||||
|
if (playIndex < 1)
|
||||||
{
|
{
|
||||||
if (scheduled)
|
if (scheduled)
|
||||||
{
|
{
|
||||||
if (AudioSettings.dspTime > scheduledTime && playIndex < 1)
|
if (AudioSettings.dspTime > scheduledTime)
|
||||||
{
|
{
|
||||||
StartCoroutine(NotRelyOnBeatSound());
|
StartCoroutine(NotRelyOnBeatSound());
|
||||||
playIndex++;
|
playIndex++;
|
||||||
|
@ -59,18 +64,42 @@ namespace RhythmHeavenMania.Util
|
||||||
}
|
}
|
||||||
else if (!playInstant)
|
else if (!playInstant)
|
||||||
{
|
{
|
||||||
if (Conductor.instance.songPositionInBeats > beat && playIndex < 1)
|
if (Conductor.instance.songPositionInBeats > beat)
|
||||||
{
|
{
|
||||||
audioSource.PlayScheduled(Time.time);
|
audioSource.PlayScheduled(Time.time);
|
||||||
playIndex++;
|
playIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerator NotRelyOnBeatSound()
|
IEnumerator NotRelyOnBeatSound()
|
||||||
|
{
|
||||||
|
if (!looping) // Looping sounds are destroyed manually.
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(clip.length);
|
yield return new WaitForSeconds(clip.length);
|
||||||
Destroy(this.gameObject);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue