Inheritance: MonoBehaviour
    void OnEnable()
    {
        m_AkInit = target as AkInitializer;   

		m_basePath = serializedObject.FindProperty("basePath");
		m_language = serializedObject.FindProperty("language"); 
		m_defaultPoolSize = serializedObject.FindProperty("defaultPoolSize");
		m_lowerPoolSize = serializedObject.FindProperty("lowerPoolSize");
		m_streamingPoolSize = serializedObject.FindProperty("streamingPoolSize");
		m_memoryCutoffThreshold = serializedObject.FindProperty("memoryCutoffThreshold");
        m_engineLogging = serializedObject.FindProperty("engineLogging");
    }
Exemplo n.º 2
0
 public void CopyInitSettings(AkInitializer in_AkInit)
 {
     if (!CompareInitSettings(in_AkInit))
     {
         in_AkInit.basePath = 				basePath;
         in_AkInit.language =                language;
         in_AkInit.defaultPoolSize =         defaultPoolSize;
         in_AkInit.lowerPoolSize =           lowerPoolSize;
         in_AkInit.streamingPoolSize =       streamingPoolSize;
         in_AkInit.memoryCutoffThreshold =   memoryCutoffThreshold;
         EditorUtility.SetDirty(in_AkInit);
     }
 }
    private bool WasInitializedInPlayMode(AkInitializer akInitializer)
    {
        if (UnityEngine.Application.isPlaying)
        {
            if (AkInitializers.Contains(akInitializer))
            {
                return(false);
            }

            AkInitializers.Add(akInitializer);
            return(AkInitializers.Count == 1);
        }

        return(true);
    }
Exemplo n.º 4
0
    public static string GetFullSoundBankPath()
    {
        // Get full path of base path
#if UNITY_ANDROID && !UNITY_EDITOR
        string fullBasePath = AkInitializer.GetBasePath();
#else
        string fullBasePath = Path.Combine(Application.streamingAssetsPath, AkInitializer.GetBasePath());
#endif

#if UNITY_SWITCH
        fullBasePath = fullBasePath.Substring(1);
#endif
        FixSlashes(ref fullBasePath);
        return(fullBasePath);
    }
Exemplo n.º 5
0
    public void CopyInitSettings(AkInitializer in_AkInit)
    {
        if (!CompareInitSettings(in_AkInit))
        {
            UnityEditor.Undo.RecordObject(in_AkInit, "Copy Init Settings");

            in_AkInit.basePath                  = basePath;
            in_AkInit.language                  = language;
            in_AkInit.defaultPoolSize           = defaultPoolSize;
            in_AkInit.lowerPoolSize             = lowerPoolSize;
            in_AkInit.streamingPoolSize         = streamingPoolSize;
            in_AkInit.preparePoolSize           = preparePoolSize;
            in_AkInit.memoryCutoffThreshold     = memoryCutoffThreshold;
            in_AkInit.callbackManagerBufferSize = callbackManagerBufferSize;
        }
    }
Exemplo n.º 6
0
    public static string GetBasePath()
    {
#if UNITY_EDITOR
        if (EditorApplication.isPlaying)
        {
            return(ms_Instance.basePath);
        }
        else
        {
            AkInitializer initializer = (AkInitializer)FindObjectOfType(typeof(AkInitializer));
            return(initializer.basePath);
        }
#else
        return(ms_Instance.basePath);
#endif
    }
