From 014bf596a969c6247e608c8b8506bebe6f8a373f Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:16:38 +0100 Subject: [PATCH] OnBeatPulse callback added --- Assets/Scripts/GameManager.cs | 16 ++++++++++++++++ Assets/Scripts/Games/Minigame.cs | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 1496704e5..0f3e74380 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -47,6 +47,7 @@ namespace HeavenStudio [NonSerialized] public bool playOnStart; [NonSerialized] public double startBeat; [NonSerialized] public GameObject currentGameO; + private Minigame _currentMinigame; [NonSerialized] public bool autoplay; [NonSerialized] public bool canInput = true; [NonSerialized] public RiqEntity currentSection, nextSection; @@ -493,6 +494,12 @@ namespace HeavenStudio } } + if (cond.songPositionInBeatsAsDouble >= Math.Ceiling(_playStartBeat) + _pulseTally) + { + if (_currentMinigame != null) _currentMinigame.OnBeatPulse(Math.Ceiling(_playStartBeat) + _pulseTally); + _pulseTally++; + } + float seekTime = 8f; //seek ahead to preload games that have assetbundles SeekAheadAndPreload(cond.songPositionInBeatsAsDouble, seekTime); @@ -580,10 +587,15 @@ namespace HeavenStudio #region Play Events + private double _playStartBeat = 0; + private int _pulseTally = 0; + public void Play(double beat, float delay = 0f) { bool paused = Conductor.instance.isPaused; Debug.Log("Playing at " + beat); + _playStartBeat = beat; + _pulseTally = 0; canInput = true; if (!paused) { @@ -951,6 +963,10 @@ namespace HeavenStudio Destroy(currentGameO); currentGameO = Instantiate(GetGame(game)); + if (currentGameO.TryGetComponent(out var minigame)) + { + _currentMinigame = minigame; + } currentGameO.transform.parent = eventCaller.GamesHolder.transform; currentGameO.name = game; diff --git a/Assets/Scripts/Games/Minigame.cs b/Assets/Scripts/Games/Minigame.cs index 24cc4c8bf..632bb8810 100644 --- a/Assets/Scripts/Games/Minigame.cs +++ b/Assets/Scripts/Games/Minigame.cs @@ -412,6 +412,12 @@ namespace HeavenStudio.Games } } + // mainly for bopping logic + public virtual void OnBeatPulse(double beat) + { + + } + public static MultiSound PlaySoundSequence(string game, string name, double startBeat, params SoundSequence.SequenceParams[] args) { Minigames.Minigame gameInfo = GameManager.instance.GetGameInfo(game);