我听说Unity现在支持32位索引缓冲区.但是,当我尝试使用Unity 2018.1时,我无法使其工作.
我用这样的代码构建了网格:
int nVertices = nx * ny;
Vector3[] vertices = new Vector3[nVertices];
Color[] colors = new Color[nVertices];
for(int i = 0; i < nx; i++) {
float x = i * w / (nx - 1);
for (int j = 0; j < ny; j++) {
float y = j * h / (ny - 1);
int vindex = i * ny + j;
vertices[vindex] = new Vector3(x, y, 0);
float colorx = Mathf.Sin(x) / 2 + 0.5f; …
Run Code Online (Sandbox Code Playgroud) 我知道第一组关键字in, out, ref
可以在所有 C# 函数中使用,第二组属性[In], [Out], [In, Out]
用于 marshaller。
我不确定它们在本机代码的函数声明中使用时是否表示相同的意思。例如,以下两个声明是否等效?
[DllImport("xxx.dll")]
void FillArray1(ref int[] arr, in int length);
[DllImport("xxx.dll")]
void FillArray2([In, Out] int[] arr, [In] int length);
Run Code Online (Sandbox Code Playgroud)
是否存在两个集合不等价的情况?
Marshal.Copy()
方法仅支持几种数组类型。现在我只知道如何从IntPtr
(指向C ++代码中的float数组)复制到float[]
。
IntPtr pvertices = GetVerticesFromCPP();
float[] vertices = new float[nVertices * 3];
Marshal.Copy(pvertices, vertices, 0, nVertices * 3);
Run Code Online (Sandbox Code Playgroud)
但是我真正想要的是一个UnityEngine.Vector3[]
。
我需要手动转换float[]
为UnityEngine.Vector3[]
吗?还是有一种更简单,更快捷的方法直接做到这一点?