OnBeatPulse callback added

This commit is contained in:
Rapandrasmus 2023-11-23 13:16:38 +01:00
parent 2d6a61eb03
commit 014bf596a9
2 changed files with 22 additions and 0 deletions

View file

@ -47,6 +47,7 @@ namespace HeavenStudio
[NonSerialized] public bool playOnStart; [NonSerialized] public bool playOnStart;
[NonSerialized] public double startBeat; [NonSerialized] public double startBeat;
[NonSerialized] public GameObject currentGameO; [NonSerialized] public GameObject currentGameO;
private Minigame _currentMinigame;
[NonSerialized] public bool autoplay; [NonSerialized] public bool autoplay;
[NonSerialized] public bool canInput = true; [NonSerialized] public bool canInput = true;
[NonSerialized] public RiqEntity currentSection, nextSection; [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; float seekTime = 8f;
//seek ahead to preload games that have assetbundles //seek ahead to preload games that have assetbundles
SeekAheadAndPreload(cond.songPositionInBeatsAsDouble, seekTime); SeekAheadAndPreload(cond.songPositionInBeatsAsDouble, seekTime);
@ -580,10 +587,15 @@ namespace HeavenStudio
#region Play Events #region Play Events
private double _playStartBeat = 0;
private int _pulseTally = 0;
public void Play(double beat, float delay = 0f) public void Play(double beat, float delay = 0f)
{ {
bool paused = Conductor.instance.isPaused; bool paused = Conductor.instance.isPaused;
Debug.Log("Playing at " + beat); Debug.Log("Playing at " + beat);
_playStartBeat = beat;
_pulseTally = 0;
canInput = true; canInput = true;
if (!paused) if (!paused)
{ {
@ -951,6 +963,10 @@ namespace HeavenStudio
Destroy(currentGameO); Destroy(currentGameO);
currentGameO = Instantiate(GetGame(game)); currentGameO = Instantiate(GetGame(game));
if (currentGameO.TryGetComponent<Minigame>(out var minigame))
{
_currentMinigame = minigame;
}
currentGameO.transform.parent = eventCaller.GamesHolder.transform; currentGameO.transform.parent = eventCaller.GamesHolder.transform;
currentGameO.name = game; currentGameO.name = game;

View file

@ -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) public static MultiSound PlaySoundSequence(string game, string name, double startBeat, params SoundSequence.SequenceParams[] args)
{ {
Minigames.Minigame gameInfo = GameManager.instance.GetGameInfo(game); Minigames.Minigame gameInfo = GameManager.instance.GetGameInfo(game);