From 4e533105122928b8504625806b0e701b11bc9773 Mon Sep 17 00:00:00 2001 From: AstrlJelly Date: Mon, 26 Feb 2024 09:32:40 -0500 Subject: [PATCH] Fix Anim Block, Fine Semitones in SFX Block * i was recursively getting the anim object path BACKWARDS. oops * added fine semitones in the sfx block, thanks Vincells * GetPitchFromSemitones uses a float instead of an int now --- Assets/Scripts/Minigames.cs | 17 +++++++++-------- Assets/Scripts/Util/SoundByte.cs | 13 ++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 9fbba446f..66a4d6009 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -1171,16 +1171,16 @@ namespace HeavenStudio var gm = GameManager.instance; Minigame game = gm.GetGameInfo(gm.currentGame); if (game != null) { - var animators = gm.minigameObj.transform.GetComponentsInChildren(); + Animator[] animators = gm.minigameObj.transform.GetComponentsInChildren(); // not in an update loop so it's fine :3 ((EntityTypes.DropdownObj)e["animator"]).SetValues(animators.Select(anim => { - var obj = anim.gameObject; + Transform obj = anim.transform; List path = new() { obj.name }; - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) // not a while loop because i don't trust myself { - if (obj.transform.parent == null || obj.transform.parent.name == game.name) break; - obj = obj.transform.parent.gameObject; - path.Add(obj.name); + if (obj.parent.name == game.name || obj.parent == null) break; + obj = obj.parent; + path.Insert(0, obj.name); } return string.Join('/', path); }).ToList()); @@ -1244,10 +1244,11 @@ namespace HeavenStudio }), "Get SFX", "Get all the sfx in the selected minigame."), new Param("sfxName", new EntityTypes.Dropdown(), "SFX Name", "The name of the sfx to play."), new Param("useSemitones", false, "Use Semitones", "Toggle to use semitones instead of straight pitch.", new() { - new((x, e) => (bool)x, "semitones"), + new((x, e) => (bool)x, "semitones", "semitonesFine"), new((x, e) => !(bool)x, "pitch"), }), new Param("semitones", new EntityTypes.Integer(-24, 24, 0), "Semitones", "The semitones of the sfx."), + new Param("semitonesFine", new EntityTypes.Float(-1, 1, 0), "Fine Semitones", "The semitones of the sfx."), new Param("pitch", new EntityTypes.Float(0, 5, 1), "Pitch", "The pitch of the sfx."), new Param("volume", new EntityTypes.Float(0, 2, 1), "Volume", "The volume of the sfx."), new Param("offset", new EntityTypes.Integer(-500, 500), "Offset (ms)", "The offset of the sfx in milliseconds."), @@ -1255,7 +1256,7 @@ namespace HeavenStudio }, preFunction : delegate { var e = eventCaller.currentEntity; - float pitch = e["useSemitones"] ? SoundByte.GetPitchFromSemiTones(e["semitones"], true) : e["pitch"]; + float pitch = e["useSemitones"] ? SoundByte.GetPitchFromSemiTones(e["semitones"] + e["semitonesFine"], false) : e["pitch"]; GameManager.PlaySFXArbitrary(e.beat, e.length, e["game"].CurrentValue, e["sfxName"].CurrentValue, pitch, e["volume"], e["loop"], e["offset"]); } ), diff --git a/Assets/Scripts/Util/SoundByte.cs b/Assets/Scripts/Util/SoundByte.cs index 1bb448ca2..c5a03cf53 100644 --- a/Assets/Scripts/Util/SoundByte.cs +++ b/Assets/Scripts/Util/SoundByte.cs @@ -458,16 +458,11 @@ namespace HeavenStudio.Util /// /// Gets a pitch multiplier from semitones. /// - public static float GetPitchFromSemiTones(int semiTones, bool pitchToMusic) + public static float GetPitchFromSemiTones(float semiTones, bool pitchToMusic) { - if (pitchToMusic) - { - return Mathf.Pow(2f, (1f / 12f) * semiTones) * Conductor.instance.musicSource.pitch; - } - else - { - return Mathf.Pow(2f, (1f / 12f) * semiTones); - } + var newSemitones = Mathf.Pow(2f, (1f / 12f) * semiTones); + if (pitchToMusic) newSemitones *= Conductor.instance.musicSource.pitch; + return newSemitones; } /// /// Returns the semitones from a pitch.