public static void PlayClip(AudioClip clip) { bool loop = false; int startSample = 0; AudioUtil.PlayClip(clip, startSample, loop); }
void PlayClip(AudioClip clip, int startSample = 0, bool loop = false) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(clip, startSample, loop); m_Clip = clip; s_PlayingInstance = this; }
public override void OnPreviewSettings() { MovieTextureInspector.Init(); EditorGUI.BeginDisabledGroup(Application.isPlaying || this.targets.Length > 1); MovieTexture target = this.target as MovieTexture; AudioClip audioClip = target.audioClip; bool flag = PreviewGUI.CycleButton(!target.isPlaying ? 0 : 1, MovieTextureInspector.s_PlayIcons) != 0; if (flag != target.isPlaying) { if (flag) { target.Stop(); target.Play(); if ((Object)audioClip != (Object)null) { AudioUtil.PlayClip(audioClip); } } else { target.Pause(); if ((Object)audioClip != (Object)null) { AudioUtil.PauseClip(audioClip); } } } EditorGUI.EndDisabledGroup(); }
public override void OnPreviewSettings() { MovieTextureInspector.Init(); EditorGUI.BeginDisabledGroup(Application.isPlaying || base.targets.Length > 1); MovieTexture movieTexture = this.target as MovieTexture; AudioClip audioClip = movieTexture.audioClip; bool flag = PreviewGUI.CycleButton((!movieTexture.isPlaying) ? 0 : 1, MovieTextureInspector.s_PlayIcons) != 0; if (flag != movieTexture.isPlaying) { if (flag) { movieTexture.Stop(); movieTexture.Play(); if (audioClip != null) { AudioUtil.PlayClip(audioClip); } } else { movieTexture.Pause(); if (audioClip != null) { AudioUtil.PauseClip(audioClip); } } } EditorGUI.EndDisabledGroup(); }
public override void OnPreviewSettings() { Init(); using (new EditorGUI.DisabledScope(Application.isPlaying || (base.targets.Length > 1))) { MovieTexture target = base.target as MovieTexture; AudioClip audioClip = target.audioClip; bool flag = PreviewGUI.CycleButton(!target.isPlaying ? 0 : 1, s_PlayIcons) != 0; if (flag != target.isPlaying) { if (flag) { target.Stop(); target.Play(); if (audioClip != null) { AudioUtil.PlayClip(audioClip); } } else { target.Pause(); if (audioClip != null) { AudioUtil.PauseClip(audioClip); } } } } }
public override void OnPreviewSettings() { Init(); // Disallow playing movie previews in play mode. Better not to interfere // with any playback the game does. // Also disallow if more than one MovieClip selected (for now). using (new EditorGUI.DisabledScope(Application.isPlaying || targets.Length > 1)) { MovieTexture t = target as MovieTexture; AudioClip ac = t.audioClip; bool isPlaying = PreviewGUI.CycleButton(t.isPlaying ? 1 : 0, s_PlayIcons) != 0; if (isPlaying != t.isPlaying) { if (isPlaying) { t.Stop(); t.Play(); if (ac != null) { AudioUtil.PlayClip(ac); } } else { t.Pause(); if (ac != null) { AudioUtil.PauseClip(ac); } } } } }
public override void OnPreviewSettings() { if (s_DefaultIcon == null) { Init(); } AudioClip clip = target as AudioClip; using (new EditorGUI.DisabledScope(AudioUtil.IsMovieAudio(clip))) { bool isEditingMultipleObjects = targets.Length > 1; using (new EditorGUI.DisabledScope(isEditingMultipleObjects)) { bool oldAutoPlay = isEditingMultipleObjects ? false : m_bAutoPlay; bool newAutoPlay = PreviewGUI.CycleButton(oldAutoPlay ? 1 : 0, s_AutoPlayIcons) != 0; if (oldAutoPlay != newAutoPlay) { m_bAutoPlay = newAutoPlay; InspectorWindow.RepaintAllInspectors(); } bool oldLoop = isEditingMultipleObjects ? false : m_bLoop; bool newLoop = PreviewGUI.CycleButton(oldLoop ? 1 : 0, s_LoopIcons) != 0; if (oldLoop != newLoop) { m_bLoop = newLoop; if (playing) { AudioUtil.LoopClip(clip, newLoop); } InspectorWindow.RepaintAllInspectors(); } } using (new EditorGUI.DisabledScope(isEditingMultipleObjects && !playing && m_PlayingInspector != this)) { bool curPlaying = m_PlayingInspector == this && playing; bool newPlaying = PreviewGUI.CycleButton(curPlaying ? 1 : 0, s_PlayIcons) != 0; if (newPlaying != curPlaying) { AudioUtil.StopAllClips(); if (newPlaying) { AudioUtil.PlayClip(clip, 0, m_bLoop); m_PlayingClip = clip; m_PlayingInspector = this; } } } } }
public override void OnPreviewSettings() { if (AudioClipInspector.s_DefaultIcon == null) { AudioClipInspector.Init(); } AudioClip audioClip = base.target as AudioClip; using (new EditorGUI.DisabledScope(AudioUtil.IsMovieAudio(audioClip))) { bool flag = base.targets.Length > 1; using (new EditorGUI.DisabledScope(flag)) { bool flag2 = !flag && AudioClipInspector.m_bAutoPlay; bool flag3 = PreviewGUI.CycleButton((!flag2) ? 0 : 1, AudioClipInspector.s_AutoPlayIcons) != 0; if (flag2 != flag3) { AudioClipInspector.m_bAutoPlay = flag3; InspectorWindow.RepaintAllInspectors(); } bool flag4 = !flag && AudioClipInspector.m_bLoop; bool flag5 = PreviewGUI.CycleButton((!flag4) ? 0 : 1, AudioClipInspector.s_LoopIcons) != 0; if (flag4 != flag5) { AudioClipInspector.m_bLoop = flag5; if (AudioClipInspector.playing) { AudioUtil.LoopClip(audioClip, flag5); } InspectorWindow.RepaintAllInspectors(); } } using (new EditorGUI.DisabledScope(flag && !AudioClipInspector.playing && AudioClipInspector.m_PlayingInspector != this)) { bool flag6 = AudioClipInspector.m_PlayingInspector == this && AudioClipInspector.playing; bool flag7 = PreviewGUI.CycleButton((!flag6) ? 0 : 1, AudioClipInspector.s_PlayIcons) != 0; if (flag7 != flag6) { AudioUtil.StopAllClips(); if (flag7) { AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop); AudioClipInspector.m_PlayingClip = audioClip; AudioClipInspector.m_PlayingInspector = this; } } } } }
public override void OnPreviewSettings() { if (AudioClipInspector.s_DefaultIcon == null) { AudioClipInspector.Init(); } AudioClip audioClip = base.target as AudioClip; using (new EditorGUI.DisabledScope(AudioUtil.IsMovieAudio(audioClip))) { bool flag = base.targets.Length > 1; using (new EditorGUI.DisabledScope(flag)) { AudioClipInspector.m_bAutoPlay = (!flag && AudioClipInspector.m_bAutoPlay); AudioClipInspector.m_bAutoPlay = (PreviewGUI.CycleButton((!AudioClipInspector.m_bAutoPlay) ? 0 : 1, AudioClipInspector.s_AutoPlayIcons) != 0); } bool bLoop = AudioClipInspector.m_bLoop; AudioClipInspector.m_bLoop = (PreviewGUI.CycleButton((!AudioClipInspector.m_bLoop) ? 0 : 1, AudioClipInspector.s_LoopIcons) != 0); if (bLoop != AudioClipInspector.m_bLoop && this.playing) { AudioUtil.LoopClip(audioClip, AudioClipInspector.m_bLoop); } using (new EditorGUI.DisabledScope(flag && !this.playing)) { bool flag2 = PreviewGUI.CycleButton((!this.playing) ? 0 : 1, AudioClipInspector.s_PlayIcons) != 0; if (flag2 != this.playing) { if (flag2) { AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = audioClip; } else { AudioUtil.StopAllClips(); this.m_PlayingClip = null; } } } } }
public override void OnPreviewSettings() { if ((UnityEngine.Object)AudioClipInspector.s_DefaultIcon == (UnityEngine.Object)null) { AudioClipInspector.Init(); } AudioClip target = this.target as AudioClip; EditorGUI.BeginDisabledGroup(AudioUtil.IsMovieAudio(target)); bool disabled = this.targets.Length > 1; EditorGUI.BeginDisabledGroup(disabled); AudioClipInspector.m_bAutoPlay = !disabled && AudioClipInspector.m_bAutoPlay; AudioClipInspector.m_bAutoPlay = PreviewGUI.CycleButton(!AudioClipInspector.m_bAutoPlay ? 0 : 1, AudioClipInspector.s_AutoPlayIcons) != 0; EditorGUI.EndDisabledGroup(); bool bLoop = AudioClipInspector.m_bLoop; AudioClipInspector.m_bLoop = PreviewGUI.CycleButton(!AudioClipInspector.m_bLoop ? 0 : 1, AudioClipInspector.s_LoopIcons) != 0; if (bLoop != AudioClipInspector.m_bLoop && this.playing) { AudioUtil.LoopClip(target, AudioClipInspector.m_bLoop); } EditorGUI.BeginDisabledGroup(disabled && !this.playing); bool flag = PreviewGUI.CycleButton(!this.playing ? 0 : 1, AudioClipInspector.s_PlayIcons) != 0; if (flag != this.playing) { if (flag) { AudioUtil.PlayClip(target, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = target; } else { AudioUtil.StopAllClips(); this.m_PlayingClip = (AudioClip)null; } } EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); }
public override void OnPreviewSettings() { if (s_DefaultIcon == null) { Init(); } AudioClip target = this.target as AudioClip; EditorGUI.BeginDisabledGroup(AudioUtil.IsMovieAudio(target)); bool disabled = base.targets.Length > 1; EditorGUI.BeginDisabledGroup(disabled); m_bAutoPlay = !disabled ? m_bAutoPlay : false; m_bAutoPlay = PreviewGUI.CycleButton(!m_bAutoPlay ? 0 : 1, s_AutoPlayIcons) != 0; EditorGUI.EndDisabledGroup(); bool bLoop = m_bLoop; m_bLoop = PreviewGUI.CycleButton(!m_bLoop ? 0 : 1, s_LoopIcons) != 0; if ((bLoop != m_bLoop) && this.playing) { AudioUtil.LoopClip(target, m_bLoop); } EditorGUI.BeginDisabledGroup(disabled && !this.playing); bool flag3 = PreviewGUI.CycleButton(!this.playing ? 0 : 1, s_PlayIcons) != 0; if (flag3 != this.playing) { if (flag3) { AudioUtil.PlayClip(target, 0, m_bLoop); this.m_PlayingClip = target; } else { AudioUtil.StopAllClips(); this.m_PlayingClip = null; } } EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (s_DefaultIcon == null) { Init(); } AudioClip clip = target as AudioClip; Event evt = Event.current; if (evt.type != EventType.Repaint && evt.type != EventType.Layout && evt.type != EventType.Used) { int px2sample = (AudioUtil.GetSampleCount(clip) / (int)r.width); switch (evt.type) { case EventType.MouseDrag: case EventType.MouseDown: { if (r.Contains(evt.mousePosition) && !AudioUtil.IsMovieAudio(clip)) { if (m_PlayingClip != clip || !AudioUtil.IsClipPlaying(clip)) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(clip, 0, m_bLoop); m_PlayingClip = clip; m_PlayingInspector = this; } AudioUtil.SetClipSamplePosition(clip, px2sample * (int)evt.mousePosition.x); evt.Use(); } } break; } return; } if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } int c = AudioUtil.GetChannelCount(clip); m_wantedRect = new Rect(r.x, r.y, r.width, r.height); float sec2px = ((float)m_wantedRect.width / clip.length); bool previewAble = AudioUtil.HasPreview(clip) || !(AudioUtil.IsTrackerFile(clip) || AudioUtil.IsMovieAudio(clip)); if (!previewAble) { float labelY = (r.height > 150) ? r.y + (r.height / 2) - 10 : r.y + (r.height / 2) - 25; if (r.width > 64) { if (AudioUtil.IsTrackerFile(clip)) { EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(clip) + " channels.")); } else if (AudioUtil.IsMovieAudio(clip)) { if (r.width > 450) { EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), "Audio is attached to a movie. To audition the sound, play the movie."); } else { EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), "Audio is attached to a movie."); EditorGUI.DropShadowLabel(new Rect(r.x, labelY + 10, r.width, 20), "To audition the sound, play the movie."); } } else { EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), "Can not show PCM data for this file"); } } if (m_PlayingInspector == this && m_PlayingClip == clip) { float t = AudioUtil.GetClipPosition(clip); System.TimeSpan ts = new System.TimeSpan(0, 0, 0, 0, (int)(t * 1000.0f)); EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20), string.Format("Playing - {0:00}:{1:00}.{2:000}", ts.Minutes, ts.Seconds, ts.Milliseconds)); } } else { PreviewGUI.BeginScrollView(m_wantedRect, m_Position, m_wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); if (Event.current.type == EventType.Repaint) { DoRenderPreview(clip, AudioUtil.GetImporterFromClip(clip), m_wantedRect, 1.0f); } for (int i = 0; i < c; ++i) { if (c > 1 && r.width > 64) { var labelRect = new Rect(m_wantedRect.x + 5, m_wantedRect.y + (m_wantedRect.height / c) * i, 30, 20); EditorGUI.DropShadowLabel(labelRect, "ch " + (i + 1).ToString()); } } if (m_PlayingInspector == this && m_PlayingClip == clip) { float t = AudioUtil.GetClipPosition(clip); System.TimeSpan ts = new System.TimeSpan(0, 0, 0, 0, (int)(t * 1000.0f)); GUI.DrawTexture(new Rect(m_wantedRect.x + (int)(sec2px * t), m_wantedRect.y, 2, m_wantedRect.height), EditorGUIUtility.whiteTexture); if (r.width > 64) { EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20), string.Format("{0:00}:{1:00}.{2:000}", ts.Minutes, ts.Seconds, ts.Milliseconds)); } else { EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20), string.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds)); } } PreviewGUI.EndScrollView(); } // autoplay start? if (m_bAutoPlay && m_PlayingClip != clip && m_PlayingInspector == this) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(clip, 0, m_bLoop); m_PlayingClip = clip; m_PlayingInspector = this; } // force update GUI if (playing) { GUIView.current.Repaint(); } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (AudioClipInspector.s_DefaultIcon == null) { AudioClipInspector.Init(); } AudioClip audioClip = base.target as AudioClip; Event current = Event.current; if (current.type != EventType.Repaint && current.type != EventType.Layout && current.type != EventType.Used) { int num = AudioUtil.GetSampleCount(audioClip) / (int)r.width; EventType type = current.type; if (type == EventType.MouseDrag || type == EventType.MouseDown) { if (r.Contains(current.mousePosition) && !AudioUtil.IsMovieAudio(audioClip)) { if (this.m_PlayingClip != audioClip) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = audioClip; } AudioUtil.SetClipSamplePosition(audioClip, num * (int)current.mousePosition.x); current.Use(); } } } else { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } int channelCount = AudioUtil.GetChannelCount(audioClip); AudioClipInspector.m_wantedRect = new Rect(r.x, r.y, r.width, r.height); float num2 = AudioClipInspector.m_wantedRect.width / audioClip.length; if (!AudioUtil.HasPreview(audioClip) && (AudioUtil.IsTrackerFile(audioClip) || AudioUtil.IsMovieAudio(audioClip))) { float num3 = (r.height <= 150f) ? (r.y + r.height / 2f - 25f) : (r.y + r.height / 2f - 10f); if (r.width > 64f) { if (AudioUtil.IsTrackerFile(audioClip)) { EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(audioClip) + " channels.", new object[0])); } else if (AudioUtil.IsMovieAudio(audioClip)) { if (r.width > 450f) { EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Audio is attached to a movie. To audition the sound, play the movie."); } else { EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Audio is attached to a movie."); EditorGUI.DropShadowLabel(new Rect(r.x, num3 + 10f, r.width, 20f), "To audition the sound, play the movie."); } } else { EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Can not show PCM data for this file"); } } if (this.m_PlayingClip == audioClip) { float clipPosition = AudioUtil.GetClipPosition(audioClip); TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)(clipPosition * 1000f)); EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("Playing - {0:00}:{1:00}.{2:000}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds)); } } else { PreviewGUI.BeginScrollView(AudioClipInspector.m_wantedRect, this.m_Position, AudioClipInspector.m_wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); if (Event.current.type == EventType.Repaint) { this.DoRenderPreview(audioClip, AudioUtil.GetImporterFromClip(audioClip), AudioClipInspector.m_wantedRect, 1f); } for (int i = 0; i < channelCount; i++) { if (channelCount > 1 && r.width > 64f) { Rect position = new Rect(AudioClipInspector.m_wantedRect.x + 5f, AudioClipInspector.m_wantedRect.y + AudioClipInspector.m_wantedRect.height / (float)channelCount * (float)i, 30f, 20f); EditorGUI.DropShadowLabel(position, "ch " + (i + 1).ToString()); } } if (this.m_PlayingClip == audioClip) { float clipPosition2 = AudioUtil.GetClipPosition(audioClip); TimeSpan timeSpan2 = new TimeSpan(0, 0, 0, 0, (int)(clipPosition2 * 1000f)); GUI.DrawTexture(new Rect(AudioClipInspector.m_wantedRect.x + (float)((int)(num2 * clipPosition2)), AudioClipInspector.m_wantedRect.y, 2f, AudioClipInspector.m_wantedRect.height), EditorGUIUtility.whiteTexture); if (r.width > 64f) { EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}.{2:000}", timeSpan2.Minutes, timeSpan2.Seconds, timeSpan2.Milliseconds)); } else { EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}", timeSpan2.Minutes, timeSpan2.Seconds)); } if (!AudioUtil.IsClipPlaying(audioClip)) { this.m_PlayingClip = null; } } PreviewGUI.EndScrollView(); } if (AudioClipInspector.m_bPlayFirst) { AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = audioClip; AudioClipInspector.m_bPlayFirst = false; } if (this.playing) { GUIView.current.Repaint(); } } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if ((UnityEngine.Object)AudioClipInspector.s_DefaultIcon == (UnityEngine.Object)null) { AudioClipInspector.Init(); } AudioClip target = this.target as AudioClip; Event current = Event.current; if (current.type != EventType.Repaint && current.type != EventType.Layout && current.type != EventType.Used) { int num = AudioUtil.GetSampleCount(target) / (int)r.width; switch (current.type) { case EventType.MouseDown: case EventType.MouseDrag: if (!r.Contains(current.mousePosition) || AudioUtil.IsMovieAudio(target)) { break; } if ((UnityEngine.Object) this.m_PlayingClip != (UnityEngine.Object)target) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(target, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = target; } AudioUtil.SetClipSamplePosition(target, num * (int)current.mousePosition.x); current.Use(); break; } } else { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } int channelCount = AudioUtil.GetChannelCount(target); AudioClipInspector.m_wantedRect = new Rect(r.x, r.y, r.width, r.height); float num = AudioClipInspector.m_wantedRect.width / target.length; if (!AudioUtil.HasPreview(target) && (AudioUtil.IsTrackerFile(target) ? 1 : (AudioUtil.IsMovieAudio(target) ? 1 : 0)) != 0) { float y = (double)r.height <= 150.0 ? (float)((double)r.y + (double)r.height / 2.0 - 25.0) : (float)((double)r.y + (double)r.height / 2.0 - 10.0); if ((double)r.width > 64.0) { if (AudioUtil.IsTrackerFile(target)) { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), string.Format("Module file with " + (object)AudioUtil.GetMusicChannelCount(target) + " channels.")); } else if (AudioUtil.IsMovieAudio(target)) { if ((double)r.width > 450.0) { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie. To audition the sound, play the movie."); } else { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie."); EditorGUI.DropShadowLabel(new Rect(r.x, y + 10f, r.width, 20f), "To audition the sound, play the movie."); } } else { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Can not show PCM data for this file"); } } if ((UnityEngine.Object) this.m_PlayingClip == (UnityEngine.Object)target) { TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)((double)AudioUtil.GetClipPosition(target) * 1000.0)); EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("Playing - {0:00}:{1:00}.{2:000}", (object)timeSpan.Minutes, (object)timeSpan.Seconds, (object)timeSpan.Milliseconds)); } } else { PreviewGUI.BeginScrollView(AudioClipInspector.m_wantedRect, this.m_Position, AudioClipInspector.m_wantedRect, (GUIStyle)"PreHorizontalScrollbar", (GUIStyle)"PreHorizontalScrollbarThumb"); if (Event.current.type == EventType.Repaint) { this.DoRenderPreview(target, AudioUtil.GetImporterFromClip(target), AudioClipInspector.m_wantedRect, 1f); } for (int index = 0; index < channelCount; ++index) { if (channelCount > 1 && (double)r.width > 64.0) { EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x + 5f, AudioClipInspector.m_wantedRect.y + AudioClipInspector.m_wantedRect.height / (float)channelCount * (float)index, 30f, 20f), "ch " + (index + 1).ToString()); } } if ((UnityEngine.Object) this.m_PlayingClip == (UnityEngine.Object)target) { float clipPosition = AudioUtil.GetClipPosition(target); TimeSpan timeSpan = new TimeSpan(0, 0, 0, 0, (int)((double)clipPosition * 1000.0)); GUI.DrawTexture(new Rect(AudioClipInspector.m_wantedRect.x + (float)(int)((double)num * (double)clipPosition), AudioClipInspector.m_wantedRect.y, 2f, AudioClipInspector.m_wantedRect.height), (Texture)EditorGUIUtility.whiteTexture); if ((double)r.width > 64.0) { EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}.{2:000}", (object)timeSpan.Minutes, (object)timeSpan.Seconds, (object)timeSpan.Milliseconds)); } else { EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}", (object)timeSpan.Minutes, (object)timeSpan.Seconds)); } if (!AudioUtil.IsClipPlaying(target)) { this.m_PlayingClip = (AudioClip)null; } } PreviewGUI.EndScrollView(); } if (AudioClipInspector.m_bPlayFirst) { AudioUtil.PlayClip(target, 0, AudioClipInspector.m_bLoop); this.m_PlayingClip = target; AudioClipInspector.m_bPlayFirst = false; } if (!this.playing) { return; } GUIView.current.Repaint(); } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (s_DefaultIcon == null) { Init(); } AudioClip target = this.target as AudioClip; Event current = Event.current; if (((current.type == EventType.Repaint) || (current.type == EventType.Layout)) || (current.type == EventType.Used)) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } int channelCount = AudioUtil.GetChannelCount(target); m_wantedRect = new Rect(r.x, r.y, r.width, r.height); float num3 = m_wantedRect.width / target.length; if (!AudioUtil.HasPreview(target) && (AudioUtil.IsTrackerFile(target) || AudioUtil.IsMovieAudio(target))) { float y = (r.height <= 150f) ? ((r.y + (r.height / 2f)) - 25f) : ((r.y + (r.height / 2f)) - 10f); if (r.width > 64f) { if (AudioUtil.IsTrackerFile(target)) { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(target) + " channels.", new object[0])); } else if (AudioUtil.IsMovieAudio(target)) { if (r.width > 450f) { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie. To audition the sound, play the movie."); } else { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie."); EditorGUI.DropShadowLabel(new Rect(r.x, y + 10f, r.width, 20f), "To audition the sound, play the movie."); } } else { EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Can not show PCM data for this file"); } } if (this.m_PlayingClip == target) { float clipPosition = AudioUtil.GetClipPosition(target); TimeSpan span = new TimeSpan(0, 0, 0, 0, (int)(clipPosition * 1000f)); EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("Playing - {0:00}:{1:00}.{2:000}", span.Minutes, span.Seconds, span.Milliseconds)); } } else { PreviewGUI.BeginScrollView(m_wantedRect, this.m_Position, m_wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); Texture2D image = null; if (r.width < 100f) { image = AssetPreview.GetAssetPreview(target); } else { image = AudioUtil.GetWaveFormFast(target, 1, 0, target.samples, r.width, r.height); } if (image == null) { Rect position = new Rect { x = ((m_wantedRect.width - s_DefaultIcon.width) / 2f) + m_wantedRect.x, y = ((m_wantedRect.height - s_DefaultIcon.height) / 2f) + m_wantedRect.y, width = s_DefaultIcon.width, height = s_DefaultIcon.height }; GUI.DrawTexture(position, s_DefaultIcon); base.Repaint(); } else { GUI.DrawTexture(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, m_wantedRect.height), image); } for (int i = 0; i < channelCount; i++) { if ((channelCount > 1) && (r.width > 64f)) { Rect rect2 = new Rect(m_wantedRect.x + 5f, m_wantedRect.y + ((m_wantedRect.height / ((float)channelCount)) * i), 30f, 20f); EditorGUI.DropShadowLabel(rect2, "ch " + ((i + 1)).ToString()); } } if (this.m_PlayingClip == target) { float num7 = AudioUtil.GetClipPosition(target); TimeSpan span2 = new TimeSpan(0, 0, 0, 0, (int)(num7 * 1000f)); GUI.DrawTexture(new Rect(m_wantedRect.x + ((int)(num3 * num7)), m_wantedRect.y, 2f, m_wantedRect.height), EditorGUIUtility.whiteTexture); if (r.width > 64f) { EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}.{2:000}", span2.Minutes, span2.Seconds, span2.Milliseconds)); } else { EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}", span2.Minutes, span2.Seconds)); } if (!AudioUtil.IsClipPlaying(target)) { this.m_PlayingClip = null; } } PreviewGUI.EndScrollView(); } if (m_bPlayFirst) { AudioUtil.PlayClip(target, 0, m_bLoop); this.m_PlayingClip = target; m_bPlayFirst = false; } if (this.playing) { GUIView.current.Repaint(); } } else { int num = AudioUtil.GetSampleCount(target) / ((int)r.width); switch (current.type) { case EventType.MouseDown: case EventType.MouseDrag: if (r.Contains(current.mousePosition) && !AudioUtil.IsMovieAudio(target)) { if (this.m_PlayingClip != target) { AudioUtil.StopAllClips(); AudioUtil.PlayClip(target, 0, m_bLoop); this.m_PlayingClip = target; } AudioUtil.SetClipSamplePosition(target, num * ((int)current.mousePosition.x)); current.Use(); } break; } } }