如何在 Unity 中使用 Xaudio2 和 ill2cpp

how can use Xaudio2 in Unity with ill2cpp

提问人:MOGI 提问时间:2/23/2023 最后编辑:Simon MourierMOGI 更新时间:2/23/2023 访问量:53

问:

我在Unity3D中使用SharpDx.dll和SharpDx.XAudio2.dll。

dll在编辑器中工作正常。但是,当我在构建 Windows 后运行程序时,初始化部分发生错误。错误日志如下,并附上部分源代码。

那个dll不能在Windows基础上运行吗?如果没有,有什么解决方法吗?

    using UnityEngine;
    using SharpDX.Multimedia;
    using SharpDX.XAudio2;
    using System.IO;
    using System;
    
    XAudio2 xaudio2;
    MasteringVoice masteringVoice;
    
    void Start()
    {
       xaudio2 = new XAudio2(); << Error
       masteringVoice = new MasteringVoice(xaudio2);
    }


NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: SharpDX.XAudio2.EngineShadow+EngineVtbl::OnProcessingPassStartImpl
  at System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate (System.Delegate d) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.CppObjectVtbl.AddMethod (System.Delegate method) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.EngineShadow+EngineVtbl..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.EngineShadow..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.XAudio2..ctor (SharpDX.XAudio2.XAudio2Flags flags, SharpDX.XAudio2.ProcessorSpecifier processorSpecifier, SharpDX.XAudio2.XAudio2Version requestedVersion) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.XAudio2..ctor (SharpDX.XAudio2.XAudio2Version requestedVersion) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.XAudio2..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at DirectWav.Start () [0x00002] in C:\Develop\WJMAX\Assets\Scripts\Common\DirectWav.cs:23 
Rethrow as TypeInitializationException: The type initializer for 'SharpDX.XAudio2.EngineShadow' threw an exception.
  at SharpDX.XAudio2.XAudio2..ctor (SharpDX.XAudio2.XAudio2Flags flags, SharpDX.XAudio2.ProcessorSpecifier processorSpecifier, SharpDX.XAudio2.XAudio2Version requestedVersion) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.XAudio2..ctor (SharpDX.XAudio2.XAudio2Version requestedVersion) [0x00000] in <00000000000000000000000000000000>:0 
  at SharpDX.XAudio2.XAudio2..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at DirectWav.Start () [0x00002] in C:\Develop\WJMAX\Assets\Scripts\Common\DirectWav.cs:23 

unity-游戏引擎 sharpdx il2cpp

评论

0赞 TheNomad 2/24/2023
一个简单的谷歌搜索给我带来了这个结果:forum.unity.com/threads/......

答: 暂无答案