示例#1
0
    public AudioClip Draw(Rect rect, AudioClip audio, bool readOnly = false)
    {
        if (audio != stored)
        {
            stored = audio;
        }
        Rect fieldRect   = new Rect(rect.position, rect.size - new Vector2(buttonWidth * 2 + buttonWidth * 0.25f, 0));
        Rect buttonRect  = new Rect(rect.position + new Vector2(rect.size.x - buttonWidth * 2 - buttonWidth * 0.25f, 0), new Vector2(buttonWidth, rect.height));
        Rect buttonRect2 = new Rect(rect.position + new Vector2(rect.size.x - buttonWidth, 0), new Vector2(buttonWidth, rect.height));

        if (readOnly)
        {
            GUI.enabled = false;
        }
        stored = EditorGUI.ObjectField(fieldRect, stored, typeof(AudioClip), false) as AudioClip;
        if (readOnly)
        {
            GUI.enabled = true;
        }
        if (stored == null)
        {
            GUI.enabled = false;
        }
        if (GUI.Button(buttonRect, playText))
        {
            PublicAudioUtil.PlayClip(stored);
            playing = true;
        }
        if (stored == null)
        {
            GUI.enabled = true;
        }
        if (!playing)
        {
            GUI.enabled = false;
        }
        if (GUI.Button(buttonRect2, stopText))
        {
            PublicAudioUtil.StopAllClips();
        }
        GUI.enabled = true;
        return(stored);
    }
示例#2
0
 public AudioClip DrawLayout(AudioClip audio, bool readOnly = false)
 {
     if (audio != stored)
     {
         stored = audio;
     }
     GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
     if (readOnly)
     {
         GUI.enabled = false;
     }
     stored = EditorGUILayout.ObjectField(stored, typeof(AudioClip), false, GUILayout.ExpandHeight(true)) as AudioClip;
     if (readOnly)
     {
         GUI.enabled = true;
     }
     if (stored == null)
     {
         GUI.enabled = false;
     }
     if (GUILayout.Button(playText, GUILayout.ExpandWidth(false)))
     {
         PublicAudioUtil.PlayClip(stored);
         playing = true;
     }
     if (stored == null)
     {
         GUI.enabled = true;
     }
     if (!playing)
     {
         GUI.enabled = false;
     }
     if (GUILayout.Button(stopText, GUILayout.ExpandWidth(false)))
     {
         PublicAudioUtil.StopAllClips();
     }
     GUI.enabled = true;
     GUILayout.EndHorizontal();
     return(stored);
 }