示例#1
0
    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());
                    }
                }
            }
        }
    }
示例#2
0
    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());
        }
    }
    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());
        }
    }