Exemplo n.º 7
0
    /// Returns the bank path, depending on the settings of AkInitializer, without platform-specific folder, in the proper path format.
    public static string GetFullBasePath()
    {
        // Get full path of base path
#if UNITY_ANDROID && !UNITY_EDITOR
        // Wwise Android SDK now loads SoundBanks from APKs.
        #if AK_LOAD_BANK_IN_MEMORY
        string fullBasePath = Path.Combine(Application.streamingAssetsPath, AkInitializer.GetBasePath());
        #else
        string fullBasePath = AkInitializer.GetBasePath();
        #endif // #if AK_LOAD_BANK_IN_MEMORY
#else
        string fullBasePath = Path.Combine(Application.streamingAssetsPath, AkInitializer.GetBasePath());
#endif
        LazyAppendTrailingSeparator(ref fullBasePath);
        LazyConvertPathConvention(ref fullBasePath);
        return(fullBasePath);
    }
    void OnEnable()
    {
        m_AkInit = target as AkInitializer;

        m_basePath                  = serializedObject.FindProperty("basePath");
        m_language                  = serializedObject.FindProperty("language");
        m_defaultPoolSize           = serializedObject.FindProperty("defaultPoolSize");
        m_lowerPoolSize             = serializedObject.FindProperty("lowerPoolSize");
        m_streamingPoolSize         = serializedObject.FindProperty("streamingPoolSize");
        m_preparePoolSize           = serializedObject.FindProperty("preparePoolSize");
        m_memoryCutoffThreshold     = serializedObject.FindProperty("memoryCutoffThreshold");
        m_callbackManagerBufferSize = serializedObject.FindProperty("callbackManagerBufferSize");
        m_engineLogging             = serializedObject.FindProperty("engineLogging");
        m_spatialAudioPoolSize      = serializedObject.FindProperty("spatialAudioPoolSize");
        m_maxSoundPropagationDepth  = serializedObject.FindProperty("maxSoundPropagationDepth");
        m_diffractionFlags          = serializedObject.FindProperty("diffractionFlags");
    }
 public void SaveInitSettings(AkInitializer in_AkInit)
 {
     if (!AkWwisePicker.WwiseProjectFound)
     {
         return;
     }
     if (!CompareInitSettings(in_AkInit))
     {
         basePath              = in_AkInit.basePath;
         language              = in_AkInit.language;
         defaultPoolSize       = in_AkInit.defaultPoolSize;
         lowerPoolSize         = in_AkInit.lowerPoolSize;
         streamingPoolSize     = in_AkInit.streamingPoolSize;
         memoryCutoffThreshold = in_AkInit.memoryCutoffThreshold;
         EditorUtility.SetDirty(this);
     }
 }
Exemplo n.º 10
0
    public bool LoadBank(string inBankFileName, bool localized = false)
    {
        if (_DicBankLoad.ContainsKey(inBankFileName.ToLower()))
        {
            return(true);
        }

        /*
         * string bankPath;
         *
         * if (!localized)
         *  bankPath = HobaText.Format("{0}/{1}/{2}/{3}", EntryPoint.Instance.ResPath, AkInitializer.GetBasePath(), AkBasePathGetter.GetPlatformName(), in_bankFileName);
         * else
         *  bankPath = HobaText.Format("{0}/{1}/{2}/{3}/{4}", EntryPoint.Instance.ResPath, AkInitializer.GetBasePath(), AkBasePathGetter.GetPlatformName(), AkInitializer.GetCurrentLanguage(), in_bankFileName);
         *
         * SBankEntry entry = new SBankEntry();
         * if (DoLoadBankFromImage(bankPath, entry))
         * {
         *  string name = localized ? HobaText.Format("{0}/{1}", AkInitializer.GetCurrentLanguage(), in_bankFileName.ToLower()) : in_bankFileName.ToLower();
         *  entry.gameObject = new GameObject(name);
         *  entry.gameObject.transform.parent = WwiseSoundMan.Instance.BanksLoaded.transform;
         *  _DicBankLoad.Add(in_bankFileName.ToLower(), entry);
         *  return true;
         * }
         *
         * HobaDebuger.LogWarningFormat("LoadBank Failed: {0}", bankPath);
         * return false;
         */


        CBankEntry entry = new CBankEntry();
        string     name  = localized ? HobaText.Format("{0}/{1}", AkInitializer.GetCurrentLanguage(), inBankFileName) : inBankFileName;
        AKRESULT   ret   = AkSoundEngine.LoadBank(name, AkSoundEngine.AK_DEFAULT_POOL_ID, out entry.BankID);

        if (ret == AKRESULT.AK_Success)
        {
            entry.GameObject = new GameObject(name);
            entry.GameObject.transform.parent = WwiseSoundMan.Instance.BanksLoaded.transform;
            _DicBankLoad.Add(inBankFileName.ToLower(), entry);
            return(true);
        }

        HobaDebuger.LogWarningFormat("LoadBank Failed: {0}", name);
        return(false);
    }
Exemplo n.º 11
0
    public AkBankHandle(string name, bool decode, bool save)
    {
        bankName        = name;
        bankCallback    = null;
        decodeBank      = decode;
        saveDecodedBank = save;

#if !UNITY_EDITOR
        // Verify if the bank has already been decoded
        if (decodeBank)
        {
            if (System.IO.File.Exists(System.IO.Path.Combine(AkInitializer.GetDecodedBankFullPath(), bankName + ".bnk")))
            {
                relativeBasePath = AkInitializer.GetDecodedBankFolder();
                decodeBank       = false;
            }
        }
#endif
    }
Exemplo n.º 12
0
    public void CopyInitSettings(AkInitializer in_AkInit)
    {
        if (!CompareInitSettings(in_AkInit))
        {
#if UNITY_5_3_OR_NEWER
            Undo.RecordObject(in_AkInit, "Copy Init Settings");
#endif
            in_AkInit.basePath              = basePath;
            in_AkInit.language              = language;
            in_AkInit.defaultPoolSize       = defaultPoolSize;
            in_AkInit.lowerPoolSize         = lowerPoolSize;
            in_AkInit.streamingPoolSize     = streamingPoolSize;
            in_AkInit.preparePoolSize       = preparePoolSize;
            in_AkInit.memoryCutoffThreshold = memoryCutoffThreshold;
#if !UNITY_5_3_OR_NEWER
            EditorUtility.SetDirty(in_AkInit);
#endif
        }
    }
    private void Awake()
    {
        if (ms_Instance)
        {
            DestroyImmediate(this);
            return;
        }

        ms_Instance = this;

#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            return;
        }
#endif

        DontDestroyOnLoad(this);
    }
        public void Migrate(AkInitializer akInitializer)
        {
            if (hasMigrated)
            {
                return;
            }

            var initializationSettings = akInitializer.InitializationSettings;

            if (!initializationSettings)
            {
                initializationSettings = AkWwiseInitializationSettings.Instance;
                if (!initializationSettings)
                {
                    return;
                }
            }

            initializationSettings.UserSettings.m_BasePath                         = akInitializer.basePath;
            initializationSettings.UserSettings.m_StartupLanguage                  = akInitializer.language;
            initializationSettings.UserSettings.m_DefaultPoolSize                  = (uint)akInitializer.defaultPoolSize * 1024;
            initializationSettings.UserSettings.m_LowerEnginePoolSize              = (uint)akInitializer.lowerPoolSize * 1024;
            initializationSettings.UserSettings.m_StreamManagerPoolSize            = (uint)akInitializer.streamingPoolSize * 1024;
            initializationSettings.UserSettings.m_PreparePoolSize                  = (uint)akInitializer.preparePoolSize * 1024;
            initializationSettings.UserSettings.m_LowerEngineMemoryCutoffThreshold = akInitializer.memoryCutoffThreshold;

            initializationSettings.AdvancedSettings.m_MonitorPoolSize      = (uint)akInitializer.monitorPoolSize * 1024;
            initializationSettings.AdvancedSettings.m_MonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024;

            initializationSettings.CallbackManagerInitializationSettings.BufferSize = akInitializer.callbackManagerBufferSize * 1024;

            initializationSettings.UserSettings.m_SpatialAudioSettings.m_PoolSize = (uint)akInitializer.spatialAudioPoolSize * 1024;
            initializationSettings.UserSettings.m_SpatialAudioSettings.m_MaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth;
            initializationSettings.UserSettings.m_SpatialAudioSettings.m_DiffractionFlags         = (AkCommonUserSettings.SpatialAudioSettings.DiffractionFlags)akInitializer.diffractionFlags;

            initializationSettings.CallbackManagerInitializationSettings.IsLoggingEnabled = akInitializer.engineLogging;

            UnityEditor.EditorUtility.SetDirty(initializationSettings);
            UnityEditor.AssetDatabase.SaveAssets();

            UnityEngine.Debug.Log("WwiseUnity: Converted from AkInitializer to AkWwiseInitializationSettings.");
            hasMigrated = true;
        }
