using System.Collections.Generic; using Framework; using UnityEngine; using UnityEditor; namespace SkillEditor { public class PlayAudioHandler : BaseSkillActionHandler { private int _selectIndex; private string[] _audioNames; private string _searchParam; public override void HandleAction(SkillActionClip clip) { if (clip == null) return; DrawWarningLabel("这里需要配置音效全名,具体名字可以找程序沟通"); var newSearchParam = EditorGUILayout.TextField("搜索音效:", _searchParam); if (newSearchParam != _searchParam) { _searchParam = newSearchParam; _UpdateAudioNames(clip.stringParam1); } if (_audioNames == null || _audioNames.Length == 0) { _UpdateAudioNames(clip.stringParam1); } if (_audioNames == null || _audioNames.Length == 0) { DrawWarningLabel("没有找到音效,请检查音效配置表"); return; } GUILayout.Label("共检索到 " + _audioNames.Length + " 个音效"); var newSelectIndex = EditorGUILayout.Popup("音效名字:", _selectIndex, _audioNames); if (newSelectIndex != _selectIndex) { _selectIndex = newSelectIndex; if (_audioNames.Length > 0) { clip.stringParam1 = _audioNames[_selectIndex]; } } } private void _UpdateAudioNames(string nowName) { var totalAudioData = EditorTableManager.instance.tables.AudioSourceConfig.DataList; var cacheList = new List(); var hasEqual = false; for (int i = 0; i < totalAudioData.Count; i++) { var audioData = totalAudioData[i]; if (string.IsNullOrEmpty(_searchParam) || audioData.Key.Contains(_searchParam)) { cacheList.Add(audioData.Key); if (audioData.Key == nowName) { hasEqual = true; } } } if (!hasEqual) { cacheList.Insert(0, nowName); _selectIndex = 0; } else { _selectIndex = Mathf.Max(0, cacheList.IndexOf(nowName)); } _audioNames = cacheList.ToArray(); } } }