using System.Collections.Generic; using System.IO; using System.Reflection; using log4net; using UnityEditor; using UnityEngine; public class AudioLibrary : MonoBehaviour { private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public List audios; public string manageableAudioFolder = "Assets/Prefabs/Audio"; public void Awake() { LoadAvailableSounds(); } /// /// Loads all the ManageableAudio prefabs from the specified folder. /// private void LoadAvailableSounds() { string[] files = Directory.GetFiles(manageableAudioFolder, "*.prefab", SearchOption.TopDirectoryOnly); List gos = new List(); foreach (var file in files) { gos.Add(AssetDatabase.LoadAssetAtPath(file)); } foreach (GameObject go in gos) { if (go.TryGetComponent(out _)) { audios.Add(go); } else { Log.Warn("Audio library can only load prefabs with ManageableAudio components!"); } } } }