Exemple #1
0
    public static void Update(bool forceUpdate = false)
    {
        //Gather all GeneratedSoundBanks folder from the project
        var allPaths     = AkUtilities.GetAllBankPaths();
        var bNeedRefresh = false;
        var projectPath  = System.IO.Path.GetDirectoryName(AkUtilities.GetFullPath(UnityEngine.Application.dataPath,
                                                                                   WwiseSettings.LoadSettings().WwiseProjectPath));

        AkWwiseInitializationSettings.UpdatePlatforms();

        //Go through all BasePlatforms
        foreach (var pairPF in AkUtilities.PlatformMapping)
        {
            //Go through all custom platforms related to that base platform and check if any of the bank files were updated.
            var bParse    = forceUpdate;
            var fullPaths = new System.Collections.Generic.List <string>();
            foreach (var customPF in pairPF.Value)
            {
                string bankPath;
                if (!allPaths.TryGetValue(customPF, out bankPath))
                {
                    continue;
                }

                var pluginFile = "";
                try
                {
                    pluginFile = System.IO.Path.Combine(projectPath, System.IO.Path.Combine(bankPath, "PluginInfo.xml"));
                    pluginFile = pluginFile.Replace('/', System.IO.Path.DirectorySeparatorChar);
                    if (!System.IO.File.Exists(pluginFile))
                    {
                        //Try in StreamingAssets too.
                        pluginFile = System.IO.Path.Combine(System.IO.Path.Combine(AkBasePathGetter.GetFullSoundBankPath(), customPF),
                                                            "PluginInfo.xml");
                        if (!System.IO.File.Exists(pluginFile))
                        {
                            continue;
                        }
                    }

                    fullPaths.Add(pluginFile);

                    var t        = System.IO.File.GetLastWriteTime(pluginFile);
                    var lastTime = System.DateTime.MinValue;
                    s_LastParsed.TryGetValue(customPF, out lastTime);
                    if (lastTime < t)
                    {
                        bParse = true;
                        s_LastParsed[customPF] = t;
                    }
                }
                catch (System.Exception ex)
                {
                    UnityEngine.Debug.LogError("WwiseUnity: " + pluginFile + " could not be parsed. " + ex.Message);
                }
            }

            if (bParse)
            {
                var platform = pairPF.Key;

                var newDlls = ParsePluginsXML(platform, fullPaths);
                System.Collections.Generic.HashSet <string> oldDlls = null;

                //Remap base Wwise platforms to Unity platform folders names
                if (platform.Contains("Vita"))
                {
                    platform = "Vita";
                }
                //else other platforms already have the right name

                s_PerPlatformPlugins.TryGetValue(platform, out oldDlls);
                s_PerPlatformPlugins[platform] = newDlls;

                //Check if there was any change.
                if (!bNeedRefresh && oldDlls != null)
                {
                    if (oldDlls.Count == newDlls.Count)
                    {
                        oldDlls.IntersectWith(newDlls);
                    }

                    bNeedRefresh |= oldDlls.Count != newDlls.Count;
                }
                else
                {
                    bNeedRefresh |= newDlls.Count > 0;
                }
            }
        }

        if (bNeedRefresh)
        {
            ActivatePluginsForEditor();
        }

        var currentConfig = GetCurrentConfig();

        CheckMenuItems(currentConfig);
    }
    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, "-batchmode") >= 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

        AkLogger.Instance.Init();

        if (isInitialized)
        {
#if UNITY_EDITOR
            if (AkWwiseInitializationSettings.ResetSoundEngine(UnityEngine.Application.isPlaying || UnityEditor.BuildPipeline.isBuildingPlayer))
            {
                UnityEditor.EditorApplication.update += LateUpdate;
            }

            if (UnityEditor.EditorApplication.isPaused && UnityEngine.Application.isPlaying)
            {
                AkSoundEngine.Suspend(true);
            }
#else
            UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized.");
#endif
            return;
        }

#if UNITY_EDITOR
        if (UnityEditor.BuildPipeline.isBuildingPlayer)
        {
            return;
        }
#endif

        if (!AkWwiseInitializationSettings.InitializeSoundEngine())
        {
            return;
        }

#if UNITY_EDITOR
        OnEnableEditorListener(akInitializer.gameObject);
        UnityEditor.EditorApplication.update += LateUpdate;
#endif
    }
    public void Init(AkInitializer akInitializer)
    {
#if UNITY_EDITOR
        if (!WasInitializedInPlayMode(akInitializer))
        {
            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
        bool isInitialized = AkSoundEngine.IsInitialized();
#endif

        AkLogger.Instance.Init();

        if (isInitialized)
        {
            UnityEngine.Debug.LogWarning("WwiseUnity: Sound engine is already initialized.");

#if UNITY_EDITOR
            if (AkWwiseInitializationSettings.ResetSoundEngine(UnityEngine.Application.isPlaying || UnityEditor.BuildPipeline.isBuildingPlayer))
            {
                UnityEditor.EditorApplication.update += LateUpdate;
            }
#endif
            return;
        }

#if UNITY_EDITOR
        if (UnityEditor.BuildPipeline.isBuildingPlayer)
        {
            return;
        }
#endif

        if (!AkWwiseInitializationSettings.InitializeSoundEngine())
        {
            return;
        }

#if UNITY_EDITOR
#if UNITY_2017_2_OR_NEWER
        UnityEditor.EditorApplication.pauseStateChanged += OnPauseStateChanged;
#else
        UnityEditor.EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged;
#endif

        OnEnableEditorListener(akInitializer.gameObject);
        UnityEditor.EditorApplication.update += LateUpdate;
#endif
    }