如何导出c++;用模板编码到Unity? 最近我一直尝试在DLL上向UNITY 3D导出一些C++代码,到目前为止它一直都很好!但是,总是有一个但是,现在我需要导出一个包含模板的代码,这似乎让Unity感到不安,因为它会立即向我显示EntryPointNotFoundException错误消息。我在谷歌上搜索了一下,没有找到太多关于这方面的信息。是否可以通过DLL将C++模板类导出到Unity?怎么做
这是.h代码:如何导出c++;用模板编码到Unity? 最近我一直尝试在DLL上向UNITY 3D导出一些C++代码,到目前为止它一直都很好!但是,总是有一个但是,现在我需要导出一个包含模板的代码,这似乎让Unity感到不安,因为它会立即向我显示EntryPointNotFoundException错误消息。我在谷歌上搜索了一下,没有找到太多关于这方面的信息。是否可以通过DLL将C++模板类导出到Unity?怎么做,c++,templates,dll,unity3d,extern,C++,Templates,Dll,Unity3d,Extern,这是.h代码: #define EXPORT __declspec (dllexport) extern "C++" { void __declspec(dllexport) computeMinBox3D(int numPoints, void* points, float epsilon, void* resultPoints); } 这是.cpp代码: template <typename Real> void computeMinBox3DAux( int num
#define EXPORT __declspec (dllexport)
extern "C++"
{
void __declspec(dllexport) computeMinBox3D(int numPoints, void* points, float epsilon, void* resultPoints);
}
这是.cpp代码:
template <typename Real>
void computeMinBox3DAux( int numPoints, void* points, float epsilon, void* resultPoints )
{
//...
}
模板
void computeMinBox3DAux(整数点、void*点、浮点ε、void*结果点)
{
//...
}
这是我在Unity使用的代码:
[DllImport("MinOBB_DLL.dll")]
private static extern void computeMinBox3D(int numPoints, IntPtr points, float epsilon, IntPtr resultPoints);
public void createOBB()
{
int numPoints = 9;
float[] points = new float[numPoints];
float[] resultPoints = new float[24];
Vector3[] result3DPoints = new Vector3[8];
float r = 1.0f;
for ( int i = 0; i < points.Length; i++ )
{
points[i] = UnityEngine.Random.Range(-r, r);
}
int rangesArraySize = Marshal.SizeOf(typeof(float))* numPoints;
IntPtr pointVec = Marshal.AllocHGlobal( rangesArraySize );
Marshal.Copy (points, 0, pointVec, numPoints);
int resultArraySize = Marshal.SizeOf(typeof(float))* 24;
IntPtr resultVec = Marshal.AllocHGlobal( resultArraySize );
computeMinBox3D( numPoints, pointVec, 0.01f, resultVec );
}
[DllImport(“MinOBB_DLL.DLL”)]
私有静态外部void computeMinBox3D(int numPoints、IntPtr points、float epsilon、IntPtr resultPoints);
public void createOBB()
{
int numPoints=9;
float[]点=新的float[numPoints];
float[]结果点=新的float[24];
Vector3[]result3DPoints=新Vector3[8];
浮球r=1.0f;
对于(int i=0;i
谢谢你抽出时间 也许您必须显式地实例化它?使用C代码只能跨越单/本机边界。没有C++允许链接,我想你是对的。我找不到一种方法来使用C++来进行轻松链接,所以我最终没有导出这个方法。