Esempio n. 1
0
    public AkBankHandle(string name, bool decode, bool save)
    {
        bankName        = name;
        bankCallback    = null;
        decodeBank      = decode;
        saveDecodedBank = save;

        // Verify if the bank has already been decoded
        if (decodeBank)
        {
            string DecodedBankPath = System.IO.Path.Combine(AkInitializer.GetDecodedBankFullPath(), bankName + ".bnk");
            string EncodedBankPath = System.IO.Path.Combine(AkBasePathGetter.GetValidBasePath(), bankName + ".bnk");
            if (System.IO.File.Exists(DecodedBankPath))
            {
                try
                {
                    if (System.IO.File.GetLastWriteTime(DecodedBankPath) > System.IO.File.GetLastWriteTime(EncodedBankPath))
                    {
                        relativeBasePath = AkInitializer.GetDecodedBankFolder();
                        decodeBank       = false;
                    }
                }
                catch
                {
                    // Assume the decoded bank exists, but is not accessible. Re-decode it anyway, so we do nothing.
                }
            }
        }
    }
Esempio n. 2
0
        static void Reload(UnityModManager.ModEntry modEntry)
        {
            CustomSoundpackPaths.Clear();
            foreach (var soundPackSettings in settings.SoundPackSettingsList)
            {
                soundPackSettings.IsValid = soundPackSettings.Files.All(fileName => !CustomSoundpackPaths.ContainsKey(fileName));
                if (!soundPackSettings.IsValid)
                {
                    continue;
                }
                if (!soundPackSettings.Enabled)
                {
                    continue;
                }
                foreach (var soundBank in soundPackSettings.Files)
                {
                    var basePath   = new Uri(AkBasePathGetter.GetValidBasePath());
                    var customPath = new Uri(Path.Combine(modEntry.Path, soundPackSettings.Name));
                    CustomSoundpackPaths[soundBank] = Uri.UnescapeDataString(basePath.MakeRelativeUri(customPath).ToString());
                }
            }
            var loadedBanks = Traverse.Create(typeof(SoundBanksManager)).Field("s_LoadCount").GetValue <Dictionary <string, int> >();

            foreach (var soundBank in DirtySoundbanks)
            {
                if (loadedBanks.ContainsKey(soundBank))
                {
                    AkBankManager.UnloadBank(soundBank);
                    AkBankManager.DoUnloadBanks();
                    AkBankManager.LoadBank(soundBank, false, false);
                }
            }
            DirtySoundbanks.Clear();
        }
Esempio n. 3
0
    /// Loads a bank. This version blocks until the bank is loaded. See AK::SoundEngine::LoadBank for more information.
    public void LoadBank()
    {
        if (m_RefCount == 0)
        {
            AKRESULT res = AKRESULT.AK_Fail;

            // There might be a case where we were asked to unload the SoundBank, but then asked immediately after to load that bank.
            // If that happens, there will be a short amount of time where the ref count will be 0, but the bank will still be in memory.
            // In that case, we do not want to unload the bank, so we have to remove it from the list of pending bank unloads.
            if (AkBankManager.BanksToUnload.Contains(this))
            {
                AkBankManager.BanksToUnload.Remove(this);
                IncRef();
                return;
            }

            if (decodeBank == false)
            {
                string basePathToSet = null;

                if (!string.IsNullOrEmpty(relativeBasePath))
                {
                    basePathToSet = AkBasePathGetter.GetValidBasePath();
                    if (string.IsNullOrEmpty(basePathToSet))
                    {
                        Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (could not obtain base path to set).");
                        return;
                    }

                    res = AkSoundEngine.SetBasePath(System.IO.Path.Combine(basePathToSet, relativeBasePath));
                }
                else
                {
                    res = AKRESULT.AK_Success;
                }

                if (res == AKRESULT.AK_Success)
                {
                    res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);

                    if (!string.IsNullOrEmpty(basePathToSet))
                    {
                        AkSoundEngine.SetBasePath(basePathToSet);
                    }
                }
            }
            else
            {
                res = AkSoundEngine.LoadAndDecodeBank(bankName, saveDecodedBank, out m_BankID);
            }

            if (res != AKRESULT.AK_Success)
            {
                Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + res.ToString() + ")");
            }
        }
        IncRef();
    }
Esempio n. 4
0
        public static void Postfix(string ___name)
        {
            if (!ModTek.CustomResources["SoundBank"].ContainsKey(___name))
            {
                return;
            }

            var basePath = AkBasePathGetter.GetValidBasePath();

            AkSoundEngine.SetBasePath(basePath);
        }
Esempio n. 5
0
    private AkWwiseXMLWatcher()
    {
        XmlWatcher      = new FileSystemWatcher();
        SoundBankFolder = AkBasePathGetter.GetValidBasePath();

        try
        {
            XmlWatcher.Path         = SoundBankFolder;
            XmlWatcher.NotifyFilter = NotifyFilters.LastWrite;

            // Event handlers that are watching for specific event
            XmlWatcher.Created += new FileSystemEventHandler(RaisePopulateFlag);
            XmlWatcher.Changed += new FileSystemEventHandler(RaisePopulateFlag);

            XmlWatcher.Filter = "*.xml";
            XmlWatcher.IncludeSubdirectories = true;
        }
        catch (Exception)
        {
            // Deliberately left empty
        }
    }
Esempio n. 6
0
    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;
#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);

// 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;
        }

#if !UNITY_SWITCH
        AkSoundEngine.SetDecodedBankPath(GetDecodedBankFullPath());
#endif

        AkSoundEngine.SetCurrentLanguage(language);

#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        AkSoundEngine.AddBasePath(Application.persistentDataPath + Path.DirectorySeparatorChar);
#endif

        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 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);
    }