GetWaveFormFast() приватный Метод

private GetWaveFormFast ( AudioClip clip, int channel, int fromSample, int toSample, float width, float height ) : Texture2D
clip UnityEngine.AudioClip
channel int
fromSample int
toSample int
width float
height float
Результат UnityEngine.Texture2D
Пример #1
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (AudioClipInspector.s_DefaultIcon == null)
            {
                AudioClipInspector.Init();
            }
            AudioClip audioClip = 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(audioClip) / (int)r.width;
                switch (current.type)
                {
                case EventType.MouseDown:
                case EventType.MouseDrag:
                    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();
                    }
                    break;
                }
                return;
            }
            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");
                Texture2D texture2D;
                if (r.width < 100f)
                {
                    texture2D = AssetPreview.GetAssetPreview(audioClip);
                }
                else
                {
                    texture2D = AudioUtil.GetWaveFormFast(audioClip, 1, 0, audioClip.samples, r.width, r.height);
                }
                if (texture2D == null)
                {
                    GUI.DrawTexture(new Rect
                    {
                        x      = (AudioClipInspector.m_wantedRect.width - (float)AudioClipInspector.s_DefaultIcon.width) / 2f + AudioClipInspector.m_wantedRect.x,
                        y      = (AudioClipInspector.m_wantedRect.height - (float)AudioClipInspector.s_DefaultIcon.height) / 2f + AudioClipInspector.m_wantedRect.y,
                        width  = (float)AudioClipInspector.s_DefaultIcon.width,
                        height = (float)AudioClipInspector.s_DefaultIcon.height
                    }, AudioClipInspector.s_DefaultIcon);
                    base.Repaint();
                }
                else
                {
                    GUI.DrawTexture(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, AudioClipInspector.m_wantedRect.height), texture2D);
                }
                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();
            }
        }
Пример #2
0
        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;
                }
            }
        }