Exemplo n.º 15
0
    public void SaveInitSettings(AkInitializer in_AkInit)
    {
        if (!AkWwisePicker.WwiseProjectFound)
        {
            return;
        }
        if (!CompareInitSettings(in_AkInit))
        {
            Undo.RecordObject(this, "Save Init Settings");

            basePath                  = in_AkInit.basePath;
            language                  = in_AkInit.language;
            defaultPoolSize           = in_AkInit.defaultPoolSize;
            lowerPoolSize             = in_AkInit.lowerPoolSize;
            streamingPoolSize         = in_AkInit.streamingPoolSize;
            preparePoolSize           = in_AkInit.preparePoolSize;
            memoryCutoffThreshold     = in_AkInit.memoryCutoffThreshold;
            callbackManagerBufferSize = in_AkInit.callbackManagerBufferSize;
        }
    }
            // Token: 0x06000B4F RID: 2895 RVA: 0x00037E98 File Offset: 0x00036098
            public override void SetString(string newValue)
            {
                int num;

                if (TextSerialization.TryParseInvariant(newValue, out num))
                {
                    AkInitializer akInitializer = AudioManager.akInitializerMsInstanceField.GetValue(null) as AkInitializer;
                    if (akInitializer)
                    {
                        AkWwiseInitializationSettings            initializationSettings  = akInitializer.InitializationSettings;
                        AkCallbackManager.InitializationSettings initializationSettings2 = (initializationSettings != null) ? initializationSettings.CallbackManagerInitializationSettings : null;
                        if (initializationSettings2 != null)
                        {
                            initializationSettings2.IsLoggingEnabled = (num != 0);
                            return;
                        }
                        Debug.Log("Cannot set value. callbackManagerInitializationSettings is null.");
                    }
                }
            }
