我尝试使用Unity3D中的.bundle文件中的函数,但每次调用函数时都会出现错误:
DllNotFoundException: libant
connectANT.Start () (at Assets/connectANT.cs:13)
这是我用来调用资源/插件文件夹中的库antlib.bundle的脚本:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class connectANT : MonoBehaviour {
[DllImport("libant")] static extern bool ANT_Init(int ucUSBDeviceNum_, int ulBaudrate_);
void Start () {
ANT_Init (1, 50000);
}
}
在bundle中,这个函数声明如下:
#ifdef __cplusplus
extern "C" {
#endif
EXPORT BOOL ANT_Init(UCHAR ucUSBDeviceNum_, ULONG ulBaudrate_); //Initializes and opens USB connection to the module
#ifdef __cplusplus
}
#endif
这只是捆绑中只有一个函数的示例 . 如果我只是在我的脚本中导入函数,我在Unity中没有任何错误 . 有人可以帮我搞清楚吗?
2 回答
试试这个:
您的代码中存在两个问题:
文件名错误
错误的参数类型和返回类型
如果要将bool用作返回类型,则需要另一个属性:
山姆是对的,你的回报 Value 和论据必须匹配 . 另外,请确保捆绑包含info.plist,如下所示:
您的包名称和库名称不必匹配,但您的plist需要通过指向正确的lib来解决此问题 .