unity3d import c++ dll for pass by reference 方法

unity3d import c++ dll for pass by reference method

我想在 Unity3d 中使用 C++ 代码。通常,没关系,我可以通过导入 dll 来完成。我想了解的是是否可以使用 C++ 方法参数作为引用传递?

我想做的是获取 C++ 代码返回的 uchar* 数组的大小。

What i'm trying to learn is whether using C++ method parameters as pass by reference is possible or not?

是的,这是可能的。在 C++ 端使用 int*,在 C# 端使用 ref int。您应该能够从 C++ 写入该参数,它将在 C# 端更新。

有关完整示例,请参阅我的另一个 post 的 回答。

What i'm trying to do is getting size of uchar* array returned by c++ code.

你可以用上面的例子。如果您关心性能,请不要使用 C++ 中的 return 数组。在 C# 中创建数组,然后将其传递给 C++ 并在那里进行修改。有关信息,请参阅链接的答案。