Created
April 9, 2021 12:42
-
-
Save silenciocorner/94d2aa7c01be2d89c12ca682aff46874 to your computer and use it in GitHub Desktop.
MarkerSpawner of BeatSpawner.cs script from Colin Vandervort article "FMOD Unity: Beat-Mapping"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeatSpawner : MonoBehaviour | |
{ | |
private bool beatSpawnArmed = false; | |
[SerializeField] | |
private Track[] tracks; | |
private string lastMarkerName; | |
private void Start() | |
{ | |
if(lastMarkerName != null) | |
lastMarkerName = (string)MusicManager.me.timelineInfo.lastMarker; | |
} | |
private void Update() | |
{ | |
if(lastMarkerName != (string)MusicManager.me.timelineInfo.lastMarker) | |
{ | |
beatSpawnArmed = true; | |
lastMarkerName = (string)MusicManager.me.timelineInfo.lastMarker; | |
} | |
if (beatSpawnArmed && lastMarkerName != string.Empty) | |
{ | |
switch (lastMarkerName[0].ToString()) | |
{ | |
case "1": | |
if (tracks[0].isActive) | |
tracks[0].CreateNote(MusicManager.me.timelineInfo.currentPosition); | |
break; | |
case "2": | |
if (tracks[1].isActive) | |
tracks[1].CreateNote(MusicManager.me.timelineInfo.currentPosition); | |
break; | |
case "3": | |
if (tracks[2].isActive) | |
tracks[2].CreateNote(MusicManager.me.timelineInfo.currentPosition); | |
break; | |
case "4": | |
if (tracks[3].isActive) | |
tracks[3].CreateNote(MusicManager.me.timelineInfo.currentPosition); | |
break; | |
default: | |
Debug.Log("No valid track"); | |
break; | |
} | |
beatSpawnArmed = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment