예제 #1
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        if (audioAsset == null)
        {
            audioAsset = (AudioAsset)target;
        }
        if (playingClip)
        {
            if (!IsClipPlaying(playingClip))
            {
                playingClip             = null;
                playFlag[clipFlagIndex] = false;
            }
        }
        if (audioAsset.audioData == null)
        {
            return;
        }
        for (int i = 0; i < audioAsset.audioData.Count; i++)
        {
            if (audioAsset.audioData[i] == null)
            {
                return;
            }
            audioAsset.audioData[i].audioClip = (AudioClip)EditorGUILayout.ObjectField("Clip", audioAsset.audioData[i].audioClip, typeof(AudioClip), true);

            if (AudioConfig.GetAllTagName().Length == 0)
            {
                AudioConfig config = Resources.Load <AudioConfig>("Audio/AudioSetting/" + typeof(AudioConfig).ToString());
                config.Initialize();
            }
            audioAsset.audioData[i].tag = EditorGUILayout.Popup("选择类型", audioAsset.audioData[i].tag, AudioConfig.GetAllTagName());
            audioAsset.audioData[i].id  = i;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("ID:" + audioAsset.audioData[i].id);
            if (GUILayout.Button(GetFlag(i)))
            {
                if (audioAsset.audioData[i].audioClip != null)
                {
                    if (playFlag[i])
                    {
                        playFlag[i] = false;
                        playingClip = null;
                        StopAllClips();
                        Repaint();
                    }
                    else
                    {
                        if (playingClip)
                        {
                            return;
                        }
                        PlayClip(audioAsset.audioData[i].audioClip);
                        playFlag[i]   = true;
                        playingClip   = audioAsset.audioData[i].audioClip;
                        clipFlagIndex = i;
                        Repaint();
                    }
                }
            }
            if (GUILayout.Button("删除音频", GUILayout.Height(25)))
            {
                audioAsset.audioData.Remove(audioAsset.audioData[i]);
                Repaint();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }

        if (GUILayout.Button("新增音频"))
        {
            audioAsset.audioData.Add(null);
        }
    }