public void CreateMicsSettings() { musicSetting = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSetting); memSetting = new AkMemSettings(); memSetting.uMaxNumPools = instance.SettingData.maxPoolNum; deviceSetting = new AkDeviceSettings(); //带回默认设置 AkSoundEngine.GetDefaultDeviceSettings(deviceSetting); streamingSetting = new AkStreamMgrSettings(); // Size of memory pool for small objects of Stream Manager. streamingSetting.uMemorySize = instance.SettingData.streamingPoolSizeKB * 1024; }
public virtual void Dispose() { AkMusicSettings settings = this; lock (settings) { if (this.swigCPtr != IntPtr.Zero) { if (this.swigCMemOwn) { this.swigCMemOwn = false; AkSoundEnginePINVOKE.CSharp_delete_AkMusicSettings(this.swigCPtr); } this.swigCPtr = IntPtr.Zero; } GC.SuppressFinalize(this); } }
public void Initialize() { if (ms_Instance != null) { //Don't init twice //Check if there are 2 objects with this script. If yes, remove this component. if (ms_Instance != this) UnityEngine.Object.DestroyImmediate(this.gameObject); return; } Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); // Unity 5 only, UNity 4 doesn't provide a way to access the product name at runtime. #if UNITY_5 #if UNITY_EDITOR AkSoundEngine.SetGameName(Application.productName + " (Editor)"); #else AkSoundEngine.SetGameName(Application.productName); #endif #endif AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } ms_Instance = this; string basePathToSet = AkBasePathGetter.GetValidBasePath(); if (string.IsNullOrEmpty(basePathToSet)) { return; } result = AkSoundEngine.SetBasePath(basePathToSet); if (result != AKRESULT.AK_Success) { return; } AkSoundEngine.SetCurrentLanguage(language); result = AkCallbackManager.Init(); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; return; } AkBankManager.Reset (); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); #if UNITY_EDITOR //Redirect Wwise error messages into Unity console. AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole); #endif //Load the init bank right away. Errors will be logged automatically. uint BankID; result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } #if UNITY_EDITOR EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged; #endif }
public void Init(AkInitializer akInitializer) { if (akInitializer == null) { UnityEngine.Debug.LogError("WwiseUnity: AkInitializer must not be null. Sound engine will not be initialized."); return; } #if UNITY_EDITOR if (UnityEngine.Application.isPlaying && !IsTheSingleOwningInitializer(akInitializer)) { UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized."); return; } var arguments = System.Environment.GetCommandLineArgs(); if (System.Array.IndexOf(arguments, "-nographics") >= 0 && System.Array.IndexOf(arguments, "-wwiseEnableWithNoGraphics") < 0) { return; } var isInitialized = false; try { isInitialized = AkSoundEngine.IsInitialized(); IsSoundEngineLoaded = true; } catch (System.DllNotFoundException) { IsSoundEngineLoaded = false; UnityEngine.Debug.LogWarning("WwiseUnity: AkSoundEngine is not loaded."); return; } #else var isInitialized = AkSoundEngine.IsInitialized(); #endif engineLogging = akInitializer.engineLogging; AkLogger.Instance.Init(); AKRESULT result; uint BankID; if (isInitialized) { #if UNITY_EDITOR if (UnityEngine.Application.isPlaying || UnityEditor.BuildPipeline.isBuildingPlayer) { AkSoundEngine.ClearBanks(); AkBankManager.Reset(); result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result); } } result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); return; } OnEnableEditorListener(akInitializer.gameObject); UnityEditor.EditorApplication.update += LateUpdate; #else UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized."); #endif return; } #if UNITY_EDITOR if (UnityEditor.BuildPipeline.isBuildingPlayer) { return; } #endif UnityEngine.Debug.Log("WwiseUnity: Initialize sound engine ..."); var basePath = s_DefaultBasePath; language = akInitializer.language; //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. var memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; var deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); var streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)akInitializer.streamingPoolSize * 1024; var initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)akInitializer.defaultPoolSize * 1024; initSettings.uMonitorPoolSize = (uint)akInitializer.monitorPoolSize * 1024; initSettings.uMonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024; #if (!UNITY_ANDROID && !PLATFORM_LUMIN && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path. initSettings.szPluginDLLPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, "Plugins" + System.IO.Path.DirectorySeparatorChar); #elif PLATFORM_LUMIN && !UNITY_EDITOR initSettings.szPluginDLLPath = UnityEngine.Application.dataPath.Replace("Data", "bin") + System.IO.Path.DirectorySeparatorChar; #endif var platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)akInitializer.lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = akInitializer.memoryCutoffThreshold; var musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); var spatialAudioSettings = new AkSpatialAudioInitSettings(); spatialAudioSettings.uPoolSize = (uint)akInitializer.spatialAudioPoolSize * 1024; spatialAudioSettings.uMaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth; spatialAudioSettings.uDiffractionFlags = (uint)akInitializer.diffractionFlags; #if UNITY_EDITOR AkSoundEngine.SetGameName(UnityEngine.Application.productName + " (Editor)"); #else AkSoundEngine.SetGameName(UnityEngine.Application.productName); #endif result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, spatialAudioSettings, (uint)akInitializer.preparePoolSize * 1024); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); AkSoundEngine.Term(); return; //AkSoundEngine.Init should have logged more details. } var basePathToSet = AkBasePathGetter.GetSoundbankBasePath(); if (string.IsNullOrEmpty(basePathToSet)) { UnityEngine.Debug.LogError("WwiseUnity: Couldn't find soundbanks base path. Terminate sound engine."); AkSoundEngine.Term(); return; } result = AkSoundEngine.SetBasePath(basePathToSet); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed to set soundbanks base path. Terminate sound engine."); AkSoundEngine.Term(); return; } #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch var decodedBankFullPath = GetDecodedBankFullPath(); // AkSoundEngine.SetDecodedBankPath creates the folders for writing to (if they don't exist) AkSoundEngine.SetDecodedBankPath(decodedBankFullPath); #endif AkSoundEngine.SetCurrentLanguage(language); #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms. AkSoundEngine.AddBasePath(UnityEngine.Application.persistentDataPath + System.IO.Path.DirectorySeparatorChar); // Adding decoded bank path last to ensure that it is the first one used when writing decoded banks. AkSoundEngine.AddBasePath(decodedBankFullPath); #endif result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); return; } AkBankManager.Reset(); UnityEngine.Debug.Log("WwiseUnity: Sound engine initialized."); //Load the init bank right away. Errors will be logged automatically. result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { UnityEngine.Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result); } #if UNITY_EDITOR OnEnableEditorListener(akInitializer.gameObject); UnityEditor.EditorApplication.update += LateUpdate; #endif }
public void Init(AkInitializer akInitializer) { engineLogging = akInitializer.engineLogging; AkLogger.Instance.Init(); AKRESULT result; uint BankID; if (AkSoundEngine.IsInitialized()) { #if UNITY_EDITOR if (Application.isPlaying) { AkSoundEngine.ClearBanks(); AkBankManager.Reset(); result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } } result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); return; } EditorApplication.update += LateUpdate; #endif return; } #if UNITY_EDITOR if (BuildPipeline.isBuildingPlayer) { return; } #endif Debug.Log("WwiseUnity: Initialize sound engine ..."); basePath = akInitializer.basePath; language = akInitializer.language; //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)akInitializer.streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)akInitializer.defaultPoolSize * 1024; initSettings.uMonitorPoolSize = (uint)akInitializer.monitorPoolSize * 1024; initSettings.uMonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024; #if (!UNITY_ANDROID && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path. initSettings.szPluginDLLPath = Path.Combine(Application.dataPath, "Plugins" + Path.DirectorySeparatorChar); #endif AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)akInitializer.lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = akInitializer.memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); AkSpatialAudioInitSettings spatialAudioSettings = new AkSpatialAudioInitSettings(); spatialAudioSettings.uPoolSize = (uint)akInitializer.spatialAudioPoolSize * 1024; spatialAudioSettings.uMaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth; spatialAudioSettings.uDiffractionFlags = (uint)akInitializer.diffractionFlags; #if UNITY_EDITOR AkSoundEngine.SetGameName(Application.productName + " (Editor)"); #else AkSoundEngine.SetGameName(Application.productName); #endif result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, spatialAudioSettings, (uint)akInitializer.preparePoolSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); AkSoundEngine.Term(); return; //AkSoundEngine.Init should have logged more details. } string basePathToSet = AkBasePathGetter.GetSoundbankBasePath(); if (string.IsNullOrEmpty(basePathToSet)) { Debug.LogError("WwiseUnity: Couldn't find soundbanks base path. Terminate sound engine."); AkSoundEngine.Term(); return; } result = AkSoundEngine.SetBasePath(basePathToSet); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to set soundbanks base path. Terminate sound engine."); AkSoundEngine.Term(); return; } #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch string decodedBankFullPath = GetDecodedBankFullPath(); // AkSoundEngine.SetDecodedBankPath creates the folders for writing to (if they don't exist) AkSoundEngine.SetDecodedBankPath(decodedBankFullPath); #endif AkSoundEngine.SetCurrentLanguage(language); #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms. AkSoundEngine.AddBasePath(Application.persistentDataPath + Path.DirectorySeparatorChar); // Adding decoded bank path last to ensure that it is the first one used when writing decoded banks. AkSoundEngine.AddBasePath(decodedBankFullPath); #endif result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); return; } AkBankManager.Reset(); Debug.Log("WwiseUnity: Sound engine initialized."); //Load the init bank right away. Errors will be logged automatically. result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } #if UNITY_EDITOR #if UNITY_2017_2_OR_NEWER EditorApplication.pauseStateChanged += OnPauseStateChanged; #else EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged; #endif EditorApplication.update += LateUpdate; #endif }
void Awake() { if (ms_Instance != null) { //Don't init twice //Check if there are 2 objects with this script. If yes, remove this component. if (ms_Instance != this) { UnityEngine.Object.DestroyImmediate(this.gameObject); } return; } Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } ms_Instance = this; AkBankPathUtil.UsePlatformSpecificPath(); string platformBasePath = AkBankPathUtil.GetPlatformBasePath(); // Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder. // Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test // our SoundBank folder for Android. #if !UNITY_ANDROID && !UNITY_METRO && !UNITY_PSP2 if (!AkBankPathUtil.Exists(platformBasePath)) { string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath); Debug.LogError(errorMsg); ms_Instance = null; return; } #endif // #if !UNITY_ANDROID AkSoundEngine.SetBasePath(platformBasePath); AkSoundEngine.SetCurrentLanguage(language); result = AkCallbackManager.Init(); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; return; } AkBankManager.Reset(); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); #if UNITY_EDITOR //Redirect Wwise error messages into Unity console. AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole); #endif //Load the init bank right away. Errors will be logged automatically. uint BankID; #if UNITY_ANDROID && !UNITY_METRO && AK_LOAD_BANK_IN_MEMORY result = AkInMemBankLoader.LoadNonLocalizedBank("Init.bnk"); #else result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); #endif // #if UNITY_ANDROID && !UNITY_METRO && AK_ANDROID_BANK_IN_OBB if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } }
internal static IntPtr getCPtr(AkMusicSettings obj) { return((obj != null) ? obj.swigCPtr : IntPtr.Zero); }
public void Initialize() { if (ms_Instance != null) { //Don't init twice //Check if there are 2 objects with this script. If yes, remove this component. if (ms_Instance != this) { UnityEngine.Object.DestroyImmediate(this.gameObject); } return; } Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; initSettings.uMonitorPoolSize = (uint)monitorPoolSize * 1024; initSettings.uMonitorQueuePoolSize = (uint)monitorQueuePoolSize * 1024; #if (!UNITY_ANDROID && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path. initSettings.szPluginDLLPath = Path.Combine(Application.dataPath, "Plugins" + Path.DirectorySeparatorChar); #endif AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); #if UNITY_EDITOR AkSoundEngine.SetGameName(Application.productName + " (Editor)"); #else AkSoundEngine.SetGameName(Application.productName); #endif AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, (uint)preparePoolSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } ms_Instance = this; string basePathToSet = AkBasePathGetter.GetSoundbankBasePath(); if (string.IsNullOrEmpty(basePathToSet)) { return; } result = AkSoundEngine.SetBasePath(basePathToSet); if (result != AKRESULT.AK_Success) { return; } #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch AkSoundEngine.SetDecodedBankPath(GetDecodedBankFullPath()); #endif AkSoundEngine.SetCurrentLanguage(language); #if !UNITY_SWITCH // Calling Application.persistentDataPath crashes Switch // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms. AkSoundEngine.AddBasePath(Application.persistentDataPath + Path.DirectorySeparatorChar); #endif result = AkCallbackManager.Init(callbackManagerBufferSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; return; } AkBankManager.Reset(); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); #if UNITY_EDITOR //Redirect Wwise error messages into Unity console. AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole); #endif //Load the init bank right away. Errors will be logged automatically. uint BankID; result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } #if UNITY_EDITOR EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged; #endif }
public static AKRESULT Init(AkMemSettings in_pMemSettings, AkStreamMgrSettings in_pStmSettings, AkDeviceSettings in_pDefaultDeviceSettings, AkInitSettings in_pSettings, AkPlatformInitSettings in_pPlatformSettings, AkMusicSettings in_pMusicSettings) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_Init(AkMemSettings.getCPtr(in_pMemSettings), AkStreamMgrSettings.getCPtr(in_pStmSettings), AkDeviceSettings.getCPtr(in_pDefaultDeviceSettings), AkInitSettings.getCPtr(in_pSettings), AkPlatformInitSettings.getCPtr(in_pPlatformSettings), AkMusicSettings.getCPtr(in_pMusicSettings)); return ret; }
internal static IntPtr getCPtr(AkMusicSettings obj) { return((obj == null) ? IntPtr.Zero : obj.swigCPtr); }
public void Initialize() { if (AkInitializer.ms_Instance != null) { if (AkInitializer.ms_Instance != this) { UnityEngine.Object.DestroyImmediate(base.gameObject); } return; } AkMemSettings akMemSettings = new AkMemSettings(); akMemSettings.uMaxNumPools = 40u; AkDeviceSettings akDeviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(akDeviceSettings); AkStreamMgrSettings akStreamMgrSettings = new AkStreamMgrSettings(); akStreamMgrSettings.uMemorySize = (uint)(this.streamingPoolSize * 1024); AkInitSettings akInitSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(akInitSettings); akInitSettings.uDefaultPoolSize = (uint)(this.defaultPoolSize * 1024); AkPlatformInitSettings akPlatformInitSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(akPlatformInitSettings); akPlatformInitSettings.uLEngineDefaultPoolSize = (uint)(this.lowerPoolSize * 1024); akPlatformInitSettings.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold; AkMusicSettings akMusicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(akMusicSettings); AKRESULT aKRESULT = AkSoundEngine.Init(akMemSettings, akStreamMgrSettings, akDeviceSettings, akInitSettings, akPlatformInitSettings, akMusicSettings); if (aKRESULT != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; } AkInitializer.ms_Instance = this; string validBasePath = AkBasePathGetter.GetValidBasePath(); if (string.IsNullOrEmpty(validBasePath)) { return; } aKRESULT = AkSoundEngine.SetBasePath(validBasePath); if (aKRESULT != AKRESULT.AK_Success) { return; } AkSoundEngine.SetCurrentLanguage("Chinese(PRC)"); aKRESULT = AkCallbackManager.Init(); if (aKRESULT != AKRESULT.AK_Success) { ClientLogger.Error("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); AkInitializer.ms_Instance = null; return; } AkBankManager.Reset(); UnityEngine.Object.DontDestroyOnLoad(this); }
internal static HandleRef getCPtr(AkMusicSettings obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
private void Awake() { if (AkInitializer.ms_Instance != null) { if (AkInitializer.ms_Instance != this) { Object.DestroyImmediate(base.gameObject); } return; } Debug.Log("WwiseUnity: Initialize sound engine ..."); AkMemSettings akMemSettings = new AkMemSettings(); akMemSettings.uMaxNumPools = 40u; AkDeviceSettings akDeviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(akDeviceSettings); AkStreamMgrSettings akStreamMgrSettings = new AkStreamMgrSettings(); akStreamMgrSettings.uMemorySize = (uint)(this.streamingPoolSize * 1024); AkInitSettings akInitSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(akInitSettings); akInitSettings.uDefaultPoolSize = (uint)(this.defaultPoolSize * 1024); AkPlatformInitSettings akPlatformInitSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(akPlatformInitSettings); akPlatformInitSettings.uLEngineDefaultPoolSize = (uint)(this.lowerPoolSize * 1024); akPlatformInitSettings.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold; AkMusicSettings akMusicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(akMusicSettings); AKRESULT aKRESULT = AkSoundEngine.Init(akMemSettings, akStreamMgrSettings, akDeviceSettings, akInitSettings, akPlatformInitSettings, akMusicSettings); if (aKRESULT != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; } AkInitializer.ms_Instance = this; AkBankPathUtil.UsePlatformSpecificPath(); string platformBasePath = AkBankPathUtil.GetPlatformBasePath(); if (!AkInitializer.s_loadBankFromMemory) { } AkSoundEngine.SetBasePath(platformBasePath); AkSoundEngine.SetCurrentLanguage(this.language); aKRESULT = AkCallbackManager.Init(); if (aKRESULT != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); AkInitializer.ms_Instance = null; return; } Debug.Log("WwiseUnity: Sound engine initialized."); Object.DontDestroyOnLoad(this); if (AkInitializer.s_loadBankFromMemory) { string soundBankPathInResources = AkInitializer.GetSoundBankPathInResources("Init.bytes"); CBinaryObject cBinaryObject = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject; GCHandle gCHandle = GCHandle.Alloc(cBinaryObject.m_data, 3); IntPtr intPtr = gCHandle.AddrOfPinnedObject(); if (intPtr != IntPtr.Zero) { uint num; aKRESULT = AkSoundEngine.LoadBank(intPtr, (uint)cBinaryObject.m_data.Length, -1, out num); gCHandle.Free(); } else { aKRESULT = AKRESULT.AK_Fail; } Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources); } else { uint num2; aKRESULT = AkSoundEngine.LoadBank("Init.bnk", -1, out num2); } if (aKRESULT != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + aKRESULT.ToString()); } }
internal static HandleRef getCPtr(AkMusicSettings obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
internal static IntPtr getCPtr(AkMusicSettings obj) { return (obj == null) ? IntPtr.Zero : obj.swigCPtr; }
internal static global::System.IntPtr getCPtr(AkMusicSettings obj) { return((obj == null) ? global::System.IntPtr.Zero : obj.swigCPtr); }
void Awake() { if (ms_Instance != null) { return; //Don't init twice } #if UNITY_ANDROID InitalizeAndroidSoundBankIO(); #endif Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; #if UNITY_IOS && !UNITY_EDITOR platformSettings.bAppListensToInterruption = true; #endif // #if UNITY_IOS && !UNITY_EDITOR AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } AkBankPath.UsePlatformSpecificPath(); string platformBasePath = AkBankPath.GetPlatformBasePath(); // Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder. // Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test // our SoundBank folder for Android. #if !UNITY_ANDROID && !UNITY_METRO if (!AkBankPath.Exists(platformBasePath)) { string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath); Debug.LogError(errorMsg); return; } #endif // #if !UNITY_ANDROID AkSoundEngine.SetBasePath(platformBasePath); AkSoundEngine.SetCurrentLanguage(language); result = AkCallbackManager.Init(); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); return; } AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, null); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); ms_Instance = this; //Load the init bank right away. Errors will be logged automatically. uint BankID; result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } }
private void Awake() { if (ms_Instance != null) { if (ms_Instance != this) { UnityEngine.Object.DestroyImmediate(base.gameObject); } } else { Debug.Log("WwiseUnity: Initialize sound engine ..."); AkMemSettings settings = new AkMemSettings { uMaxNumPools = 40 }; AkDeviceSettings settings2 = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(settings2); AkStreamMgrSettings settings3 = new AkStreamMgrSettings { uMemorySize = (uint)(this.streamingPoolSize * 0x400) }; AkInitSettings settings4 = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(settings4); settings4.uDefaultPoolSize = (uint)(this.defaultPoolSize * 0x400); AkPlatformInitSettings settings5 = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(settings5); settings5.uLEngineDefaultPoolSize = (uint)(this.lowerPoolSize * 0x400); settings5.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold; AkMusicSettings settings6 = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(settings6); if (AkSoundEngine.Init(settings, settings3, settings2, settings4, settings5, settings6) != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); } else { ms_Instance = this; AkBankPathUtil.UsePlatformSpecificPath(); string platformBasePath = AkBankPathUtil.GetPlatformBasePath(); if (!s_loadBankFromMemory) { } AkSoundEngine.SetBasePath(platformBasePath); AkSoundEngine.SetCurrentLanguage(this.language); if (AkCallbackManager.Init() != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; } else { AKRESULT akresult; uint num; Debug.Log("WwiseUnity: Sound engine initialized."); UnityEngine.Object.DontDestroyOnLoad(this); if (s_loadBankFromMemory) { string soundBankPathInResources = GetSoundBankPathInResources("Init.bytes"); CBinaryObject content = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject; GCHandle handle = GCHandle.Alloc(content.m_data, GCHandleType.Pinned); IntPtr ptr = handle.AddrOfPinnedObject(); if (ptr != IntPtr.Zero) { akresult = AkSoundEngine.LoadBank(ptr, (uint)content.m_data.Length, -1, out num); handle.Free(); } else { akresult = AKRESULT.AK_Fail; } Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources); } else { akresult = AkSoundEngine.LoadBank("Init.bnk", -1, out num); } if (akresult != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + akresult.ToString()); } } } } }
public static void GetDefaultMusicSettings(AkMusicSettings out_settings) { AkSoundEnginePINVOKE.CSharp_GetDefaultMusicSettings(AkMusicSettings.getCPtr(out_settings)); }
void Awake() { if (ms_Instance != null) return; //Don't init twice #if UNITY_ANDROID && !UNITY_EDITOR InitalizeAndroidSoundBankIO(); #endif Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } ms_Instance = this; AkBankPath.UsePlatformSpecificPath(); string platformBasePath = AkBankPath.GetPlatformBasePath(); // Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder. // Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test // our SoundBank folder for Android. #if !UNITY_ANDROID && !UNITY_METRO && !UNITY_PSP2 if ( ! AkBankPath.Exists(platformBasePath) ) { string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath); Debug.LogError(errorMsg); ms_Instance = null; return; } #endif // #if !UNITY_ANDROID AkSoundEngine.SetBasePath(platformBasePath); AkSoundEngine.SetCurrentLanguage(language); result = AkCallbackManager.Init(); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; return; } AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, null); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); //Load the init bank right away. Errors will be logged automatically. uint BankID; #if UNITY_ANDROID && !UNITY_METRO && AK_LOAD_BANK_IN_MEMORY result = AkInMemBankLoader.LoadNonLocalizedBank("Init.bnk"); #else result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); #endif // #if UNITY_ANDROID && !UNITY_METRO && AK_ANDROID_BANK_IN_OBB if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } }
public void CopyTo(AkMusicSettings settings) { settings.fStreamingLookAheadRatio = m_StreamingLookAheadRatio; }
public void Initialize() { if (ms_Instance != null) { //Don't init twice //Check if there are 2 objects with this script. If yes, remove this component. if (ms_Instance != this) { UnityEngine.Object.DestroyImmediate(this.gameObject); } return; } Debug.Log("WwiseUnity: Initialize sound engine ..."); //Use default properties for most SoundEngine subsystem. //The game programmer should modify these when needed. See the Wwise SDK documentation for the initialization. //These settings may very well change for each target platform. AkMemSettings memSettings = new AkMemSettings(); memSettings.uMaxNumPools = 20; AkDeviceSettings deviceSettings = new AkDeviceSettings(); AkSoundEngine.GetDefaultDeviceSettings(deviceSettings); AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings(); streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024; AkInitSettings initSettings = new AkInitSettings(); AkSoundEngine.GetDefaultInitSettings(initSettings); initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024; AkPlatformInitSettings platformSettings = new AkPlatformInitSettings(); AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings); platformSettings.uLEngineDefaultPoolSize = (uint)lowerPoolSize * 1024; platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold; AkMusicSettings musicSettings = new AkMusicSettings(); AkSoundEngine.GetDefaultMusicSettings(musicSettings); // Unity 5 only, UNity 4 doesn't provide a way to access the product name at runtime. #if UNITY_5 #if UNITY_EDITOR AkSoundEngine.SetGameName(Application.productName + " (Editor)"); #else AkSoundEngine.SetGameName(Application.productName); #endif #endif AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, (uint)preparePoolSize * 1024); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort."); return; //AkSoundEngine.Init should have logged more details. } ms_Instance = this; string basePathToSet = AkBasePathGetter.GetValidBasePath(); if (string.IsNullOrEmpty(basePathToSet)) { return; } result = AkSoundEngine.SetBasePath(basePathToSet); if (result != AKRESULT.AK_Success) { return; } AkSoundEngine.SetCurrentLanguage(language); result = AkCallbackManager.Init(); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); ms_Instance = null; return; } AkBankManager.Reset(); Debug.Log("WwiseUnity: Sound engine initialized."); //The sound engine should not be destroyed once it is initialized. DontDestroyOnLoad(this); #if UNITY_EDITOR //Redirect Wwise error messages into Unity console. AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole); #endif //Load the init bank right away. Errors will be logged automatically. uint BankID; result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID); if (result != AKRESULT.AK_Success) { Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString()); } #if UNITY_EDITOR EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged; #endif }