@@ -165,9 +165,20 @@ internal static void AddBankReferenceToAddressableBankAsset(ConcurrentDictionary
165165 var results = AssetDatabase . FindAssets ( string . Format ( "{0} t:{1}" , name , nameof ( WwiseAddressableSoundBank ) ) ) ;
166166 if ( results . Length > 0 )
167167 {
168- string addressableBankGuid = results . First ( ) ;
169- string addressableBankPath = AssetDatabase . GUIDToAssetPath ( addressableBankGuid ) ;
170- addressableBankAsset = AssetDatabase . LoadAssetAtPath < WwiseAddressableSoundBank > ( addressableBankPath ) ;
168+ foreach ( var addressableBankGuid in results )
169+ {
170+ string addressableBankPath = AssetDatabase . GUIDToAssetPath ( addressableBankGuid ) ;
171+ var assetName = Path . GetFileNameWithoutExtension ( addressableBankPath ) ;
172+ if ( assetName == name )
173+ {
174+ addressableBankAsset = AssetDatabase . LoadAssetAtPath < WwiseAddressableSoundBank > ( addressableBankPath ) ;
175+ }
176+ }
177+ }
178+
179+ if ( name == "Init" )
180+ {
181+ AkAddressablesEditorUtilities . EnsureInitBankAssetCreated ( ) ;
171182 }
172183
173184 string addressableBankAssetDirectory = AkAssetUtilities . GetSoundbanksPath ( ) ;
@@ -197,42 +208,13 @@ internal static void AddBankReferenceToAddressableBankAsset(ConcurrentDictionary
197208 }
198209 addressableBankAsset = ScriptableObject . CreateInstance < WwiseAddressableSoundBank > ( ) ;
199210 itemsToCreate . Add ( new CreateAssetEntry { Asset = addressableBankAsset , Path = addressableBankAssetPath , Name = name } ) ;
200-
201211 }
202212 else
203213 {
204214 UpdateAddressableBankReference ( addressableBankAsset , name ) ;
205215 }
206216
207217 addressableAssetCache . AddOrUpdate ( name , addressableBankAsset , ( key , oldValue ) => addressableBankAsset ) ;
208-
209- if ( name == "Init" )
210- {
211- var wwiseGlobablGameObject = GameObject . Find ( "WwiseGlobal" ) ;
212- InitBankHolder bankHolder ;
213- if ( wwiseGlobablGameObject != null )
214- {
215- bankHolder = wwiseGlobablGameObject . GetComponent < InitBankHolder > ( ) ;
216- if ( bankHolder == null )
217- {
218- wwiseGlobablGameObject . AddComponent < InitBankHolder > ( ) ;
219- bankHolder = wwiseGlobablGameObject . GetComponent < InitBankHolder > ( ) ;
220- }
221- bankHolder . InitBank = addressableBankAsset ;
222- }
223- else
224- {
225- bankHolder = UnityEngine . Object . FindObjectOfType < InitBankHolder > ( ) ;
226- if ( bankHolder != null )
227- {
228- bankHolder . InitBank = addressableBankAsset ;
229- }
230- else
231- {
232- Debug . Log ( "Could not find or create the InitBankHolder, you will have to add one to the WwiseGlobal object in your scene and ensure it references the Init bank." ) ;
233- }
234- }
235- }
236218 }
237219
238220 if ( ! string . IsNullOrEmpty ( platform ) )
@@ -256,19 +238,26 @@ internal static void AddBankReferenceToAddressableBankAsset(ConcurrentDictionary
256238 {
257239 if ( itemsToCreate . Count > 0 )
258240 {
259- AssetDatabase . StartAssetEditing ( ) ;
260- foreach ( var entry in itemsToCreate )
241+ try
261242 {
262- AssetDatabase . CreateAsset ( entry . Asset , entry . Path ) ;
263- UpdateAddressableBankReference ( entry . Asset , entry . Name ) ;
243+ AssetDatabase . StartAssetEditing ( ) ;
244+ foreach ( var entry in itemsToCreate )
245+ {
246+ AssetDatabase . CreateAsset ( entry . Asset , entry . Path ) ;
247+ UpdateAddressableBankReference ( entry . Asset , entry . Name ) ;
248+ }
249+ }
250+ finally
251+ {
252+ AssetDatabase . StopAssetEditing ( ) ;
264253 }
265- AssetDatabase . StopAssetEditing ( ) ;
266254 }
267255
268256 AssetDatabase . SaveAssets ( ) ;
269257 AssetDatabase . Refresh ( ) ;
270258 }
271259 }
260+
272261 internal static void UpdateAddressableBankReference ( WwiseAddressableSoundBank asset , string bankName )
273262 {
274263 bool bankScriptableObjectUpdated = false ;
@@ -278,15 +267,21 @@ internal static void UpdateAddressableBankReference(WwiseAddressableSoundBank as
278267 }
279268 if ( ! bankScriptableObjectUpdated )
280269 {
281- AkAddressablesEditorUtilities . FindAndSetBankReference ( asset , bankName ) ;
270+ if ( bankName == WwiseInitBankReference . InitBankName )
271+ {
272+ WwiseInitBankReference . FindInitBankReferenceAndSetAddressableBank ( asset , bankName ) ;
273+ }
274+ else
275+ {
276+ AkAddressablesEditorUtilities . FindAndSetBankReference ( asset , bankName ) ;
277+ }
282278 }
283279 }
284280
285281 internal static void AddStreamedAssetsToBanks ( HashSet < string > streamingAssetsAdded )
286282 {
287283 try
288284 {
289- var updatedBanks = new List < string > ( ) ;
290285 foreach ( var assetPath in streamingAssetsAdded )
291286 {
292287 string name = Path . GetFileNameWithoutExtension ( assetPath ) ;
@@ -297,35 +292,48 @@ internal static void AddStreamedAssetsToBanks(HashSet<string> streamingAssetsAdd
297292
298293 var soundbankInfos = AkAddressablesEditorUtilities . ParsePlatformSoundbanksXML ( platform , name ) ;
299294
300- var bankNames = soundbankInfos . eventToSoundBankMap [ name ] ;
301- foreach ( var bankName in bankNames )
295+ if ( soundbankInfos . eventToSoundBankMap . TryGetValue ( name , out var bankNames ) )
302296 {
303- string bankAssetDir = Path . GetDirectoryName ( assetPath ) ;
304- string addressableBankAssetDir = AkAssetUtilities . GetSoundbanksPath ( ) ;
305- string addressableBankAssetPath = System . IO . Path . Combine ( addressableBankAssetDir , bankName + ".asset" ) ;
306- var bankAsset = AssetDatabase . LoadAssetAtPath < WwiseAddressableSoundBank > ( addressableBankAssetPath ) ;
307-
308- if ( bankAsset == null )
309- {
310- continue ;
311- }
312-
313- if ( ! string . IsNullOrEmpty ( platform ) )
297+ foreach ( var bankName in bankNames )
314298 {
315- if ( ! soundbankInfos [ bankName ] . TryGetValue ( language , out AkAddressablesEditorUtilities . SoundBankInfo sbInfo ) )
299+ string bankAssetDir = Path . GetDirectoryName ( assetPath ) ;
300+ string addressableBankAssetDir = AkAssetUtilities . GetSoundbanksPath ( ) ;
301+ string addressableBankAssetPath =
302+ System . IO . Path . Combine ( addressableBankAssetDir , bankName + ".asset" ) ;
303+ var bankAsset =
304+ AssetDatabase . LoadAssetAtPath < WwiseAddressableSoundBank > ( addressableBankAssetPath ) ;
305+
306+ if ( bankAsset == null )
316307 {
317- if ( int . TryParse ( language , out int result ) )
318- UnityEngine . Debug . LogError ( "Wwise Unity Addressables: Sub-folders for generated files currently not supported. Please turn off the option in Wwise under Project Settings -> SoundBanks" ) ;
319- else
320- UnityEngine . Debug . LogError ( $ "Wwise Unity Addressables: Unable to process asset at path { assetPath } : Unrecognized language { language } ") ;
321308 continue ;
322309 }
323- List < string > MediaIds = sbInfo . streamedFileIds ;
324- bankAsset . UpdateLocalizationLanguages ( platform , soundbankInfos [ bankName ] . Keys . ToList ( ) ) ;
325- bankAsset . SetStreamingMedia ( platform , language , bankAssetDir , MediaIds ) ;
326- EditorUtility . SetDirty ( bankAsset ) ;
310+
311+ if ( ! string . IsNullOrEmpty ( platform ) )
312+ {
313+ if ( ! soundbankInfos [ bankName ] . TryGetValue ( language ,
314+ out AkAddressablesEditorUtilities . SoundBankInfo sbInfo ) )
315+ {
316+ if ( int . TryParse ( language , out int result ) )
317+ UnityEngine . Debug . LogError (
318+ "Wwise Unity Addressables: Sub-folders for generated files currently not supported. Please turn off the option in Wwise under Project Settings -> SoundBanks" ) ;
319+ else
320+ UnityEngine . Debug . LogError (
321+ $ "Wwise Unity Addressables: Unable to process asset at path { assetPath } : Unrecognized language { language } ") ;
322+ continue ;
323+ }
324+
325+ List < string > MediaIds = sbInfo . streamedFileIds ;
326+ bankAsset . UpdateLocalizationLanguages ( platform , soundbankInfos [ bankName ] . Keys . ToList ( ) ) ;
327+ bankAsset . SetStreamingMedia ( platform , language , bankAssetDir , MediaIds ) ;
328+ EditorUtility . SetDirty ( bankAsset ) ;
329+ }
327330 }
328331 }
332+ else
333+ {
334+ UnityEngine . Debug . LogWarning (
335+ $ "Wwise Unity Addressables: Can't find containing SoundBank(s) for event { name } ") ;
336+ }
329337 }
330338 }
331339 finally
0 commit comments