Exemple #1
0
        public void LoadBank(string bankName, CSoundManager.BankType bankType)
        {
            if (!this.m_isPrepared)
            {
                return;
            }
            if (this.m_loadedBanks[(int)bankType].Contains(bankName))
            {
                return;
            }
            if (AkInitializer.s_loadBankFromMemory)
            {
                string        soundBankPathInResources = AkInitializer.GetSoundBankPathInResources(bankName);
                CBinaryObject cBinaryObject            = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), 2, false, false).m_content as CBinaryObject;

                if (cBinaryObject != null)
                {
                    AkBankManager.LoadBank(bankName, cBinaryObject.m_data);
                }
                Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
            }
            else
            {
                AkBankManager.LoadBank(bankName);
            }
            this.m_loadedBanks[(int)bankType].Add(bankName);
        }
    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());
        }
    }