#region Copyright RenGuiYou. All rights reserved. //===================================================== // NeatlyFrameWork // Author: RenGuiyou // Feedback: mailto:750539605@qq.com //===================================================== #endregion using Neatly.Module; using UnityEngine; namespace Neatly.Load.Manager { public class SoundLoadManager : Singleton { private LoadModule m_LoadModule; private readonly SoundPool m_SoundPool = new SoundPool(); public void Init(LoadModule loadModule) { m_LoadModule = loadModule; InitSound(); } private void InitSound() { #if UNITY_EDITOR if (m_LoadModule.GetUseBundle()) #endif { var result = m_LoadModule.LoadAssetBundleDirect(NeatlyConfig.SOUND_PACKAGE).ResultObject; var soundBundle = result as AssetBundle; var audioClip = soundBundle.LoadAllAssets(); for (int i = 0; i < audioClip.Length; i++) { m_SoundPool.Add(audioClip[i].name, audioClip[i]); } soundBundle.Unload(false); } } public AudioClip LoadMusic(string fileName) { #if UNITY_EDITOR if (m_LoadModule.GetUseBundle()) #endif { var musicBundle = m_LoadModule.LoadAssetBundleDirect(string.Format("music_{0}", fileName)).ResultObject as AssetBundle; var asset = musicBundle.LoadAsset(fileName); musicBundle.Unload(false); return asset; } #if UNITY_EDITOR string path = string.Format("data/{0}/{1}{2}", NeatlyConfig.MUSIC_PACKAGE, fileName, NeatlyConfig.SUFFIX_MUSIC); return m_LoadModule.LoadAssetFileSync(path); #endif } public AudioClip LoadSound(string fileName) { #if !UNITY_EDITOR return m_SoundPool.Get(fileName); #else if (m_LoadModule.GetUseBundle()) { return m_SoundPool.Get(fileName); } string path = string.Format("data/{0}/{1}{2}", NeatlyConfig.SOUND_PACKAGE, fileName, NeatlyConfig.SUFFIX_SOUND); return m_LoadModule.LoadAssetFileSync(path); #endif } } }