Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 82 additions & 25 deletions Runtime/AkAddressableBankManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,28 @@ private static WwiseAddressableSoundBank FindInitBank()
var foundBank = UnityEngine.MonoBehaviour.FindObjectsOfType<InitBankHolder>();
if (foundBank.Count() == 0)
{
UnityEngine.Debug.LogError("Wwise Addressables : There is no InitBankHolder in the scene, please add one for Wwise to function properly.");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError("Wwise Addressables : There is no InitBankHolder in the scene, please add one for Wwise to function properly.");
}
return null;
}

if (foundBank.Count() > 1)
{
UnityEngine.Debug.LogError("Wwise Addressables : There is more than one InitBankHolder in the scene, which is not recommended.");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError("Wwise Addressables : There is more than one InitBankHolder in the scene, which is not recommended.");
}
}

WwiseAddressableSoundBank InitBank = foundBank[0].GetAddressableInitBank();
if (InitBank == null)
{
UnityEngine.Debug.LogError("Wwise Addressables : The InitBankHolder could not get a valid reference to the Init bank.");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError("Wwise Addressables : The InitBankHolder could not get a valid reference to the Init bank.");
}
return null;

}
Expand Down Expand Up @@ -239,7 +248,10 @@ public async Task LoadBank(WwiseAddressableSoundBank bank, bool decodeBank = fal
{
if (!InitBankLoaded && bank.name != "Init")
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: {bank.name} bank will be loaded after the init bank is loaded");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: {bank.name} bank will be loaded after the init bank is loaded");
}
bank.loadState = BankLoadState.WaitingForInitBankToLoad;
return;
}
Expand All @@ -261,15 +273,21 @@ public async Task LoadBank(WwiseAddressableSoundBank bank, bool decodeBank = fal

if (bank.Data == null)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager : {bank.name} could not be loaded - Bank reference not set");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager : {bank.name} could not be loaded - Bank reference not set");
}
m_AddressableBanks.TryRemove((bank.name, bank.isAutoBank), out _);
return;
}

AssetReferenceWwiseBankData bankData;
if (bank.Data.ContainsKey("SFX"))
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Loading {bank.name} bank");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Loading {bank.name} bank");
}
bankData = bank.Data["SFX"];
bank.currentLanguage = "SFX";
}
Expand All @@ -284,11 +302,17 @@ public async Task LoadBank(WwiseAddressableSoundBank bank, bool decodeBank = fal
{
bankData = bank.Data[currentLanguage];
bank.currentLanguage = currentLanguage;
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Loading {bank.name} - {currentLanguage}");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Loading {bank.name} - {currentLanguage}");
}
}
else
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: {bank.name} could not be loaded in {currentLanguage} language ");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: {bank.name} could not be loaded in {currentLanguage} language ");
}
m_AddressableBanks.TryRemove((bank.name, bank.isAutoBank), out _);
bank.loadState = BankLoadState.Unloaded;
return;
Expand Down Expand Up @@ -366,13 +390,16 @@ public async Task LoadBankAsync(WwiseAddressableSoundBank bank, AssetReferenceWw
{
bank.soundbankId = INVALID_SOUND_BANK_ID;
bank.loadState = BankLoadState.LoadFailed;
if ((int)result == 100) // 100 == AK_InvalidBankType (using the raw int value until this package only supports Wwise 22.1 and up)
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogWarning($"Wwise Addressable Bank Manager : Bank {bank.name} is an auto-generated bank. The Unity Wwise Addressables package only supports user-defined banks. Avoid using auto-generated banks.");
}
else
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Sound Engine failed to load {bank.name} SoundBank");
if ((int)result == 100) // 100 == AK_InvalidBankType (using the raw int value until this package only supports Wwise 22.1 and up)
{
UnityEngine.Debug.LogWarning($"Wwise Addressable Bank Manager : Bank {bank.name} is an auto-generated bank. The Unity Wwise Addressables package only supports user-defined banks. Avoid using auto-generated banks.");
}
else
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Sound Engine failed to load {bank.name} SoundBank");
}
}
}
bank.GCHandle.Free();
Expand All @@ -386,7 +413,10 @@ public async Task LoadBankAsync(WwiseAddressableSoundBank bank, AssetReferenceWw
{
if (streamedAsset == null)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: Streaming media asset referenced in {bank.name} SoundBank is null");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: Streaming media asset referenced in {bank.name} SoundBank is null");
}
continue;
}
assetKeys.Add(streamedAsset);
Expand Down Expand Up @@ -421,7 +451,10 @@ public async Task LoadBankAsync(WwiseAddressableSoundBank bank, AssetReferenceWw
}
else
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager : Failed to load {bank.name} SoundBank");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager : Failed to load {bank.name} SoundBank");
}
bank.loadState = BankLoadState.LoadFailed;
}