Exemplo n.º 17
0
    public override void OnChildInspectorGUI()
    {
        serializedObject.Update();

        m_LoadBankEventHandlerInspector.OnGUI();
        m_UnloadBankEventHandlerInspector.OnGUI();

        GUILayout.Space(5);

        GUILayout.BeginVertical("Box");
        {
            bool oldDecodeValue      = decode.boolValue;
            bool oldSaveDecodedValue = saveDecoded.boolValue;
            EditorGUILayout.PropertyField(loadAsync, new GUIContent("Asynchronous:"));
            EditorGUILayout.PropertyField(decode, new GUIContent("Decode compressed data:"));

            if (decode.boolValue)
            {
                if (decode.boolValue != oldDecodeValue && AkWwiseProjectInfo.GetData().preparePoolSize == 0)
                {
                    EditorUtility.DisplayDialog("Warning", "You will need to define a prepare pool size in the AkInitializer component options.", "Ok");
                }
                EditorGUILayout.PropertyField(saveDecoded, new GUIContent("Save decoded bank:"));
                if (oldSaveDecodedValue == true && saveDecoded.boolValue == false)
                {
                    string decodedBankPath = System.IO.Path.Combine(AkInitializer.GetDecodedBankFullPath(), bankName.stringValue + ".bnk");
                    try
                    {
                        System.IO.File.Delete(decodedBankPath);
                    }
                    catch (Exception e)
                    {
                        Debug.Log("WwiseUnity: Could not delete existing decoded SoundBank. Please delete it manually. " + e.ToString());
                    }
                }
            }
        }
        GUILayout.EndVertical();

        serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 18
0
    // Create a Wwise Global object containing the initializer and terminator scripts. Set the soundbank path of the initializer script.
    // This game object will live for the whole project; there is no need to instanciate one per scene.
    void CreateWwiseGlobalObject()
    {
        // Look for a game object which has the initializer component
        AkInitializer[] AkInitializers        = FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[];
        GameObject      WwiseGlobalGameObject = null;

        if (AkInitializers.Length > 0)
        {
            GameObject.DestroyImmediate(AkInitializers[0].gameObject);
        }
        WwiseGlobalGameObject = new GameObject("WwiseGlobal");

        // attach initializer component
        AkInitializer AkInit = WwiseGlobalGameObject.AddComponent <AkInitializer>();

        // Set the soundbank path property on the initializer
        AkInit.basePath = Settings.SoundbankPath;

        // Set focus on WwiseGlobal
        Selection.activeGameObject = WwiseGlobalGameObject;
    }
Exemplo n.º 19
0
        public void LoadBank(string bankName, BankType bankType)
        {
            if (this.m_isPrepared && !this.m_loadedBanks[(int)bankType].Contains(bankName))
            {
                if (AkInitializer.s_loadBankFromMemory)
                {
                    string        soundBankPathInResources = AkInitializer.GetSoundBankPathInResources(bankName);
                    CBinaryObject content = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject;

                    if (content != null)
                    {
                        AkBankManager.LoadBank(bankName, content.m_data);
                    }
                    Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
                }
                else
                {
                    AkBankManager.LoadBank(bankName);
                }
                this.m_loadedBanks[(int)bankType].Add(bankName);
            }
        }
Exemplo n.º 20
0
    public void SaveInitSettings(AkInitializer in_AkInit)
    {
        if (!AkWwisePicker.WwiseProjectFound)
        {
            return;
        }
        if (!CompareInitSettings(in_AkInit))
        {
            UnityEditor.Undo.RecordObject(this, "Save Init Settings");

            basePath                  = AudioPluginSettingAgent.GetBankAssetFolder();
            language                  = in_AkInit.language;
            defaultPoolSize           = in_AkInit.defaultPoolSize;
            lowerPoolSize             = in_AkInit.lowerPoolSize;
            streamingPoolSize         = in_AkInit.streamingPoolSize;
            preparePoolSize           = in_AkInit.preparePoolSize;
            memoryCutoffThreshold     = in_AkInit.memoryCutoffThreshold;
            callbackManagerBufferSize = in_AkInit.callbackManagerBufferSize;

            UnityEditor.EditorUtility.SetDirty(this);
        }
    }
            // Token: 0x06000B50 RID: 2896 RVA: 0x00037EF4 File Offset: 0x000360F4
            public override string GetString()
            {
                AkInitializer akInitializer = AudioManager.akInitializerMsInstanceField.GetValue(null) as AkInitializer;

                if (akInitializer)
                {
                    AkWwiseInitializationSettings initializationSettings = akInitializer.InitializationSettings;
                    if (((initializationSettings != null) ? initializationSettings.CallbackManagerInitializationSettings : null) != null)
                    {
                        if (!akInitializer.InitializationSettings.CallbackManagerInitializationSettings.IsLoggingEnabled)
                        {
                            return("0");
                        }
                        return("1");
                    }
                    else
                    {
                        Debug.Log("Cannot retrieve value. callbackManagerInitializationSettings is null.");
                    }
                }
                return("1");
            }
Exemplo n.º 22
0
        public DecodableBankHandle(string name, bool save) : base(name)
        {
            saveDecodedBank = save;

            var bankFileName = bankName + ".bnk";

            // test language-specific decoded file path
            var language = AkInitializer.GetCurrentLanguage();

            decodedBankPath = System.IO.Path.Combine(AkInitializer.GetDecodedBankFullPath(), language);
            var decodedBankFilePath = System.IO.Path.Combine(decodedBankPath, bankFileName);

            bool decodedFileExists = System.IO.File.Exists(decodedBankFilePath);

            if (!decodedFileExists)
            {
                // test non-language-specific decoded file path
                decodedBankPath     = AkInitializer.GetDecodedBankFullPath();
                decodedBankFilePath = System.IO.Path.Combine(decodedBankPath, bankFileName);
                decodedFileExists   = System.IO.File.Exists(decodedBankFilePath);
            }

            if (decodedFileExists)
            {
                try
                {
                    var decodedFileTime     = System.IO.File.GetLastWriteTime(decodedBankFilePath);
                    var defaultBankPath     = AkBasePathGetter.GetSoundbankBasePath();
                    var encodedBankFilePath = System.IO.Path.Combine(defaultBankPath, bankFileName);
                    var encodedFileTime     = System.IO.File.GetLastWriteTime(encodedBankFilePath);

                    decodeBank = (decodedFileTime <= encodedFileTime);
                }
                catch
                {
                    // Assume the decoded bank exists, but is not accessible. Re-decode it anyway, so we do nothing.
                }
            }
        }
Exemplo n.º 23
0
    private void Awake()
    {
        if (ms_Instance)
        {
            DestroyImmediate(this);
            return;
        }

        ms_Instance = this;

#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            return;
        }

                #if !(AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES)
        AkWwiseFileWatcher.Instance.XMLUpdated += AkBankManager.ReloadAllBanks;
                #endif
#endif

        DontDestroyOnLoad(this);
    }
