IsInitialized() публичный статический Метод

public static IsInitialized ( ) : bool
Результат bool
Пример #1
0
    private void OnDestroy()
    {
#if UNITY_EDITOR
        if (!AkSoundEngineController.Instance.IsSoundEngineLoaded || AkUtilities.IsMigrating)
        {
            return;
        }

        if (!UnityEditor.EditorApplication.isPlaying)
        {
            UnityEditor.EditorApplication.update -= CheckStaticStatus;
        }
#endif

        // We can't do the code in OnDestroy if the gameObj is unregistered, so do it now.
        var eventHandlers = gameObject.GetComponents <AkTriggerHandler>();
        foreach (var handler in eventHandlers)
        {
            if (handler.triggerList.Contains(AkTriggerHandler.DESTROY_TRIGGER_ID))
            {
                handler.DoDestroy();
            }
        }

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

        if (AkSoundEngine.IsInitialized())
        {
            AkSoundEngine.UnregisterGameObj(gameObject);
        }
    }
Пример #2
0
    void OnDestroy()
    {
#if !DISABLE_AKSOUNDENGINE
#if UNITY_EDITOR
        if (AkMigrating.IsMigrating)
        {
            return;
        }

        if (!UnityEditor.EditorApplication.isPlaying)
        {
            UnityEditor.EditorApplication.update -= this.CheckStaticStatus;
        }
#endif

        // We can't do the code in OnDestroy if the gameObj is unregistered, so do it now.
        AkUnityEventHandler[] eventHandlers = gameObject.GetComponents <AkUnityEventHandler>();
        foreach (AkUnityEventHandler handler in eventHandlers)
        {
            if (handler.triggerList.Contains(AkUnityEventHandler.DESTROY_TRIGGER_ID))
            {
                handler.DoDestroy();
            }
        }

#if UNITY_EDITOR
        if (UnityEditor.EditorApplication.isPlaying)
#endif
        {
            if (AkSoundEngine.IsInitialized())
            {
                AkSoundEngine.UnregisterGameObj(gameObject);
            }
        }
#endif
    }
Пример #3
0
        public AKRESULT Initialize()
        {
            if (IsInitialized)
            {
                return(AKRESULT.AK_Success);
            }
            if (!AkSoundEngine.IsInitialized())
            {
                return(AKRESULT.AK_Fail);
            }
            string[] assetNames = AudioUtil.GetBankAssetNamesByFolder(null);
            foreach (string bankName in assetNames)
            {
                if (bankName.StartsWith("Hall_") || bankName.StartsWith("Map_"))
                {
                    continue;
                }
                AKBankAtom atom = bankAtomSet.Register(bankName, AudioBank_LoadMode.Aync);
                bankAtomSet.DoLoadBank(atom);
            }

            IsInitialized = true;
            return(AKRESULT.AK_Success);
        }
    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
    }
Пример #5
0
    /// <summary>
    ///     Sends the mesh filter's triangles and their acoustic texture to Spatial Audio
    /// </summary>
    /// <param name="acousticTexture"></param>
    /// <param name="meshFilter"></param>
    public static void AddGeometrySet(AK.Wwise.AcousticTexture acousticTexture, UnityEngine.MeshFilter meshFilter, ulong roomID, bool enableDiffraction, bool enableDiffractionOnBoundaryEdges)
    {
        if (!AkSoundEngine.IsInitialized())
        {
            return;
        }

        if (meshFilter == null)
        {
            UnityEngine.Debug.Log("AddGeometrySet(): No mesh found!");
        }
        else
        {
            var mesh      = meshFilter.sharedMesh;
            var vertices  = mesh.vertices;
            var triangles = mesh.triangles;

            // Remove duplicate vertices
            var vertRemap   = new int[vertices.Length];
            var uniqueVerts = new System.Collections.Generic.List <UnityEngine.Vector3>();
            var vertDict    = new System.Collections.Generic.Dictionary <UnityEngine.Vector3, int>();

            for (var v = 0; v < vertices.Length; ++v)
            {
                int vertIdx = 0;
                if (!vertDict.TryGetValue(vertices[v], out vertIdx))
                {
                    vertIdx = uniqueVerts.Count;
                    uniqueVerts.Add(vertices[v]);
                    vertDict.Add(vertices[v], vertIdx);
                }
                vertRemap[v] = vertIdx;
            }

            int vertexCount = uniqueVerts.Count;

            using (var surfaceArray = new AkAcousticSurfaceArray(1))
            {
                var surface = surfaceArray[0];
                surface.textureID            = acousticTexture.Id;
                surface.reflectorChannelMask = unchecked ((uint)-1);
                surface.strName = meshFilter.gameObject.name;

                using (var vertexArray = new AkVertexArray(vertexCount))
                {
                    for (var v = 0; v < vertexCount; ++v)
                    {
                        var point = meshFilter.transform.TransformPoint(uniqueVerts[v]);
                        using (var akVert = vertexArray[v])
                        {
                            akVert.X = point.x;
                            akVert.Y = point.y;
                            akVert.Z = point.z;
                        }
                    }

                    var numTriangles = mesh.triangles.Length / 3;
                    using (var triangleArray = new AkTriangleArray(numTriangles))
                    {
                        for (var i = 0; i < numTriangles; ++i)
                        {
                            using (var triangle = triangleArray[i])
                            {
                                triangle.point0  = (ushort)vertRemap[triangles[3 * i + 0]];
                                triangle.point1  = (ushort)vertRemap[triangles[3 * i + 1]];
                                triangle.point2  = (ushort)vertRemap[triangles[3 * i + 2]];
                                triangle.surface = (ushort)0;
                            }
                        }

                        AkSoundEngine.SetGeometry(GetAkGeometrySetID(meshFilter), triangleArray, (uint)triangleArray.Count(), vertexArray, (uint)vertexArray.Count(), surfaceArray, (uint)surfaceArray.Count(), roomID, enableDiffraction, enableDiffractionOnBoundaryEdges);
                    }
                }
            }
        }
    }
    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
    }
