MusicWrapper.BPMSection GetCurrentSection() { float musicTime = m_audioSource.time; MusicWrapper.BPMSection[] sections = m_music.sections; MusicWrapper.BPMSection section = null; for (int i = 0; i < sections.Length; ++i) { if (musicTime > sections[i].startTime && musicTime < sections[i].endTime) { //Correct section section = sections[i]; break; } } return(section); }
/// <summary> /// Returns a float which represents the current beat. Will be a whole number when exactly on the beat, or will end in .5 when exactly on an off-beat. /// </summary> /// <returns></returns> float GetCurrentBeat(MusicWrapper.BPMSection section) { float beatDuration = 60f / section.bpm; return((m_audioSource.time - section.startTime) / beatDuration); }