Exemplo n.º 24
0
    public void SaveInitSettings(AkInitializer in_AkInit)
    {
        if (!AkWwisePicker.WwiseProjectFound)
        {
            return;
        }
        if (!CompareInitSettings(in_AkInit))
        {
#if UNITY_5_3_OR_NEWER
            Undo.RecordObject(this, "Save Init Settings");
#endif
            basePath              = in_AkInit.basePath;
            language              = in_AkInit.language;
            defaultPoolSize       = in_AkInit.defaultPoolSize;
            lowerPoolSize         = in_AkInit.lowerPoolSize;
            streamingPoolSize     = in_AkInit.streamingPoolSize;
            preparePoolSize       = in_AkInit.preparePoolSize;
            memoryCutoffThreshold = in_AkInit.memoryCutoffThreshold;
#if !UNITY_5_3_OR_NEWER
            EditorUtility.SetDirty(this);
#endif
        }
    }
Exemplo n.º 25
0
        public void Migrate(AkInitializer akInitializer)
        {
            if (hasMigrated)
            {
                return;
            }

            var initializationSettings = akInitializer.InitializationSettings;

            if (!initializationSettings)
            {
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
                initializationSettings = AkWwiseAddressablesInitializationSettings.Instance;
#else
                initializationSettings = AkWwiseInitializationSettings.Instance;
#endif
                if (!initializationSettings)
                {
                    return;
                }
            }

            initializationSettings.UserSettings.m_BasePath        = akInitializer.basePath;
            initializationSettings.UserSettings.m_StartupLanguage = akInitializer.language;

            initializationSettings.AdvancedSettings.m_MonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024;

            initializationSettings.UserSettings.m_SpatialAudioSettings.m_MaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth;

            initializationSettings.CallbackManagerInitializationSettings.IsLoggingEnabled = akInitializer.engineLogging;

            UnityEditor.EditorUtility.SetDirty(initializationSettings);
            UnityEditor.AssetDatabase.SaveAssets();

            UnityEngine.Debug.Log("WwiseUnity: Converted from AkInitializer to AkWwiseInitializationSettings.");
            hasMigrated = true;
        }
        public override void Awake()
        {
            if (!AkSoundEngine.IsInitialized())
            {
                //
                // Check to see if the AkInitializer is in the scene
                //
                AkInitializer initializer = GameObject.FindObjectOfType <AkInitializer>();

                if (initializer == null)
                {
                    mWwiseAvailable = false;
                    Debug.LogError("Trying to use Wwise NewtonVR collision sounds but no AkInitializer in scene");
                    return;
                }

                Debug.LogWarning("Wwise NewtonVR collision sounds framework awake but Wwise not yet initialised");
            }
            mWwiseAvailable = true;
            AudioPool       = new AkGameObj[NVRCollisionSoundController.Instance.SoundPoolSize];

            AudioSourcePrefab = Resources.Load <GameObject>(AudioSourcePrefabPath);

            for (int index = 0; index < AudioPool.Length; index++)
            {
                AudioPool[index] = GameObject.Instantiate <GameObject>(AudioSourcePrefab).GetComponent <AkGameObj>();
                AudioPool[index].transform.parent = this.transform;

                //
                // Disable the AkGameObjs until they are actually in use
                //
                AudioPool[index].gameObject.SetActive(false);
            }

            mImpactVolumeControlId = AkSoundEngine.GetIDFromString(kImpactVolumeControlName);
        }
