count in rework + preloading, multisound addition
multisound was using an array that was converted to a list..? very silly when you consider it's a list first so sometimes it's list -> array -> list lol new Count-In and Play SFX block preloads sfx now!! epic.
This commit is contained in:
parent
1d8462cb01
commit
e48ac15efc
|
|
@ -620,11 +620,12 @@ namespace HeavenStudio
|
|||
}
|
||||
}
|
||||
|
||||
public void PlaySFXArbitrary(double beat, string game, string name, float pitch, float offset)
|
||||
public static void PlaySFXArbitrary(double beat, string game, string name, float pitch, float offset)
|
||||
{
|
||||
if (string.IsNullOrEmpty(game)) {
|
||||
SoundByte.PlayOneShot(name, beat, pitch, offset: offset);
|
||||
} else {
|
||||
SoundByte.PreloadGameAudioClips(game);
|
||||
SoundByte.PlayOneShotGame(game + "/" + name, beat, pitch, forcePlay: true, offset: (offset / 1000f));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,67 +8,71 @@ namespace HeavenStudio.Games
|
|||
{
|
||||
public class SoundEffects : MonoBehaviour
|
||||
{
|
||||
|
||||
public enum CountNumbers { One, Two, Three, Four }
|
||||
public static string[] countNames = { "one", "two", "three", "four" };
|
||||
public readonly static string[] countNames = { "one", "two", "one", "two", "three", "four" };
|
||||
public readonly static float[] timings = { 0f, 2f, 4f, 5f, 6f, 7f };
|
||||
public static void Count(int type, bool alt)
|
||||
{
|
||||
string sound = countNames[type];
|
||||
if (!alt)
|
||||
sound += "1";
|
||||
else
|
||||
sound += "2";
|
||||
SoundByte.PlayOneShot("count-ins/" + sound);
|
||||
SoundByte.PlayOneShot("count-ins/" + countNames[type] + (!alt ? "1" : "2"));
|
||||
}
|
||||
|
||||
public enum CountInType { Normal, Alt, Cowbell }
|
||||
public static string[] GetCountInSounds(string[] sounds, CountInType type)
|
||||
public static string GetCountInSound(int type)
|
||||
{
|
||||
for (int i = 0; i < sounds.Length; i++)
|
||||
return (CountInType)type switch {
|
||||
CountInType.Normal => "1",
|
||||
CountInType.Alt => "2",
|
||||
CountInType.Cowbell or _ => "cowbell",
|
||||
};
|
||||
}
|
||||
|
||||
public static void PreloadCounts()
|
||||
{
|
||||
foreach (var load in new string[] { "one", "two", "three", "four", "cowbell", "ready1", "ready2" })
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CountInType.Normal:
|
||||
sounds[i] += "1";
|
||||
break;
|
||||
case CountInType.Alt:
|
||||
sounds[i] += "2";
|
||||
break;
|
||||
case CountInType.Cowbell:
|
||||
sounds[i] = "cowbell";
|
||||
break;
|
||||
SoundByte.PreloadAudioClipAsync(load);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CountIn(double beat, float length, bool alt, bool go)
|
||||
{
|
||||
PreloadCounts();
|
||||
string countType = alt ? "2" : "1";
|
||||
double startBeat = beat + length - 8;
|
||||
|
||||
List<MultiSound.Sound> sfx = new();
|
||||
for (int i = 0; i < countNames.Length; i++) {
|
||||
if (startBeat + timings[i] >= beat) {
|
||||
sfx.Add(new MultiSound.Sound("count-ins/" + countNames[i] + countType, startBeat + timings[i]));
|
||||
}
|
||||
}
|
||||
return sounds;
|
||||
if (go) sfx[^1].name = "count-ins/go" + countType;
|
||||
MultiSound.Play(sfx, false);
|
||||
}
|
||||
|
||||
public static void FourBeatCountIn(double beat, float length, int type)
|
||||
{
|
||||
string[] sounds = { "one", "two", "three", "four" };
|
||||
sounds = GetCountInSounds(sounds, (CountInType)type);
|
||||
PreloadCounts();
|
||||
string countType = GetCountInSound(type);
|
||||
|
||||
MultiSound.Play(new MultiSound.Sound[]
|
||||
{
|
||||
new MultiSound.Sound("count-ins/" + sounds[0], beat),
|
||||
new MultiSound.Sound("count-ins/" + sounds[1], beat + 1f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[2], beat + 2f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[3], beat + 3f * length)
|
||||
}, false);
|
||||
List<MultiSound.Sound> sfx = new();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
sfx.Add(new MultiSound.Sound("count-ins/" + countNames[i + 2] + countType, beat + (i * length)));
|
||||
}
|
||||
MultiSound.Play(sfx, false);
|
||||
}
|
||||
|
||||
public static void EightBeatCountIn(double beat, float length, int type)
|
||||
{
|
||||
PreloadCounts();
|
||||
string[] sounds = { "one", "two", "one", "two", "three", "four" };
|
||||
sounds = GetCountInSounds(sounds, (CountInType)type);
|
||||
string sound = GetCountInSound(type);
|
||||
|
||||
MultiSound.Play(new MultiSound.Sound[]
|
||||
{
|
||||
new MultiSound.Sound("count-ins/" + sounds[0], beat),
|
||||
new MultiSound.Sound("count-ins/" + sounds[1], beat + 2f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[2], beat + 4f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[3], beat + 5f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[4], beat + 6f * length),
|
||||
new MultiSound.Sound("count-ins/" + sounds[5], beat + 7f * length)
|
||||
}, false);
|
||||
List<MultiSound.Sound> sfx = new();
|
||||
for (int i = 0; i < sounds.Length; i++) {
|
||||
sfx.Add(new MultiSound.Sound("count-ins/" + sounds[i] + sound, beat + (timings[i] * length)));
|
||||
}
|
||||
MultiSound.Play(sfx, false);
|
||||
}
|
||||
|
||||
public static void Cowbell()
|
||||
|
|
@ -78,10 +82,9 @@ namespace HeavenStudio.Games
|
|||
|
||||
public static void Ready(double beat, float length)
|
||||
{
|
||||
MultiSound.Play(new MultiSound.Sound[]
|
||||
{
|
||||
MultiSound.Play(new MultiSound.Sound[] {
|
||||
new MultiSound.Sound("count-ins/ready1", beat),
|
||||
new MultiSound.Sound("count-ins/ready2", beat + 1f * length),
|
||||
new MultiSound.Sound("count-ins/ready2", beat + (1f * length)),
|
||||
}, false);
|
||||
}
|
||||
|
||||
|
|
@ -92,12 +95,7 @@ namespace HeavenStudio.Games
|
|||
|
||||
public static void Go(bool alt)
|
||||
{
|
||||
string sound = "count-ins/go";
|
||||
if (!alt)
|
||||
sound += "1";
|
||||
else
|
||||
sound += "2";
|
||||
SoundByte.PlayOneShot(sound);
|
||||
SoundByte.PlayOneShot("count-ins/go" + (!alt ? "1" : "2"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -775,26 +775,43 @@ namespace HeavenStudio
|
|||
},
|
||||
preFunction : delegate {
|
||||
var e = eventCaller.currentEntity;
|
||||
GameManager.instance.PlaySFXArbitrary(e.beat, e["game"], e["sfxName"], e["pitch"], e["offset"]);
|
||||
GameManager.PlaySFXArbitrary(e.beat, e["game"], e["sfxName"], e["pitch"], e["offset"]);
|
||||
}
|
||||
),
|
||||
}),
|
||||
|
||||
new Minigame("countIn", "Count-Ins", "", false, true, new List<GameAction>()
|
||||
{
|
||||
new GameAction("count-in", "Count-In", 4f, true,
|
||||
new List<Param>()
|
||||
{
|
||||
new Param("alt", false, "Alt", "Set the type of sounds to use for the count-in."),
|
||||
new Param("go", false, "Go!", "Toggle to end the count-in with \"Go!\""),
|
||||
},
|
||||
preFunction : delegate {
|
||||
var e = eventCaller.currentEntity;
|
||||
SoundEffects.CountIn(e.beat, e.length, e["alt"], e["go"]);
|
||||
}
|
||||
),
|
||||
new GameAction("4 beat count-in", "4 Beat Count-In", 4f, true,
|
||||
new List<Param>()
|
||||
{
|
||||
new Param("type", SoundEffects.CountInType.Normal, "Type", "Set the type of sounds to use for the count-in.")
|
||||
},
|
||||
delegate { var e = eventCaller.currentEntity; SoundEffects.FourBeatCountIn(e.beat, e.length / 4f, e["type"]); }
|
||||
delegate {
|
||||
var e = eventCaller.currentEntity;
|
||||
SoundEffects.FourBeatCountIn(e.beat, e.length / 4f, e["type"]);
|
||||
}
|
||||
),
|
||||
new GameAction("8 beat count-in", "8 Beat Count-In", 8f, true,
|
||||
new List<Param>()
|
||||
{
|
||||
new Param("type", SoundEffects.CountInType.Normal, "Type", "Set the type of sounds to use for the count-in.")
|
||||
},
|
||||
delegate { var e = eventCaller.currentEntity; SoundEffects.EightBeatCountIn(e.beat, e.length / 8f, e["type"]); }
|
||||
delegate {
|
||||
var e = eventCaller.currentEntity;
|
||||
SoundEffects.EightBeatCountIn(e.beat, e.length / 8f, e["type"]);
|
||||
}
|
||||
),
|
||||
new GameAction("count", "Count", 1f, false,
|
||||
new List<Param>()
|
||||
|
|
@ -802,13 +819,16 @@ namespace HeavenStudio
|
|||
new Param("type", SoundEffects.CountNumbers.One, "Type", "Set the number to say."),
|
||||
new Param("toggle", false, "Alt", "Toggle if the alternate version of this voice line should be used.")
|
||||
},
|
||||
delegate { var e = eventCaller.currentEntity; SoundEffects.Count(e["type"], e["toggle"]); }
|
||||
delegate {
|
||||
var e = eventCaller.currentEntity;
|
||||
SoundEffects.Count(e["type"], e["toggle"]);
|
||||
}
|
||||
),
|
||||
new GameAction("cowbell", "Cowbell",
|
||||
function: delegate { SoundEffects.Cowbell(); }
|
||||
),
|
||||
new GameAction("ready!", "Ready!", 2f, true,
|
||||
function: delegate { var e = eventCaller.currentEntity; SoundEffects.Ready(e.beat, e.length / 2f); }
|
||||
function: delegate { var e = eventCaller.currentEntity; SoundEffects.Ready(e.beat, (e.length / 2f)); }
|
||||
),
|
||||
new GameAction("and", "And", 0.5f,
|
||||
function: delegate { SoundEffects.And(); }
|
||||
|
|
|
|||
|
|
@ -36,12 +36,15 @@ namespace HeavenStudio.Util
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static MultiSound Play(Sound[] snds, bool game = true, bool forcePlay = false)
|
||||
{
|
||||
if (Conductor.instance == null) return null;
|
||||
return Play(snds.ToList(), game, forcePlay);
|
||||
}
|
||||
|
||||
public static MultiSound Play(List<Sound> sounds, bool game = true, bool forcePlay = false)
|
||||
{
|
||||
if (Conductor.instance == null || sounds.Count <= 0) return null;
|
||||
|
||||
List<Sound> sounds = snds.ToList();
|
||||
GameObject go = new GameObject("MultiSound");
|
||||
MultiSound ms = go.AddComponent<MultiSound>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue