void Update() { AudioEventContainer audioEventContainer = Selection.activeObject as AudioEventContainer; if (audioEventContainer == null) { return; } activeAudioEventContainer = audioEventContainer; AudioClip obj = audioEventContainer.clip; if (obj != null && obj != activeAudioClip) { activeAudioClip = obj; activeAudioClipData = new float[activeAudioClip.samples * activeAudioClip.channels]; activeClipChannelOneData = new float[activeAudioClip.samples]; if (activeAudioClip.channels == 2) { activeClipChannelTwoData = new float[activeAudioClip.samples]; } activeAudioClip.GetData(activeAudioClipData, 0); int c = 0; for (int i = 0; i < activeAudioClipData.Length; i += 2) { activeClipChannelOneData[c] = activeAudioClipData[i]; ++c; } if (activeAudioClip.channels == 2) { c = 0; for (int j = 1; j < activeAudioClipData.Length; j += 2) { activeClipChannelTwoData[c] = activeAudioClipData[j]; ++c; } } dirty = true; selectionPosition = 0; selectedIndex = 0; selectedTime = 0; } if (activeAudioClip != null) { float percent = selectedIndex / (float)activeClipChannelOneData.Length; selectedTime = percent * activeAudioClip.length; } }
void Update() { AudioEventContainer audioEventContainer = Selection.activeObject as AudioEventContainer; if ( audioEventContainer == null ) { return; } activeAudioEventContainer = audioEventContainer; AudioClip obj = audioEventContainer.clip; if ( obj != null && obj != activeAudioClip ) { activeAudioClip = obj; activeAudioClipData = new float[activeAudioClip.samples * activeAudioClip.channels]; activeClipChannelOneData = new float[activeAudioClip.samples]; if ( activeAudioClip.channels == 2 ) { activeClipChannelTwoData = new float[activeAudioClip.samples]; } activeAudioClip.GetData( activeAudioClipData, 0 ); int c = 0; for ( int i = 0; i < activeAudioClipData.Length; i += 2 ) { activeClipChannelOneData[c] = activeAudioClipData[i]; ++c; } if ( activeAudioClip.channels == 2 ) { c = 0; for ( int j = 1; j < activeAudioClipData.Length; j += 2 ) { activeClipChannelTwoData[c] = activeAudioClipData[j]; ++c; } } dirty = true; selectionPosition = 0; selectedIndex = 0; selectedTime = 0; } if ( activeAudioClip != null ) { float percent = selectedIndex / (float)activeClipChannelOneData.Length; selectedTime = percent * activeAudioClip.length; } }