From b68da9f2a00b0683a399698d22f843af0847768b Mon Sep 17 00:00:00 2001 From: AstrlJelly Date: Fri, 16 Feb 2024 12:11:18 -0500 Subject: [PATCH] play sfx and play animation blocks i also changed prescheduleFunction to preFunction, and removed the unused preFunction argument in GameAction i can revert this if need be but it just seemed vestigial --- Assets/Scripts/GameManager.cs | 18 ++++++++++++++++++ Assets/Scripts/Minigames.cs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index d401e23aa..d6c5dd431 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -620,6 +620,24 @@ namespace HeavenStudio } } + public 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.PlayOneShotGame(game + "/" + name, beat, pitch, forcePlay: true, offset: (offset / 1000f)); + } + } + + public void PlayAnimationArbitrary(string animator, string animation, float scale) + { + // if possible (efficient enough) id like to find the object recursively, but for now this works + Transform animTrans = minigameObj.transform.Find(animator); + if (animTrans != null && animTrans.TryGetComponent(out var anim)) { + anim.DoScaledAnimationAsync(animation, scale); + } + } + public void ToggleInputs(bool inputs) { canInput = inputs; diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index d4e4045ed..bbc820de8 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -635,11 +635,10 @@ namespace HeavenStudio /// What the block does when read during playback /// Only does this if the game that it is associated with is loaded. /// What the block does when read while the game it's associated with isn't loaded. - /// What the block does when the GameManager seeks to this cue for pre-scheduling. + /// What the block does when the GameManager seeks to this cue for pre-scheduling. /// Prevents the block from being shown in the game list. Block will still function normally if it is in the timeline. - /// Runs two beats before this event is reached. /// Priority of this event. Higher priority events will be run first. - public GameAction(string actionName, string displayName, float defaultLength = 1, bool resizable = false, List parameters = null, EventCallback function = null, EventCallback inactiveFunction = null, EventCallback prescheduleFunction = null, bool hidden = false, EventCallback preFunction = null, int priority = 0, float preFunctionLength = 2.0f) + public GameAction(string actionName, string displayName, float defaultLength = 1, bool resizable = false, List parameters = null, EventCallback function = null, EventCallback inactiveFunction = null, EventCallback preFunction = null, bool hidden = false, int priority = 0, float preFunctionLength = 2.0f) { this.actionName = actionName; if (displayName == String.Empty) this.displayName = actionName; @@ -651,7 +650,7 @@ namespace HeavenStudio this.function = function ?? delegate { }; this.inactiveFunction = inactiveFunction ?? delegate { }; - this.preFunction = prescheduleFunction ?? delegate { }; + this.preFunction = preFunction ?? delegate { }; this.priority = priority; this.preFunctionLength = preFunctionLength; } @@ -754,6 +753,31 @@ namespace HeavenStudio GameManager.instance.ToggleInputs(eventCaller.currentEntity["toggle"]); } ), + new GameAction("play animation", "Play Animation", 0.5f, false, + new List() + { + new Param("animator", "", "Animator", "Specify which animator in the scene to play an animation on. (i.e \"Plalin\" or \"Game/Paddlers/Player\")"), + new Param("animation", "", "Animation", "Specify the name of the animation to play."), + new Param("scale", new EntityTypes.Float(0, 5, 0.5f), "Animation Scale", "The time scale of the animation. Higher values are faster."), + }, + delegate { + var e = eventCaller.currentEntity; + GameManager.instance.PlayAnimationArbitrary(e["animator"], e["animation"], e["scale"]); + } + ), + new GameAction("play sfx", "Play SFX", 0.5f, false, + new List() + { + new Param("game", "", "Which Game", "Specify the game's sfx to play. An empty input will play global sfx."), + new Param("sfxName", "", "SFX Name", "The name of the sfx to play."), + new Param("pitch", new EntityTypes.Float(0, 5, 1), "Pitch", "The sfx's pitch."), + new Param("offset", new EntityTypes.Float(-500, 500), "Offset (ms)", "The sfx's offset in milliseconds."), + }, + preFunction : delegate { + var e = eventCaller.currentEntity; + GameManager.instance.PlaySFXArbitrary(e.beat, e["game"], e["sfxName"], e["pitch"], e["offset"]); + } + ), }), new Minigame("countIn", "Count-Ins", "", false, true, new List()