2025-06-03 02:42:28 -04:00
#if ! ( UNITY_DASHBOARD_WIDGET | | UNITY_WEBPLAYER | | UNITY_WII | | UNITY_WIIU | | UNITY_NACL | | UNITY_FLASH | | UNITY_BLACKBERRY ) // Disable under unsupported platforms.
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
Technology released in source code form as part of the game integration package .
The content of this file may not be used without valid licenses to the
AUDIOKINETIC Wwise Technology .
Note that the use of the game engine is subject to the Unity ( R ) Terms of
Service at https : //unity3d.com/legal/terms-of-service
License Usage
Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
this file in accordance with the end user license agreement provided with the
software or , alternatively , in accordance with the terms contained
in a written agreement between you and Audiokinetic Inc .
2026-03-14 03:13:10 -04:00
Copyright ( c ) 2025 Audiokinetic Inc .
2025-06-03 02:42:28 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
[UnityEngine.AddComponentMenu("Wwise/AkBank")]
[UnityEngine.ExecuteInEditMode]
[UnityEngine.DefaultExecutionOrder(-75)]
/// @brief Loads and unloads a SoundBank at a specified moment. Vorbis sounds can be decompressed at a specified moment using the decode compressed data option. In that case, the SoundBank will be prepared.
public class AkBank : AkTriggerHandler
#if UNITY_EDITOR
, AK . Wwise . IMigratable
#endif
{
public AK . Wwise . Bank data = new AK . Wwise . Bank ( ) ;
2026-03-14 03:13:10 -04:00
/// DEPRECATED Decode this SoundBank upon load
2025-06-03 02:42:28 -04:00
public bool decodeBank = false ;
2026-03-14 03:13:10 -04:00
public bool overrideLoadSetting = false ;
2025-06-03 02:42:28 -04:00
/// Check this to load the SoundBank in the background. Be careful, if Events are triggered and the SoundBank hasn't finished loading, you'll have "Event not found" errors.
public bool loadAsynchronous = false ;
2026-03-14 03:13:10 -04:00
/// DEPRECATED Save the decoded SoundBank to disk for faster loads in the future
2025-06-03 02:42:28 -04:00
public bool saveDecodedBank = false ;
/// Reserved.
public System . Collections . Generic . List < int > unloadTriggerList =
new System . Collections . Generic . List < int > { DESTROY_TRIGGER_ID } ;
protected override void Awake ( )
{
#if UNITY_EDITOR
2026-03-14 03:13:10 -04:00
AkUnitySoundEngineInitialization . Instance . initializationDelegate + = HandleEvent ;
2025-06-03 02:42:28 -04:00
if ( UnityEditor . BuildPipeline . isBuildingPlayer | | AkUtilities . IsMigrating )
2026-03-14 03:13:10 -04:00
{
2025-06-03 02:42:28 -04:00
return ;
2026-03-14 03:13:10 -04:00
}
2025-06-03 02:42:28 -04:00
var reference = AkWwiseTypes . DragAndDropObjectReference ;
if ( reference )
{
UnityEngine . GUIUtility . hotControl = 0 ;
data . ObjectReference = reference ;
2026-03-14 03:13:10 -04:00
AkWwiseTypes . DragAndDropObjectReference = null ;
2025-06-03 02:42:28 -04:00
}
#endif
base . Awake ( ) ;
RegisterTriggers ( unloadTriggerList , UnloadBank ) ;
}
2026-03-14 03:13:10 -04:00
#if UNITY_EDITOR
public override void OnEnable ( )
{
if ( UnityEditor . BuildPipeline . isBuildingPlayer )
{
return ;
}
base . OnEnable ( ) ;
}
#endif
2025-06-03 02:42:28 -04:00
protected override void Start ( )
{
#if UNITY_EDITOR
if ( UnityEditor . BuildPipeline . isBuildingPlayer | | AkUtilities . IsMigrating )
2026-03-14 03:13:10 -04:00
{
2025-06-03 02:42:28 -04:00
return ;
2026-03-14 03:13:10 -04:00
}
if ( ! UnityEditor . EditorApplication . isPlaying )
{
HandleEvent ( ) ;
}
2025-06-03 02:42:28 -04:00
#endif
base . Start ( ) ;
//Call the UnloadBank function if registered to the Start Trigger
if ( unloadTriggerList . Contains ( START_TRIGGER_ID ) )
2026-03-14 03:13:10 -04:00
{
2025-06-03 02:42:28 -04:00
UnloadBank ( null ) ;
2026-03-14 03:13:10 -04:00
}
2025-06-03 02:42:28 -04:00
}
/// Loads the SoundBank
public override void HandleEvent ( UnityEngine . GameObject in_gameObject )
{
2026-03-14 03:13:10 -04:00
bool asyncResult = loadAsynchronous ;
if ( ! overrideLoadSetting )
{
asyncResult = AkWwiseInitializationSettings . ActivePlatformSettings . LoadBanksAsynchronously ;
}
if ( asyncResult )
{
2025-06-03 02:42:28 -04:00
data . LoadAsync ( ) ;
2026-03-14 03:13:10 -04:00
}
else
{
data . Load ( decodeBank , saveDecodedBank ) ;
}
}
private void HandleEvent ( )
{
HandleEvent ( gameObject ) ;
2025-06-03 02:42:28 -04:00
}
/// Unloads a SoundBank
public void UnloadBank ( UnityEngine . GameObject in_gameObject )
{
data . Unload ( ) ;
}
protected override void OnDestroy ( )
{
#if UNITY_EDITOR
2026-03-14 03:13:10 -04:00
AkUnitySoundEngineInitialization . Instance . initializationDelegate - = HandleEvent ;
2025-06-03 02:42:28 -04:00
if ( UnityEditor . BuildPipeline . isBuildingPlayer | | AkUtilities . IsMigrating )
2026-03-14 03:13:10 -04:00
{
2025-06-03 02:42:28 -04:00
return ;
2026-03-14 03:13:10 -04:00
}
2025-06-03 02:42:28 -04:00
#endif
base . OnDestroy ( ) ;
UnregisterTriggers ( unloadTriggerList , UnloadBank ) ;
}
#region Obsolete
2026-03-14 03:13:10 -04:00
[System.Obsolete(AkUnitySoundEngine.Deprecation_2018_1_6)]
2025-06-03 02:42:28 -04:00
public string bankName { get { return data = = null ? string . Empty : data . Name ; } }
2026-03-14 03:13:10 -04:00
[System.Obsolete(AkUnitySoundEngine.Deprecation_2018_1_6)]
2025-06-03 02:42:28 -04:00
public byte [ ] valueGuid
{
get
{
if ( data = = null )
return null ;
var objRef = data . ObjectReference ;
return ! objRef ? null : objRef . Guid . ToByteArray ( ) ;
}
}
#endregion
#region WwiseMigration
#pragma warning disable 0414 // private field assigned but not used.
[UnityEngine.HideInInspector]
[UnityEngine.SerializeField]
[UnityEngine.Serialization.FormerlySerializedAs("bankName")]
private string bankNameInternal ;
[UnityEngine.HideInInspector]
[UnityEngine.SerializeField]
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
private byte [ ] valueGuidInternal ;
#pragma warning restore 0414 // private field assigned but not used.
#if UNITY_EDITOR
bool AK . Wwise . IMigratable . Migrate ( UnityEditor . SerializedObject obj )
{
if ( ! AkUtilities . IsMigrationRequired ( AkUtilities . MigrationStep . WwiseTypes_v2018_1_6 ) )
return false ;
return AK . Wwise . TypeMigration . ProcessSingleGuidType ( obj . FindProperty ( "data.WwiseObjectReference" ) , WwiseObjectType . Soundbank ,
obj . FindProperty ( "valueGuidInternal" ) , obj . FindProperty ( "bankNameInternal" ) ) ;
}
#endif
#endregion
}
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.