private static void Init() { //已经初始化则不处理了 if (null != self) { return; } self = GameObject.FindObjectOfType <KAssetBundle>(); if (self == null) { KLogger.Log("开始初始化|KAssetBundle"); GameObject go = new GameObject(); go.name = "__KAssetBundle__"; DontDestroyOnLoad(go); //场景切换也保留 self = go.AddComponent <KAssetBundle>(); } }
/// <summary> /// 调用oneShotAudioSource的PlayOneShot播放音频文件,直接使用已经预加载的AB资源 /// </summary> /// <param name="volumeScale">音量缩放比</param> public static void PlayOneShot(string audioABName, float volumeScale = 1.0f) { PlayOneShot(KAssetBundle.GetObject <AudioClip>(audioABName), volumeScale); }
/// <summary> /// 调用bgAudioSource的Play播放音频文件,,直接使用已经预加载的AB资源 /// </summary> /// <param name="volumeScale">音量缩放比</param> public static void PlayBg(string audioABName, float volumeScale = 1.0f) { KSound.PlayBg(KAssetBundle.GetObject <AudioClip>(audioABName), volumeScale); }