void OnEventEasyChange(KoreographyEvent evt) { string txt = evt.GetTextValue(); if (m_PreSample == evt.StartSample) { return; } m_PreSample = evt.StartSample; string[] values = txt.Split(','); if (values.Length < 3) { return; } MusicEventData data = new MusicEventData(); data.oper = (MusicOper)int.Parse(values[0]); data.player = (MusicPlayer)int.Parse(values[1]); data.content = values[2]; data.sampleLen = (evt.EndSample - evt.StartSample) / (float)Koreographer.GetSampleRate(m_AudioClip.name); //data.oper = MusicOper.LongUp; //data.sampleLen = 1.5f; //Debug.Log(txt + " " + data.sampleLen); if (EventChangeHandler != null) { EventChangeHandler(data); } }
void Update() { // The Demo song has a quarter note as it's beat value. This will get us the current // quarter note! int curQuarterNote = Mathf.FloorToInt(Koreographer.GetBeatTime()); if (curQuarterNote != lastQuarterNote) { // Turn the group on when the beat is an even number. SwitchGroup(quarterNoteGroup, lastQuarterNote % 2 != 0); lastQuarterNote = curQuarterNote; } // The 'null' value asks Koreographer to look at the beat time of what it considers // the current "Main" song. These demos use a basic player with a single song and // define that as the Main song. Therefore there is no need to specify it. The // '2' parameter, tells Koreographer to divide each beat into 2 equal parts. As the // base beat value is 4, this will result in eighth notes. int curEighthNote = Mathf.FloorToInt(Koreographer.GetBeatTime(null, 2)); if (curEighthNote != lastEighthNote) { SwitchGroup(eighthNoteGroup, lastEighthNote % 2 != 0); lastEighthNote = curEighthNote; } }
private int iLastEighthNote = 0; // 上一个八分音符 private void Update() { /// 四分音符 int iCurQuarterNote = Mathf.RoundToInt(Koreographer.GetBeatTime()); // 当前的四分音符 != 上一个四分音符 if (iCurQuarterNote != iLastQuarterNote) { // 开关灯 SwitchGroup(m_QuarterNoteGroup, iLastQuarterNote % 2 != 0); // 记录此时的四分音符 iLastQuarterNote = iCurQuarterNote; } /// 八分音符 int iCurEighthNote = Mathf.RoundToInt(Koreographer.GetBeatTime(null, 2)); // 当前的八分音符 != 上一个八分音符 if (iCurEighthNote != iLastEighthNote) { // 开关灯 SwitchGroup(m_EighthNoteGroup, iLastEighthNote % 2 != 0); // 记录此时的八分音符 iLastEighthNote = iCurEighthNote; } }
void OnParticleControlEvent(KoreographyEvent evt) { // If two Koreography span events overlap, this can be called twice in the same frame. // This check ensures that we only ask the particle system to emit once for any frame. if (Time.frameCount != lastEmitFrame) { // Spans get called over a specified amount of music time. Use Koreographer's beat delta // to calculate the number of particles to emit this frame based on the "particlesPerBeat" // rate configured in the Inspector. int particleCount = (int)(particlesPerBeat * Koreographer.GetBeatTimeDelta()); // Emit the calculated number of particles! particleCom.Emit(particleCount); lastEmitFrame = Time.frameCount; } }
public FMODAudioVisor(EventInstance fmodInstance, Koreographer targetKoreographer, AudioClip clip) { koreographerCom = targetKoreographer; if (koreographerCom == null) { koreographerCom = Koreographer.Instance; } this.clip = clip; audioCom = fmodInstance; AudioSettings.OnAudioConfigurationChanged += UpdateAudioConfiguration; UpdateAudioConfiguration(false); lastFrameStats = GetFrameStats(); audioCom.getDescription(out evtDescription); sourceSampleTime = GetAudioSampleTime(); }
int sourceSampleTime = -1; // The most recently read sample time from the AudioSource. #endregion Fields #region Constructors /// <summary> /// Initializes a new instance of the <see cref="AudioVisor"/> class. This will /// connect the AudioSource to a Koreographer. /// </summary> /// <param name="sourceCom">The AudioSource component to watch.</param> /// <param name="overrideKoreographer">If specified, updates are sent to this /// Koreographer. Otherwise they use the default Singleton Koreographer.</param> public AudioVisor(AudioSource sourceCom, Koreographer overrideKoreographer = null) { int bufferNum = 0; AudioSettings.GetDSPBufferSize(out audioBufferLen, out bufferNum); // Potentially store a specific Koreographer to report to. koreographerCom = overrideKoreographer; if (koreographerCom == null) { koreographerCom = Koreographer.Instance; } audioCom = sourceCom; // This class shouldn't work without a valid AudioSource. if (audioCom == null) { System.NullReferenceException e = new System.NullReferenceException("AudioVisor does not work with a null AudioSource."); throw e; } // Initialize timings. sourceSampleTime = audioCom.timeSamples; }
void Awake() { _instance = this; }
// Start is called before the first frame update void Start() { Koreographer = GetComponent <Koreographer>(); Koreographer.Instance.RegisterForEvents("NewKoreographyTrack", lightChange); light = this.gameObject.GetComponent <Light>(); }
private void CreateParticle(KoreographyEvent koreographyEvent) { int iParticleCount = (int)(Koreographer.GetBeatTimeDelta() * m_fParticlePerBeat); m_ps.Emit(iParticleCount); }
private void Awake() { koreographer = Koreographer.Instance; koreographer.musicPlaybackController = this; InstantiateAudio(); }
private void CreateParticle(KoreographyEvent koreographyEvent) { int particleCount = (int)(Koreographer.GetBeatTimeDelta() * particlesPerBeat); particleSystemCom.Emit(particleCount); }