// Called when changes are made to the scene and when a new scene is created. public static void CheckWwiseGlobalExistance() { WwiseSettings settings = WwiseSettings.LoadSettings(); string activeSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; if (String.IsNullOrEmpty(s_CurrentScene) || !s_CurrentScene.Equals(activeSceneName)) { // Look for a game object which has the initializer component AkInitializer[] AkInitializers = UnityEngine.Object.FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[]; if (AkInitializers.Length == 0) { if (settings.CreateWwiseGlobal == true) { //No Wwise object in this scene, create one so that the sound engine is initialized and terminated properly even if the scenes are loaded //in the wrong order. GameObject objWwise = new GameObject("WwiseGlobal"); //Attach initializer and terminator components AkInitializer init = objWwise.AddComponent <AkInitializer>(); AkWwiseProjectInfo.GetData().CopyInitSettings(init); } } else { if (settings.CreateWwiseGlobal == false && AkInitializers[0].gameObject.name == "WwiseGlobal") { GameObject.DestroyImmediate(AkInitializers[0].gameObject); } //All scenes will share the same initializer. So expose the init settings consistently across scenes. AkWwiseProjectInfo.GetData().CopyInitSettings(AkInitializers[0]); } if (Camera.main != null) { GameObject mainCameraGameObject = Camera.main.gameObject; AkAudioListener akListener = mainCameraGameObject.GetComponent <AkAudioListener>(); if (settings.CreateWwiseListener == true) { AudioListener listener = mainCameraGameObject.GetComponent <AudioListener>(); if (listener != null) { Component.DestroyImmediate(listener); } // Add the AkAudioListener script if (akListener == null) { akListener = mainCameraGameObject.AddComponent <AkAudioListener>(); AkGameObj akGameObj = akListener.GetComponent <AkGameObj>(); akGameObj.isEnvironmentAware = false; Debug.LogWarning("Automatically added AkAudioListener to Main Camera. Go to \"Edit > Wwise Settings...\" to disable this functionality."); } } } s_CurrentScene = activeSceneName; } }
public void Reset(AkAudioListener listener, AkSpatialAudioListener spatialListener) { DefaultListener = listener; SpatialListener = spatialListener; DefaultListenerObj = listener.GetComponent <AkGameObj>(); }