/// <summary> /// Starts tracking the audio and beatmap. /// </summary> /// <returns><c>true</c>, if tracking was started successfully, <c>false</c> otherwise.</returns> bool StartTracking() { if (beatmap == null || beatmap.beats.Count == 0) { return false; } _songEnded = false; _nextBeat = beatmap.beats[0]; _beatTimer = 0.0; return true; }
/// <summary> /// Tracks the beats. /// </summary> /// <returns><c>true</c>, if there was a beat this frame, <c>false</c> otherwise.</returns> bool TrackBeats() { if (!(_songEnded && !loopAudio)) { _beatTimer += Time.deltaTime; } else { _beatFrame = false; return false; } if (_songEnded) { if (_beatTimer >= (double)beatmap.songLength) { if (_audioClipExists) { _audio.Stop(); } StartTracking(); if (_audioClipExists) { _audio.Play(); } } } else if (_nextBeat.timeStamp <= _beatTimer) { _beatIndex++; if (_beatIndex == beatmap.beats.Count) { _songEnded = true; if (loopAudio) { _nextBeat = beatmap.beats[0]; } } else { _prevBeat = _nextBeat; _nextBeat = beatmap.beats[_beatIndex % beatmap.beats.Count]; } _beatFrame = true; return true; } _beatFrame = false; return false; }
/// <summary> /// Tracks the beats. /// </summary> /// <returns><c>true</c>, if there was a beat this frame, <c>false</c> otherwise.</returns> bool TrackBeats() { if (!(_songEnded && !loopAudio) && !audioClipTracking) { _beatTimer += Time.deltaTime; } else if (!(_songEnded && !loopAudio) && audioClipTracking) { if (!_audioClipExists) { Debug.LogError("Audio clip missing! Add an audio clip to the Maestro AudioSource or uncheck Audio Clip Tracking in the Inspector"); _beatTimer += Time.deltaTime; } else { double beatTimeElapsed = _audio.time - _beatTimer; _beatTimer += beatTimeElapsed; } } else { _beatFrame = false; return false; } if (_songEnded) { if (_beatTimer >= (double)beatmap.songLength) { if (_audioClipExists) { _audio.Stop(); } StartTracking(); if (_audioClipExists) { _audio.Play(); } } } else if (_nextBeat.timeStamp <= _beatTimer) { _beatIndex++; if (_beatIndex == beatmap.beats.Count) { _songEnded = true; if (loopAudio) { _nextBeat = beatmap.beats[0]; } } else { _prevBeat = _nextBeat; _nextBeat = beatmap.beats[_beatIndex % beatmap.beats.Count]; } _beatFrame = true; return true; } _beatFrame = false; return false; }