I just noticed that I missed the message you replied to.
There is a caveat about my question: this is a project under the WebGL platform.
Therefore, the loading of Bank at this point causes the entire Bank file to exist in memory, rather than being loaded on demand.
Ultimately our solution was to extend the custom method in the RuntimeManager class and trigger the callback method when loading the Bank is complete.
private IEnumerator LoadBankFromURL(Action loadedCallback, string bankURL, string bankName, bool loadSamples)
{
byte[] loadWebResult;
FMOD.RESULT loadResult;
UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Get(bankURL);
yield return www.SendWebRequest();
loadWebResult = www.downloadHandler.data;
LoadedBank loadedBank = new LoadedBank();
loadResult = Instance.studioSystem.loadBankMemory(loadWebResult, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out loadedBank.Bank);
if (loadResult != FMOD.RESULT.OK)
{
RuntimeUtils.DebugLogWarningFormat("[FMOD] loadFromWeb. Path = {0}, result = {1}.", bankURL, loadResult);
}
RegisterLoadedBank(loadedBank, bankURL, bankName, loadSamples, loadResult);
Instance.loadingBanksRef--;
RuntimeUtils.DebugLogFormat("[FMOD] Finished loading {0}", bankURL);
loadedCallback();
}
/// <summary>
/// 扩展的方法。通过给定URL来加载bank文件。基于官方的LoadBank方法修改。
/// </summary>
/// <param name="loadedCallback">加载完成后的回调</param>
/// <param name="bankURL">文件的URL。</param>
/// <param name="bankName">bank文件的名称,应保证所有加载的bank文件的名称相互唯一。</param>
/// <param name="loadSamples">是否加载SampleData。</param>
public static void LoadBankByURL(Action loadedCallback, string bankURL, string bankName, bool loadSamples = false)
{
// bankId实际上就是用了bankName
string bankId = bankName;
// 如果已经加载过,则添加引用计数
if (Instance.loadedBanks.ContainsKey(bankId))
{
ReferenceLoadedBank(bankId, loadSamples);
// 也代表加载成功,直接调用回调
loadedCallback();
}
else
{
// 添加计数,该字段是本类用于判断是否已经加载完成所有的bank文件的参考
Instance.loadingBanksRef++;
Instance.StartCoroutine(Instance.LoadBankFromURL(loadedCallback, bankURL, bankName, loadSamples));
}
}
private IEnumerator LoadBankFromFilePath(Action loadedCallback, string bankPath, string bankId, bool loadSamples = false)
{
LoadedBank loadedBank = new LoadedBank();
FMOD.RESULT loadResult = Instance.studioSystem.loadBankFile(bankPath, FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out loadedBank.Bank);
Instance.RegisterLoadedBank(loadedBank, bankPath, bankId, loadSamples, loadResult);
yield return 0;
Instance.loadingBanksRef--;
RuntimeUtils.DebugLogFormat("[FMOD] Finished loading {0}", bankPath);
loadedCallback();
}
/// <summary>
/// 扩展的方法。通过给定路径来加载bank文件。基于官方的LoadBank方法修改。
/// </summary>
/// <param name="loadedCallback">加载完成后的回调</param>
/// <param name="bankPath">文件所在路径。</param>
/// <param name="bankName">bank文件的名称,应保证所有加载的bank文件的名称相互唯一。</param>
/// <param name="loadSamples">是否加载SampleData。</param>
public static void LoadBankByFilePath(Action loadedCallback, string bankPath, string bankName, bool loadSamples = false)
{
// bankId实际上就是用了bankName
string bankId = bankName;
// 如果已经加载过,则添加引用计数
if (Instance.loadedBanks.ContainsKey(bankId))
{
ReferenceLoadedBank(bankId, loadSamples);
// 也代表加载成功,直接调用回调
loadedCallback();
}
else
{
// 添加计数,该字段是本类用于判断是否已经加载完成所有的bank文件的参考
Instance.loadingBanksRef++;
Instance.StartCoroutine(Instance.LoadBankFromFilePath(loadedCallback, bankPath, bankId, loadSamples));
}
}