Пример #7
0
    static public void PostCallbacks()
    {
        if (!AkSoundEngine.IsInitialized())
        {
            return;
        }


        if (m_pNotifMem == IntPtr.Zero)
        {
            return;
        }

        IntPtr pData = AkCallbackSerializer.Lock();

        if (pData == IntPtr.Zero)
        {
            AkCallbackSerializer.Unlock();
            return;
        }

        AkCommonCallback commonCB;

        commonCB.eType    = 0;
        commonCB.pPackage = IntPtr.Zero;
        commonCB.pNext    = IntPtr.Zero;

        IntPtr callbacksStart = pData;

        commonCB = new AkCommonCallback();

        commonCB.pPackage = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.pNext = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
        GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

        EventCallbackPackage eventPkg = null;
        BankCallbackPackage  bankPkg  = null;

        if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
        {
            AkCallbackSerializer.Unlock();
            return;
        }

        pData = callbacksStart;

        do
        {
            // Point to start of the next callback after commonCallback.
            pData = (IntPtr)(pData.ToInt64() + Marshal.SizeOf(typeof(AkCommonCallback)));

            if (commonCB.eType == AkCallbackType.AK_Monitoring)
            {
                AkMonitoringMsg monitorMsg = new AkMonitoringMsg();

                monitorMsg.errorCode = (ErrorCode)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <ErrorCode>(ref pData);

                monitorMsg.errorLevel = (ErrorLevel)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <ErrorLevel>(ref pData);

                monitorMsg.playingID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                monitorMsg.gameObjID = (IntPtr)Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_IntPtr(ref pData);

                // C# implementation of the struct does not include the tail string member, so as we skip sizes, pData is now at the actual start of the string member.
                monitorMsg.msg = SafeMarshalString(pData);
                if (m_MonitoringCB != null)
                {
                    m_MonitoringCB(monitorMsg.errorCode, monitorMsg.errorLevel, monitorMsg.playingID, monitorMsg.gameObjID, monitorMsg.msg);
                }
                else
                {
#if UNITY_EDITOR
                    string msg = "Wwise: " + monitorMsg.msg;
                    if (monitorMsg.gameObjID != (IntPtr)AkSoundEngine.AK_INVALID_GAME_OBJECT)
                    {
                        GameObject obj  = EditorUtility.InstanceIDToObject((int)monitorMsg.gameObjID) as GameObject;
                        string     name = obj != null?obj.ToString() : monitorMsg.gameObjID.ToString();

                        msg += "(Object: " + name + ")";
                    }

                    if (monitorMsg.errorLevel == ErrorLevel.ErrorLevel_Error)
                    {
                        Debug.LogError(msg);
                    }
                    else
                    {
                        Debug.Log(msg);
                    }
#endif
                }
            }
            else if (commonCB.eType == AkCallbackType.AK_Bank)
            {
                AkBankInfo bankCB = new AkBankInfo();

                bankCB.bankID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                bankCB.inMemoryBankPtr = Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_ValueType <IntPtr>(ref pData);

                bankCB.eLoadResult = (AKRESULT)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pData);

                bankCB.memPoolId = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                if (bankPkg != null)
                {
                    bankPkg.m_Callback(bankCB.bankID, bankCB.inMemoryBankPtr, bankCB.eLoadResult, bankCB.memPoolId, bankPkg.m_Cookie);
                }
            }
#if UNITY_IOS && !UNITY_EDITOR
            else if (commonCB.eType == AkCallbackType.AK_AudioInterruption)
            {
                AkAudioInterruptionInfo cbInfo = new AkAudioInterruptionInfo();

                cbInfo.bEnterInterruption = Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <Int32>(ref pData);

                cbInfo.prevEngineStepResult = (AKRESULT)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pData);

                ms_interruptCallbackPkg.m_Callback(cbInfo.bEnterInterruption, cbInfo.prevEngineStepResult, ms_interruptCallbackPkg.m_Cookie);
            }
