private void TrackPlayer_OnSongEnded(object sender, EventArgs e) { Debug.Log("ending song state"); lobbyUI.Show(); // this should be a callback in the UI prob inGame = false; if (selectedBeatmapPath != null) { Debug.Log(selectedBeatmapPath); BeatmapCompressor.DeleteTempBeatmap(selectedBeatmapPath); } if (currentConductor != null) { trackPlayer.currentBeat -= currentConductor.OnCurrentBeat; Destroy(currentConductor.gameObject); currentConductor = null; } if (currentNoteSpawner != null) { Destroy(currentNoteSpawner.gameObject); currentNoteSpawner = null; } trackPlayer.songEnded -= TrackPlayer_OnSongEnded; if (!recording) { Destroy(trackPlayer.gameObject); } }
public void Init(NoteSpawner noteSpawner, Beatmap beatmap) { this.noteSpawner = noteSpawner; this.beatmap = beatmap; }
private void Update() { // rn a little messy bc everything depends on one other object to create it- could turn note spawn into request, but metronome is associated w note creation unless event is "global" // need better classes to help instantiate beatsynced & metronome if (Input.GetKeyDown(KeyCode.Space) && !inGame && !recording) { Debug.Log("started playing"); // copy the selected beatmap so not modified somehow? need to clarify on c# class passde by value Beatmap currentBeatmap = selectedBeatmap; if (currentBeatmap == null || selectedBeatmapPath == null) { lobbyUI.FlashMessage("no beatmap selected!"); } else { inGame = true; audioSource.clip = selectedMusic; lobbyUI.Hide(); trackPlayer = Instantiate(trackPlayerPrefab); trackPlayer.Init(audioSource, selectedBeatmap.songInfo.bpm, recording = false); currentNoteSpawner = Instantiate(noteSpawnerPrefab); currentNoteSpawner.Init(trackPlayer); currentConductor = Instantiate(conductorPrefab); currentConductor.Init(currentNoteSpawner, currentBeatmap); trackPlayer.currentBeat += currentConductor.OnCurrentBeat; trackPlayer.songEnded += currentConductor.TrackPlayer_OnSongEnded; trackPlayer.songEnded += TrackPlayer_OnSongEnded; } } else if (Input.GetKeyDown(KeyCode.R) && !recording && !inGame) { Debug.Log("started recording"); int bpm = lobbyUI.TryGetBPM(); if (bpm < 1) { lobbyUI.FlashMessage("invalid bpm"); } else if (selectedSong == null || selectedMusic == null) { lobbyUI.FlashMessage("no song selected"); } else { recording = true; lobbyUI.Hide(); audioSource.clip = selectedMusic; Beatmap newBeatmap = new Beatmap { songInfo = new SongInfo { bpm = bpm, pathToMusic = selectedSong.pathToMusic, name = selectedSong.name, } }; trackPlayer = Instantiate(trackPlayerPrefab); trackPlayer.Init(audioSource, newBeatmap.songInfo.bpm, recording = true, newBeatmap); trackPlayer.finishedRecording += TrackPlayer_OnDoneRecording; trackPlayer.songEnded += TrackPlayer_OnSongEnded; } } }