-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestImportCPPClass.cs
37 lines (31 loc) · 1.08 KB
/
TestImportCPPClass.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Runtime.InteropServices;
using UnityEngine;
public class TestImportCPPClass : MonoBehaviour
{
[DllImport("TestExportCPPClass")]
public static extern IntPtr Student_Create();
[DllImport("TestExportCPPClass")]
public static extern void Student_SetScore(IntPtr value, int score);
[DllImport("TestExportCPPClass")]
public static extern int Student_GetGrade(IntPtr value);
[DllImport("TestExportCPPClass")]
public static extern void Student_Delete(IntPtr value);
void Start()
{
int[] scores = {20, 40, 50, 56, 60, 75, 85, 100};
IntPtr[] students = new IntPtr[scores.Length];
for (int i = 0; i < students.Length; i++)
{
int score = scores[i];
students[i] = Student_Create();
Student_SetScore(students[i], score);
}
for (int i = 0; i < students.Length; i++)
{
int grade = Student_GetGrade(students[i]);
Debug.Log("Score: " + scores[i] + " Grade: " + grade);
Student_Delete(students[i]);
}
}
}