NotSupportedException: To marshal a manged method, please add
an attribute named 'MonoPInvokeCallback' to the method definition
NotSupportedException: IL2CPP does not support marshaling
delegates that point to instance methods to native code.
出现原因
把自定义函数传递给 C++非托管代码
解决办法
- 定义特性
internal class MonoPInvokeCallbackAttribute : Attribute
{
public MonoPInvokeCallbackAttribute() { }
}
- 添加特性到 需要传递给c++的函数上面
[MonoPInvokeCallback]
internal static void OnResult( IntPtr param )
{
OnResultWithInfo( param, false, 0 );
}
例子 https://www.jianshu.com/p/f8ee0e02cdb2
找到的大神回答 https://garry.tv/2018/02/15/steamworks-and-il2cpp/