Пример #1
0
 public void Init(TrackPlayer metronome)
 {
     this.trackPlayer = metronome;
 }
Пример #2
0
        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;
                }
            }
        }