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;
}
}
}