コード例 #1
0
ファイル: MusicManager.cs プロジェクト: aarondesin/route95
 /// <summary>
 /// Creates a new blank song and adds
 /// it to the current project.
 /// </summary>
 public void NewSong()
 {
     _currentSong = new Song();
     _currentProject.Songs.Add(_currentSong);
 }
コード例 #2
0
ファイル: MusicManager.cs プロジェクト: aarondesin/route95
 public void ResetPlayback()
 {
     _currentPlayingSong = 0;
     _currentSong        = _currentProject.Empty ? null : _currentProject.Songs[0];
 }
コード例 #3
0
ファイル: MusicManager.cs プロジェクト: aarondesin/route95
        void FixedUpdate()
        {
            // Return if not playing or game is paused
            if (!_isPlaying)
            {
                return;
            }
            if (GameManager.Instance.Paused)
            {
                return;
            }

            // If new beat
            if (_beatTimer <= 0f)
            {
                switch (GameManager.Instance.CurrentState)
                {
                // Setup mode (riff editor)
                case GameManager.State.Setup:

                    if (_riffMode)
                    {
                        // Play riff note
                        RiffEditor.CurrentRiff.PlayRiff(_beat++);

                        // Wrap payback
                        if (_beat >= Riff.MAX_BEATS && _loopRiffs)
                        {
                            _beat = 0;
                        }

                        // Decrement shaker density
                        WorldManager.Instance.Shakers -= 2;
                    }
                    else
                    {
                        if (_currentSong.BeatsCount == 0)
                        {
                            return;
                        }

                        // If song is finished
                        if (_beat >= _currentSong.BeatsCount && _loopRiffs)
                        {
                            _beat = 0;
                        }

                        // Play notes
                        _currentSong.PlaySong(_beat++);
                    }
                    break;

                // Live mode
                case GameManager.State.Live:

                    if (!_currentProject.Empty)
                    {
                        // If song is finished
                        if (_beat >= _currentSong.BeatsCount || _currentSong.BeatsCount == 0)
                        {
                            onCompleteSong.Invoke();

                            _beat = 0;

                            // Reset vars
                            _beatsElapsedInCurrentSong = 0;
                            _guitarNotes   = 0;
                            _keyboardNotes = 0;
                            _brassNotes    = 0;

                            // Reset shaker density
                            WorldManager.Instance.Shakers = 0;

                            // If another song available, switch
                            if (_currentPlayingSong < _currentProject.Songs.Count - 1)
                            {
                                onStartSong.Invoke();
                                DisableAllAudioSources();
                                _currentPlayingSong++;
                                _currentSong = _currentProject.Songs[_currentPlayingSong];

                                // If no more songs to play
                            }
                            else
                            {
                                // Loop playlist if possible
                                if (_loopPlaylist)
                                {
                                    _currentPlayingSong     = 0;
                                    _beatsElapsedInPlaylist = 0;

                                    // Otherwise go to postplay menu
                                }
                                else
                                {
                                    UIManager.Instance.SwitchToPostplay();
                                }
                            }
                        }

                        if (_currentSong.BeatsCount == 0)
                        {
                            return;
                        }

                        // Play notes
                        _currentSong.PlaySong(_beat);

                        // Calculate song progress
                        float songTotalTime   = _currentSong.BeatsCount * 7200f / TempoToFloat[_tempo] / 4f;
                        float songCurrentTime = (_beat * 7200f / TempoToFloat[_tempo] / 4f) + (7200f / TempoToFloat[_tempo] / 4f) - _beatTimer;
                        SongProgressBar.Instance.SetValue(songCurrentTime / songTotalTime);

                        // Increment vars
                        _beat++;
                        _beatsElapsedInCurrentSong++;
                        _beatsElapsedInPlaylist++;

                        // Update instrument densities
                        _guitarDensity   = (float)_guitarNotes / (float)_beatsElapsedInCurrentSong;
                        _keyboardDensity = (float)_keyboardNotes / (float)_beatsElapsedInCurrentSong;
                        _brassDensity    = (float)_brassNotes / (float)_beatsElapsedInCurrentSong;
                        if (WorldManager.Instance.Shakers > 2)
                        {
                            WorldManager.Instance.Shakers -= 2;
                        }
                        WorldManager.Instance.RoadVariance = Mathf.Clamp(_guitarDensity * 0.6f, 0.2f, 0.6f);
                        WorldManager.Instance.RoadMaxSlope = Mathf.Clamp(_keyboardDensity * 0.002f, 0.002f, 0.001f);
                        //WorldManager.Instance.DecorationDensity = Mathf.Clamp(_brassDensity * 2f, 1f, 2f);
                    }
                    break;
                }

                // Reset beat timer
                _beatTimer = 7200f / TempoToFloat[_tempo] / 4f; // 3600f = 60 fps * 60 seconds

                // Decrement beat timer
            }
            else
            {
                _beatTimer -= 1.667f;
            }
        }