Created
December 1, 2017 09:08
-
-
Save romanus/e39d15f7b6559327242de61711065d65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The interop signature in the Unity script. | |
[DllImport("mypluginname")] | |
private static extern bool getSomeArrayData(ref IntPtr ptrResultVerts, ref int resultVertLength); | |
// An example of calling the interop function. | |
public MyMarshallingMethod() | |
{ | |
IntPtr ptrResultVerts = IntPtr.Zero; | |
int resultVertLength = 0; | |
bool success = getSomeArrayData(ref ptrResultVerts, ref resultVertLength) | |
float[] resultVertices = null; | |
if (success) | |
{ | |
// Load the results into a managed array. | |
resultVertices = new float[resultVertLength]; | |
Marshal.Copy(ptrResultVerts | |
, resultVertices | |
, 0 | |
, resultVertLength); | |
/* | |
* WARNING!!!! IMPORTANT!!! | |
* In this example the plugin created an array allocated | |
* in unmanged memory. The plugin will need to provide a | |
* means to free the memory. | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment