using UnityEngine; using System.Collections.Generic; namespace SK.Framework { /// /// 音频库管理器 /// public class AudioDatabaseController { //音频库列表 private readonly List list; public AudioDatabaseController() { list = new List(); } /// /// 加载音频库 /// /// 音频库资源路径 /// 音频库 /// 加载成功返回true 否则返回false public bool Load(string resourcesPath, out AudioDatabase database) { database = Resources.Load(resourcesPath); if (database != null) { string databaseName = database.databaseName; var index = list.FindIndex(m => m.databaseName == databaseName); if (index == -1) { list.Add(database); return true; } return false; } return false; } /// /// 卸载音频库 /// /// 音频库名称 /// 卸载成功返回true 否则返回false public bool Unload(string databaseName) { var target = list.Find(m => m.databaseName == databaseName); if (target != null) { list.Remove(target); Resources.UnloadAsset(target); return true; } return false; } /// /// 获取音频库 /// /// 音频库名称 /// 音频库 public AudioDatabase Get(string databaseName) { return list.Find(m => m.databaseName == databaseName); } } }