Exemplo n.º 27
0
    static public void CheckWwiseGlobalExistance()
    {
        WwiseSettings settings = WwiseSettings.LoadSettings();

#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
        if (!settings.OldProject && (String.IsNullOrEmpty(EditorApplication.currentScene) || s_CurrentScene != EditorApplication.currentScene))
#else
        string activeSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;
        if (!settings.OldProject && s_CurrentScene != activeSceneName)
#endif
        {
            // Look for a game object which has the initializer component
            AkInitializer[] AkInitializers = UnityEngine.Object.FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[];
            if (AkInitializers.Length == 0)
            {
                if (settings.CreateWwiseGlobal == true)
                {
                    //No Wwise object in this scene, create one so that the sound engine is initialized and terminated properly even if the scenes are loaded
                    //in the wrong order.
                    GameObject objWwise = new GameObject("WwiseGlobal");

                    //Attach initializer and terminator components
                    AkInitializer init = objWwise.AddComponent <AkInitializer>();
                    AkWwiseProjectInfo.GetData().CopyInitSettings(init);
                }
            }
            else
            {
                if (settings.CreateWwiseGlobal == false && AkInitializers[0].gameObject.name == "WwiseGlobal")
                {
                    GameObject.DestroyImmediate(AkInitializers[0].gameObject);
                }
                //All scenes will share the same initializer.  So expose the init settings consistently across scenes.
                AkWwiseProjectInfo.GetData().CopyInitSettings(AkInitializers[0]);
            }

            AkAudioListener[] akAudioListeners = UnityEngine.Object.FindObjectsOfType(typeof(AkAudioListener)) as AkAudioListener[];
            if (akAudioListeners.Length == 0)
            {
                // Remove the audio listener script
                if (Camera.main != null && settings.CreateWwiseListener == true)
                {
                    AudioListener listener = Camera.main.gameObject.GetComponent <AudioListener>();
                    if (listener != null)
                    {
                        Component.DestroyImmediate(listener);
                    }

                    // Add the AkAudioListener script
                    if (Camera.main.gameObject.GetComponent <AkAudioListener>() == null)
                    {
                        Camera.main.gameObject.AddComponent <AkAudioListener>();
                    }
                }
            }
            else
            {
                foreach (AkAudioListener akListener in akAudioListeners)
                {
                    if (settings.CreateWwiseListener == false && akListener.gameObject == Camera.main.gameObject)
                    {
                        Component.DestroyImmediate(akListener);
                    }
                }
            }


#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            s_CurrentScene = EditorApplication.currentScene;
#else
            s_CurrentScene = activeSceneName;
#endif
        }
    }
