@@ -83,7 +83,7 @@ public class API_3DTI_Spatializer : MonoBehaviour
8383
8484 // Set this to the 3DTI mixer containing the SpatializerCore3DTI effect.
8585 public AudioMixer spatializereCoreMixer ;
86-
86+ private bool isInitialized = false ;
8787
8888
8989
@@ -242,30 +242,40 @@ private string[] binaryResourcePaths(BinaryResourceRole role)
242242 private static extern bool Reset3DTISpatializerIfNeeded ( int sampleRate , int dspBufferSize ) ;
243243
244244
245+
245246 private void Awake ( )
246247 {
247- // Check a missized array hasn't been saved from a previous version
248- if ( spatializerParameters . Length != NumParameters )
248+ initialize ( ) ;
249+ }
250+
251+ // This function is called automatically when the scene starts. It is made public so the Inspector GUI can call it.
252+ public void initialize ( )
253+ {
254+ if ( ! isInitialized )
249255 {
250- int originalLength = spatializerParameters . Length ;
251- Array . Resize ( ref spatializerParameters , NumParameters ) ;
252- if ( spatializerParameters . Length > originalLength )
256+ // Check a missized array hasn't been saved from a previous version
257+ if ( spatializerParameters . Length != NumParameters )
253258 {
254- for ( int i = originalLength ; i < spatializerParameters . Length ; i ++ )
259+ int originalLength = spatializerParameters . Length ;
260+ Array . Resize ( ref spatializerParameters , NumParameters ) ;
261+ if ( spatializerParameters . Length > originalLength )
255262 {
256- spatializerParameters [ i ] = ( ( SpatializerParameter ) i ) . GetAttribute < SpatializerParameterAttribute > ( ) . defaultValue ;
263+ for ( int i = originalLength ; i < spatializerParameters . Length ; i ++ )
264+ {
265+ spatializerParameters [ i ] = ( ( SpatializerParameter ) i ) . GetAttribute < SpatializerParameterAttribute > ( ) . defaultValue ;
266+ }
257267 }
258268 }
259- }
260269
261- AudioSettings . GetDSPBufferSize ( out int dspBufferSize , out _ ) ;
262- Reset3DTISpatializerIfNeeded ( AudioSettings . outputSampleRate , dspBufferSize ) ;
263- sendAllBinaryResourcePathsToPlugin ( ) ;
264- for ( int i = 0 ; i < NumParameters ; i ++ )
265- {
266- if ( ! Set3DTISpatializerFloat ( i , spatializerParameters [ i ] ) )
270+ AudioSettings . GetDSPBufferSize ( out int dspBufferSize , out _ ) ;
271+ Reset3DTISpatializerIfNeeded ( AudioSettings . outputSampleRate , dspBufferSize ) ;
272+ sendAllBinaryResourcePathsToPlugin ( ) ;
273+ for ( int i = 0 ; i < NumParameters ; i ++ )
267274 {
268- Debug . LogError ( $ "Failed to set 3DTI parameter { i } .", this ) ;
275+ if ( ! Set3DTISpatializerFloat ( i , spatializerParameters [ i ] ) )
276+ {
277+ Debug . LogError ( $ "Failed to set 3DTI parameter { i } .", this ) ;
278+ }
269279 }
270280 }
271281 }
0 commit comments