UnityEditor.AudioUtil.HasPreview C# (CSharp) Method

HasPreview() private method

private HasPreview ( AudioClip clip ) : bool
clip UnityEngine.AudioClip
return bool
        public static extern bool HasPreview(AudioClip clip);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]

Usage Example

示例#1
0
        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();
            }
        }
All Usage Examples Of UnityEditor.AudioUtil::HasPreview