Exemplo n.º 28
0
 void Awake()
 {
     AkSoundEngineController.OnAudioPluginInitialized += LaunchAppAudio;
     akInitComponent = gameObject.AddComponent <AkInitializer> ();
 }
 private void ClearInitializeState()
 {
     TheAkInitializer = null;
 }
    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 OnGUI()
    {
        // Make sure everything is initialized
        // Use soundbank path, because Wwise project path can be empty.
        if (String.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath) && WwiseSetupWizard.Settings.WwiseProjectPath == null)
        {
            WwiseSetupWizard.Settings = WwiseSettings.LoadSettings();
        }

        string initialProject = WwiseSetupWizard.Settings.WwiseProjectPath;

        if (VersionStyle == null)
        {
            InitGuiStyles();
        }
        GUILayout.Label(m_WwiseVersionString, VersionStyle);

        DrawSettingsPart();

        string newProject = WwiseSetupWizard.Settings.WwiseProjectPath;         // DrawSettingsPart modifies WwiseSetupWizard.Settings.WwiseProjectPath directly.

        if (initialProject != newProject)
        {
            ApplyNewProject = true;
        }

        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("OK", GUILayout.Width(60)))
        {
            if (string.IsNullOrEmpty(WwiseSetupWizard.Settings.SoundbankPath))
            {
                EditorUtility.DisplayDialog("Error", "Please fill in the required settings", "Ok");
            }

            if (AkWwiseSettingsWindow.m_oldCreateWwiseGlobal != WwiseSetupWizard.Settings.CreateWwiseGlobal)
            {
                AkInitializer[] AkInitializers = UnityEngine.Object.FindObjectsOfType(typeof(AkInitializer)) as AkInitializer[];
                if (WwiseSetupWizard.Settings.CreateWwiseGlobal == true)
                {
                    if (AkInitializers.Length == 0)
                    {
                        //No Wwise object in this scene, create one so that the sound engine is initialized and terminated properly even if the scenes are loaded
                        //in the wrong order.
                        GameObject objWwise = new GameObject("WwiseGlobal");

                        //Attach initializer and terminator components
                        AkInitializer init = objWwise.AddComponent <AkInitializer>();
                        AkWwiseProjectInfo.GetData().CopyInitSettings(init);
                    }
                }
                else
                {
                    if (AkInitializers.Length != 0 && AkInitializers[0].gameObject.name == "WwiseGlobal")
                    {
                        GameObject.DestroyImmediate(AkInitializers[0].gameObject);
                    }
                }
            }

            if (AkWwiseSettingsWindow.m_oldCreateWwiseListener != WwiseSetupWizard.Settings.CreateWwiseListener)
            {
                if (Camera.main != null)
                {
                    AkAudioListener akListener = Camera.main.GetComponentInChildren <AkAudioListener>();

                    if (WwiseSetupWizard.Settings.CreateWwiseListener)
                    {
                        if (akListener == null)
                        {
                            akListener = Undo.AddComponent <AkAudioListener>(Camera.main.gameObject);
                            AkGameObj akGameObj = akListener.GetComponentInChildren <AkGameObj>();
                            akGameObj.isEnvironmentAware = false;
                        }

                        // If Unity had already an audio listener, we want to remove it when adding our own.
                        AudioListener unityListener = Camera.main.GetComponentInChildren <AudioListener>();
                        if (unityListener != null)
                        {
                            Component.DestroyImmediate(unityListener);
                        }
                    }
                }
            }

            if (m_oldShowMissingRigidBodyWarning != WwiseSetupWizard.Settings.ShowMissingRigidBodyWarning)
            {
                InternalEditorUtility.RepaintAllViews();
            }

            WwiseSettings.SaveSettings(WwiseSetupWizard.Settings);

            CloseWindow();

            // Pop the Picker window so the user can start working right away
            AkWwiseProjectInfo.GetData();             // Load data
            if (ApplyNewProject)
            {
                //Clear the data, the project path changed.
                AkWwiseProjectInfo.GetData().Reset();
                ApplyNewProject = false;
                AkWwisePicker.WwiseProjectFound = true;
            }
            AkWwiseProjectInfo.Populate();
            AkWwisePicker.PopulateTreeview();
            AkWwisePicker.init();
        }

        if (GUILayout.Button("Cancel", GUILayout.Width(60)))
        {
            WwiseSetupWizard.Settings = WwiseSettings.LoadSettings(true);
            CloseWindow();
        }
        GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
        GUILayout.EndHorizontal();

        GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
        GUILayout.EndVertical();
    }
	private bool CompareInitSettings(AkInitializer in_AkInit)
	{
        return basePath == in_AkInit.basePath &&
            language == in_AkInit.language &&
            defaultPoolSize == in_AkInit.defaultPoolSize &&
            lowerPoolSize == in_AkInit.lowerPoolSize &&
            streamingPoolSize == in_AkInit.streamingPoolSize &&
            memoryCutoffThreshold == in_AkInit.memoryCutoffThreshold;
	}
	public void SaveInitSettings(AkInitializer in_AkInit)
	{
		if (!AkWwisePicker.WwiseProjectFound)
		{
			return;
		}
		if (!CompareInitSettings(in_AkInit))
		{
            basePath = in_AkInit.basePath;
			language =              in_AkInit.language;
			defaultPoolSize =       in_AkInit.defaultPoolSize;
			lowerPoolSize =         in_AkInit.lowerPoolSize;
			streamingPoolSize =     in_AkInit.streamingPoolSize;
            memoryCutoffThreshold = in_AkInit.memoryCutoffThreshold;
            EditorUtility.SetDirty(this);
		}
	}
Exemplo n.º 35
0
 public void SaveInitSettings(AkInitializer in_AkInit)
 {
     if (!CompareInitSettings(in_AkInit))
     {
         basePath = in_AkInit.basePath;
         language =              in_AkInit.language;
         defaultPoolSize =       in_AkInit.defaultPoolSize;
         lowerPoolSize =         in_AkInit.lowerPoolSize;
         streamingPoolSize =     in_AkInit.streamingPoolSize;
         memoryCutoffThreshold = in_AkInit.memoryCutoffThreshold;
         BankDestinationFolders = in_AkInit.BankDestinationFolders;
         EditorUtility.SetDirty(this);
     }
 }