// Called when changes are made to the scene and when a new scene is created. public static void CheckWwiseGlobalExistance() { var settings = WwiseSettings.LoadSettings(); var activeSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; if (string.IsNullOrEmpty(s_CurrentScene) || !s_CurrentScene.Equals(activeSceneName)) { // Look for a game object which has the initializer component var AkInitializers = UnityEngine.Object.FindObjectsOfType <AkInitializer>(); if (AkInitializers.Length == 0) { if (settings.CreateWwiseGlobal) { //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. var objWwise = new UnityEngine.GameObject("WwiseGlobal"); //Attach initializer and terminator components UnityEditor.Undo.AddComponent <AkInitializer>(objWwise); } } else if (settings.CreateWwiseGlobal == false && AkInitializers[0].gameObject.name == "WwiseGlobal") { UnityEditor.Undo.DestroyObjectImmediate(AkInitializers[0].gameObject); } if (settings.CreateWwiseListener) { AkUtilities.RemoveUnityAudioListenerFromMainCamera(); AkUtilities.AddAkAudioListenerToMainCamera(true); } s_CurrentScene = activeSceneName; } }
// Perform all necessary steps to use the Wwise Unity integration. private static void Setup() { AkPluginActivator.DeactivateAllPlugins(); // 0. Make sure the soundbank directory exists var sbPath = AkUtilities.GetFullPath(UnityEngine.Application.streamingAssetsPath, Settings.SoundbankPath); if (!System.IO.Directory.Exists(sbPath)) { System.IO.Directory.CreateDirectory(sbPath); } // 1. Disable built-in audio if (!DisableBuiltInAudio()) { UnityEngine.Debug.LogWarning( "WwiseUnity: Could not disable built-in audio. Please disable built-in audio by going to Project->Project Settings->Audio, and check \"Disable Audio\"."); } // 2. Create a "WwiseGlobal" game object and set the AkSoundEngineInitializer and terminator scripts // 3. Set the SoundBank path property on AkSoundEngineInitializer CreateWwiseGlobalObject(); // 5. Disable the built-in audio listener, and add AkAudioListener component to camera if (WwiseSettings.LoadSettings().CreateWwiseListener) { AkUtilities.RemoveUnityAudioListenerFromMainCamera(); AkUtilities.AddAkAudioListenerToMainCamera(); } // 6. Enable "Run In Background" in PlayerSettings (PlayerSettings.runInbackground property) UnityEditor.PlayerSettings.runInBackground = true; AkPluginActivator.Update(); AkPluginActivator.ActivatePluginsForEditor(); // 9. Activate WwiseIDs file generation, and point Wwise to the Assets/Wwise folder // 10. Change the SoundBanks options so it adds Max Radius information in the Wwise project if (!SetSoundbankSettings()) { UnityEngine.Debug.LogWarning("WwiseUnity: Could not modify Wwise Project to generate the header file!"); } // 11. Activate XboxOne network sockets. AkXboxOneUtils.EnableXboxOneNetworkSockets(); }
private void OnGUI() { // Make sure everything is initialized // Use soundbank path, because Wwise project path can be empty. if (string.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath) && WwiseSetupWizard.Settings.WwiseProjectPath == null) { WwiseSetupWizard.Settings = WwiseSettings.LoadSettings(); } var initialProject = WwiseSetupWizard.Settings.WwiseProjectPath; if (VersionStyle == null) { InitGuiStyles(); } UnityEngine.GUILayout.Label(m_WwiseVersionString, VersionStyle); DrawSettingsPart(); // DrawSettingsPart modifies WwiseSetupWizard.Settings.WwiseProjectPath directly. var newProject = WwiseSetupWizard.Settings.WwiseProjectPath; if (initialProject != newProject) { ApplyNewProject = true; } using (new UnityEngine.GUILayout.VerticalScope()) { UnityEngine.GUILayout.FlexibleSpace(); using (new UnityEngine.GUILayout.HorizontalScope()) { UnityEngine.GUILayout.FlexibleSpace(); if (UnityEngine.GUILayout.Button("OK", UnityEngine.GUILayout.Width(60))) { if (string.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath)) { UnityEditor.EditorUtility.DisplayDialog("Error", "Please fill in the required settings", "Ok"); } if (m_oldCreateWwiseGlobal != WwiseSetupWizard.Settings.CreateWwiseGlobal) { // var AkInitializers = FindObjectsOfType<AkInitializer>(); // if (WwiseSetupWizard.Settings.CreateWwiseGlobal) // { // if (AkInitializers.Length == 0) // { // //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. // //var objWwise = new UnityEngine.GameObject("WwiseGlobal"); // // //UnityEditor.Undo.AddComponent<AkInitializer>(objWwise); // } // } // else if (AkInitializers.Length != 0 && AkInitializers[0].gameObject.name == "WwiseGlobal") // UnityEditor.Undo.DestroyObjectImmediate(AkInitializers[0].gameObject); } if (m_oldCreateWwiseListener != WwiseSetupWizard.Settings.CreateWwiseListener) { if (WwiseSetupWizard.Settings.CreateWwiseListener) { AkUtilities.RemoveUnityAudioListenerFromMainCamera(); AkUtilities.AddAkAudioListenerToMainCamera(); } } if (m_oldShowMissingRigidBodyWarning != WwiseSetupWizard.Settings.ShowMissingRigidBodyWarning) { UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); } WwiseSettings.SaveSettings(WwiseSetupWizard.Settings); CloseWindow(); // Pop the Picker window so the user can start working right away AkWwiseProjectInfo.GetData(); // Load data if (ApplyNewProject) { //Clear the data, the project path changed. AkWwiseProjectInfo.GetData().Reset(); ApplyNewProject = false; AkUtilities.IsWwiseProjectAvailable = true; } AkWwiseProjectInfo.Populate(); AkWwisePicker.PopulateTreeview(); AkWwisePicker.init(); } if (UnityEngine.GUILayout.Button("Cancel", UnityEngine.GUILayout.Width(60))) { WwiseSetupWizard.Settings = WwiseSettings.LoadSettings(true); CloseWindow(); } UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing); } UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing); } }
// Called when changes are made to the scene and when a new scene is created. public static void CheckWwiseGlobalExistance() { var settings = WwiseSettings.LoadSettings(); var activeSceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; if (string.IsNullOrEmpty(s_CurrentScene) || !s_CurrentScene.Equals(activeSceneName)) { //{ // // Look for a game object which has the initializer component // var akRoutes = UnityEngine.Object.FindObjectsOfType<WisePluginNotificationRoute>(); // if (akRoutes.Length == 0) // { // while (true) // { // var oldObj = UnityEngine.GameObject.Find("WwiseGlobal"); // if(oldObj == null) // break; // UnityEditor.Undo.DestroyObjectImmediate(oldObj); // } // var objWwise = new UnityEngine.GameObject("WwiseGlobal"); // var init = UnityEditor.Undo.AddComponent<AkInitializer>(objWwise); // //Attach initializer and terminator components // UnityEditor.Undo.AddComponent<WisePluginNotificationRoute>(objWwise); // AkWwiseProjectInfo.GetData().CopyInitSettings(init); // //if (false) // //{ // // //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. // // //var oldObj = UnityEngine.GameObject.Find("WwiseGlobal"); // // //while (true) // // //{ // // //} // // //if (oldObj) // // //{ // // // if (!oldObj.GetComponent<WisePluginNotificationRoute>() || !oldObj.GetComponent<AkInitializer>()) // // // { // // // UnityEngine.Object.Destroy(oldObj); // // // var objWwise = new UnityEngine.GameObject("WwiseGlobal"); // // // var init = UnityEditor.Undo.AddComponent<AkInitializer>(objWwise); // // // //Attach initializer and terminator components // // // UnityEditor.Undo.AddComponent<WisePluginNotificationRoute>(objWwise); // // // AkWwiseProjectInfo.GetData().CopyInitSettings(init); // // // } // // //} // //} // } // else // { // for(int i=1;i< akRoutes.Length;i++) // { // UnityEditor.Undo.DestroyObjectImmediate(akRoutes[i].gameObject); // } // //if (settings.CreateWwiseGlobal == false && AkInitializers[0].gameObject.name == "WwiseGlobal") // // UnityEditor.Undo.DestroyObjectImmediate(AkInitializers[0].gameObject); // //All scenes will share the same initializer. So expose the init settings consistently across scenes. // AkWwiseProjectInfo.GetData().CopyInitSettings(akRoutes[0].GetComponent<AkInitializer>()); // } if (settings.CreateWwiseListener) { AkUtilities.RemoveUnityAudioListenerFromMainCamera(); AkUtilities.AddAkAudioListenerToMainCamera(true); } s_CurrentScene = activeSceneName; } }