From aa1752953c9b3c594c07743ef94bd4ffef3f7700 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Thu, 8 Feb 2024 01:05:21 -0500 Subject: [PATCH] also grab from cache in this method --- Assets/Scripts/Util/SoundByte.cs | 43 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Util/SoundByte.cs b/Assets/Scripts/Util/SoundByte.cs index b38d4ce74..289526274 100644 --- a/Assets/Scripts/Util/SoundByte.cs +++ b/Assets/Scripts/Util/SoundByte.cs @@ -218,30 +218,41 @@ namespace HeavenStudio.Util public static double GetClipLength(string name, float pitch = 1f, string game = null) { AudioClip clip = null; - if (audioClips.ContainsKey(name)) + string soundName = name.Split('/')[^1]; + if (game != null) { - clip = audioClips[name]; - } - else if (game != null) - { - string soundName = name.Split('/')[2]; - var inf = GameManager.instance.GetGameInfo(game); - //first try the game's common assetbundle - // Debug.Log("Jukebox loading sound " + soundName + " from common"); - clip = inf.GetCommonAssetBundle()?.LoadAsset(soundName); - //then the localized one - if (clip == null) + string cachedName = $"games/{game}/{soundName}"; + if (audioClips.ContainsKey(cachedName)) { - // Debug.Log("Jukebox loading sound " + soundName + " from locale"); - clip = inf.GetLocalizedAssetBundle()?.LoadAsset(soundName); + clip = audioClips[cachedName]; + } + else + { + var inf = GameManager.instance.GetGameInfo(game); + //first try the game's common assetbundle + // Debug.Log("Jukebox loading sound " + soundName + " from common"); + clip = inf.GetCommonAssetBundle()?.LoadAsset(soundName); + //then the localized one + if (clip == null) + { + // Debug.Log("Jukebox loading sound " + soundName + " from locale"); + clip = inf.GetLocalizedAssetBundle()?.LoadAsset(soundName); + } } } //can't load from assetbundle, load from resources if (clip == null) { - // Debug.Log("Jukebox loading sound " + name + " from resources"); - clip = Resources.Load($"Sfx/{name}"); + if (audioClips.ContainsKey(name)) + { + clip = audioClips[name]; + } + else + { + // Debug.Log("Jukebox loading sound " + name + " from resources"); + clip = Resources.Load($"Sfx/{name}"); + } } if (clip == null)