#endif // #if UNITY_IOS && ! UNITY_EDITOR
            else
            {
                //Get the other parameters
                switch (commonCB.eType)
                {
                case AkCallbackType.AK_EndOfEvent:
                    AkEventCallbackInfo eventCB = new AkEventCallbackInfo();

                    eventCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, eventCB);
                    break;

                case AkCallbackType.AK_EndOfDynamicSequenceItem:
                    AkDynamicSequenceItemCallbackInfo dynSeqInfoCB = new AkDynamicSequenceItemCallbackInfo();

                    dynSeqInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    dynSeqInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.pCustomInfo = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, dynSeqInfoCB);
                    break;

                case AkCallbackType.AK_Marker:
                    AkMarkerCallbackInfo markerInfo = new AkMarkerCallbackInfo();

                    markerInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uIdentifier = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uPosition = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.strLabel = SafeMarshalMarkerString(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, markerInfo);
                    break;

                case AkCallbackType.AK_Duration:
                    AkDurationCallbackInfo durInfoCB = new AkDurationCallbackInfo();

                    durInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.fDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.fEstimatedDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, durInfoCB);
                    break;

                case AkCallbackType.AK_MusicSyncUserCue:
                case AkCallbackType.AK_MusicPlayStarted:
                case AkCallbackType.AK_MusicSyncBar:
                case AkCallbackType.AK_MusicSyncBeat:
                case AkCallbackType.AK_MusicSyncEntry:
                case AkCallbackType.AK_MusicSyncExit:
                case AkCallbackType.AK_MusicSyncGrid:
                case AkCallbackType.AK_MusicSyncPoint:
                    AkMusicSyncCallbackInfo pInfo = new AkMusicSyncCallbackInfo();

                    pInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    pInfo.musicSyncType = (AkCallbackType)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

                    pInfo.fBeatDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fBarDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fGridDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fGridOffset = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    // WG-22334: User cues are always ANSI char*.
                    pInfo.pszUserCueName = Marshal.PtrToStringAnsi(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, pInfo);
                    break;

                default:
                    string log = string.Format("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type found. Callback object possiblly corrupted.");
                    Log.d(log);
                    AkCallbackSerializer.Unlock();
                    return;
                }
                ;
            }

            if (commonCB.pNext == IntPtr.Zero)
            {
                break;
            }

            // Note: At the end of each callback case above, pData points to either end of the callback struct, or right before the tail string member of the struct.
            pData = commonCB.pNext;

            callbacksStart = pData;

            commonCB = new AkCommonCallback();

            commonCB.pPackage = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.pNext = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
            GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

            eventPkg = null;
            bankPkg  = null;

            if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
            {
                AkCallbackSerializer.Unlock();
                return;
            }

            pData = callbacksStart;
        } while (true);

        AkCallbackSerializer.Unlock();
    }
Пример #8
0
    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
        bool 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;
            }
#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)
    {
        // Only initialize the room mamanger during play.
        bool initRoomManager = true;

#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            initRoomManager = false;
        }
#endif
        if (initRoomManager)
        {
            AkRoomManager.Init();
        }

        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();
            AkSoundEngine.EditorIsSoundEngineLoaded = true;
        }
        catch (System.DllNotFoundException)
        {
            AkSoundEngine.EditorIsSoundEngineLoaded = 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 (GetInitSettingsInstance().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 (!GetInitSettingsInstance().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)
        {
#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
    }