/// <summary> /// Checks if a rythmic pulse can be applied at the given time in seconds /// </summary> private void PulseCheck(float t0) { if ((t0 + pulseFrameOffset * Time.deltaTime) % MajorTime <= Time.deltaTime) { MajorNote?.Invoke(); AnyNote?.Invoke(); } else if ((t0 + pulseFrameOffset * Time.deltaTime) % MinorTime <= Time.deltaTime) { MinorNote?.Invoke(); AnyNote?.Invoke(); } }
protected void NoteHit() { fallTime = 0; switch (type) { case PropertyType.Scale: transform.DOScale(intensityMul, frequency).SetEase(easing); stagger?.Invoke(); break; case PropertyType.Rotation: Vector3 curRot = transform.rotation.eulerAngles; transform.DORotate(curRot + intensityMul * Vector3.forward, frequency).SetEase(easing); stagger?.Invoke(); //transform.DORotate break; } }
/// <summary> /// Start playback after a delay /// </summary> /// <returns></returns> public IEnumerator PlayDelay() { delayTime = 0; //StartCoroutine(BrickSpawner.instance.Reset()); yield return(new WaitForSeconds(PickupTime)); IsPlaying = true; OnPlaySong?.Invoke(); song.Play(); playInitiater = null; print("Playing!"); }
/// <summary> /// pauses playback /// </summary> public void Pause() { if (playInitiater != null) { // Paused During pickup StopCoroutine(playInitiater); playInitiater = null; } else { // Paused during song IsPlaying = false; song.Pause(); OnPauseSong?.Invoke(); print("Paused!"); // quantize play time to the nearest measure PlayTime -= (PlayTime % MajorTime); song.time = PlayTime; //SaveSongData(); } }
void UpdateNormalizedSpectrum() { for (int i = 0; i < reducedSpectrum.Length; i++) { if (reducedSpectrum[i] > reducedSpectrumMaximum[i]) { reducedSpectrumMaximum[i] = reducedSpectrum[i]; } normalizedReducedSpectrum[i] = reducedSpectrum[i] / reducedSpectrumMaximum[i]; normalizedReducedSpectrumBuffer[i] = reducedSpectrumBuffer[i] / reducedSpectrumMaximum[i]; //Il fait soit un event Off ou On if (normalizedReducedSpectrumBuffer[i] < triggerThreshold) { eventsOff?.Invoke(i); } else { eventsOn?.Invoke(i); } } }
internal void InvokeMusicEvent(MusicEvent arg) { MusicEvent?.Invoke(this, arg); }
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; } }
internal void InvokeMusicEvent(MusicEvent arg) => MusicEvent?.Invoke(null, arg);