Expand All @@ -446,7 +479,10 @@ public void UnloadBank(WwiseAddressableSoundBank bank, bool ignoreRefCount = fal

if (bank.loadState == BankLoadState.Loading || bank.loadState == BankLoadState.WaitingForPrepareEvent)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: {bank.name} will be unloaded after it is done loading");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: {bank.name} will be unloaded after it is done loading");
}
m_banksToUnload.TryAdd(bank.name, bank.name);
return;
}
Expand All @@ -458,13 +494,19 @@ public void UnloadBank(WwiseAddressableSoundBank bank, bool ignoreRefCount = fal
#else
AkSoundEngine.PrepareEvent(AkPreparationType.Preparation_Unload, new string[] { bank.name }, 1);
#endif
UnityEngine.Debug.Log($"Wwise Addressables Bank Manager: {bank.name} is already unloaded.");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressables Bank Manager: {bank.name} is already unloaded.");
}
return;
}

if (bank.loadState == BankLoadState.Loaded || bank.loadState == BankLoadState.TimedOut)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Unloading {bank.name} sound bank - Bank ID : {bank.soundbankId}");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Unloading {bank.name} sound bank - Bank ID : {bank.soundbankId}");
}
if (bank.bankType != 0)
{
#if WWISE_2024_OR_LATER
Expand Down Expand Up @@ -503,7 +545,10 @@ public void UnloadBank(WwiseAddressableSoundBank bank, bool ignoreRefCount = fal
#endif
if (InitBank && bank.name != InitBank.name)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: Unloaded {bank.name}, but it was not in the list of loaded banks");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogError($"Wwise Addressable Bank Manager: Unloaded {bank.name}, but it was not in the list of loaded banks");
}
}
}
}
Expand All @@ -519,7 +564,11 @@ public bool LoadedBankContainsEvent(string eventName, uint eventId, object event
}
}

UnityEngine.Debug.LogWarning($"Wwise Addressables : {eventName} will be delayed, because its soundbank has not been loaded.");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.LogWarning($"Wwise Addressables : {eventName} will be delayed, because its soundbank has not been loaded.");
}

m_eventsToFireOnBankLoad.TryAdd(eventId, new EventContainer { eventName = eventName, eventObject = eventObject, methodName = methodName, methodArgTypes = methodArgTypes, methodArgs = methodArgs });
return false;
}
Expand All @@ -540,7 +589,10 @@ private Type EventType

public void OnAutoBankLoaded(WwiseAddressableSoundBank bank)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Loaded {bank.name} AutoBank - Bank ID : {bank.soundbankId}");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Loaded {bank.name} AutoBank - Bank ID : {bank.soundbankId}");
}
bank.loadState = BankLoadState.Loaded;
FireEventOnBankLoad(bank, false);
}
Expand All @@ -555,8 +607,10 @@ private void FireEventOnBankLoad(WwiseAddressableSoundBank bank, bool skipAutoBa
{
if (skipAutoBank && bank.isAutoBank)
continue;

UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Triggering delayed event {e.Value.eventName}");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager: Triggering delayed event {e.Value.eventName}");
}
MethodInfo handleEvent = EventType.GetMethod(e.Value.methodName, e.Value.methodArgTypes);
handleEvent.Invoke(e.Value.eventObject, e.Value.methodArgs);
eventsToRemove.Add(e.Key);
Expand All @@ -573,7 +627,10 @@ private void OnBankLoaded(WwiseAddressableSoundBank bank)
{
if (bank.loadState == BankLoadState.Loaded)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Loaded {bank.name} bank - Bank ID : {bank.soundbankId}");
if (AkWwiseInitializationSettings.Instance.UserSettings.m_EngineLogging)
{
UnityEngine.Debug.Log($"Wwise Addressable Bank Manager : Loaded {bank.name} bank - Bank ID : {bank.soundbankId}");
}
if (InitBankLoaded && bank.name == InitBank.name)
{
foreach (var b in m_AddressableBanks.Values)
Expand Down