所以我有下面的結構如何在C#中統一使用C結構與二維數組
typedef struct mat4f_ { float m[4][4]; } mat4f;
它被作爲參數傳遞給我的API函數的一個通過一個C API:
void myFunction(const mat4f matrix);
[DllImport ("mylib")]
private static extern void myFunction(mat4f matrix);
我的問題是,我應該麥:
我在Unity使用DLL導出此函數C# e相應的C#結構是?
現在,我有以下幾點:
[StructLayout(LayoutKind.Sequential)]
public struct mat4f
{
public float[,] m;
}
與應用嘗試使用功能如下:
//Just make an identity matrix
mat4f matrix;
matrix.m = new float[4, 4] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
myFunction(matrix); //Call dll function
這是做正確的事嗎?有一個更好的方法嗎?