-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSwiftPmPlugin.cs
98 lines (77 loc) · 2.8 KB
/
SwiftPmPlugin.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using AOT;
using System;
using System.Runtime.InteropServices;
#if !UNITY_EDITOR && UNITY_IOS
using UnityEngine;
#endif
public static class SwiftPmPlugin
{
#if UNITY_EDITOR_OSX
private const string libName = "MacOsSwiftPmPlugin";
#elif UNITY_IOS
private const string libName = "__Internal";
#endif
// ------------------------------------------------------------------
// Functions for iOS & macOS
// ------------------------------------------------------------------
[DllImport(libName)]
private static extern long swiftPmPlugin_toNumber(string stringNumber);
/// <summary>
/// Convert string to long
/// </summary>
public static long ToNumber(string stringNumber)
{
return swiftPmPlugin_toNumber(stringNumber);
}
// ------------------------------------------------------------------
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void swiftPmPlugin_callBackType([MarshalAs(UnmanagedType.LPStr), In] string message);
[DllImport(libName)]
private static extern void swiftPmPlugin_callBack([MarshalAs(UnmanagedType.FunctionPtr)] swiftPmPlugin_callBackType callback);
[MonoPInvokeCallback(typeof(swiftPmPlugin_callBackType))]
private static void swiftPmPlugin_callBackHandler(string message)
{
CallBackAction(message);
}
/// <summary>
/// Action on CallBack function
/// </summary>
public static event Action<string> CallBackAction;
/// <summary>
/// CallBack
/// </summary>
public static void CallBack()
{
swiftPmPlugin_callBack(swiftPmPlugin_callBackHandler);
}
// ------------------------------------------------------------------
// Functions for iOS
// ------------------------------------------------------------------
#if !UNITY_EDITOR && UNITY_IOS
// ------------------------------------------------------------------
[DllImport("__Internal")]
private static extern void swiftPmPlugin_callSendMessage();
/// <summary>
/// Send Message Object: "Cube", Method: "Sent", Arg: "from send message"
/// </summary>
public static void CallSendMessage()
{
swiftPmPlugin_callSendMessage();
}
// ------------------------------------------------------------------
[DllImport("__Internal")]
private static extern void swiftPmPlugin_saveImage(IntPtr mtlTexture);
public static void SaveImage(Texture texture)
{
swiftPmPlugin_saveImage(texture.GetNativeTexturePtr());
}
// ------------------------------------------------------------------
[DllImport("__Internal")]
private static extern void swiftPmPlugin_presentVc();
public static void PresentVc()
{
swiftPmPlugin_presentVc();
}
// ------------------------------------------------------------------
#endif
}