|
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Runtime.InteropServices; |
5 | 5 | using UnityEngine; |
6 | | -public class iOSNative |
| 6 | + public static class iOSNative |
7 | 7 | { |
| 8 | + public static class iCloudKeyValueStore |
| 9 | + { |
8 | 10 | #if UNITY_IOS && !UNITY_EDITOR |
9 | | - [DllImport("__Internal")] |
10 | | - private static extern void _initialize(); |
11 | | - |
12 | | - [DllImport("__Internal")] |
13 | | - private static extern void _ShowTempAlert(string alertString, int duration = 5); |
14 | | - |
15 | | - [DllImport("__Internal")] |
16 | | - private static extern void _PushNotification(string msg, string title, string identifier, int delay); |
17 | | - |
18 | | - [DllImport("__Internal")] |
19 | | - private static extern void _RemovePendingNotifications(string identifier); |
20 | | - |
21 | | - [DllImport("__Internal")] |
22 | | - private static extern void _RemoveAllPendingNotifications(); |
23 | | - |
24 | | - |
25 | | - [DllImport("__Internal")] |
26 | | - private static extern bool _Synchronize(); |
27 | | - |
28 | | - [DllImport("__Internal")] |
29 | | - private static extern void _PlayHaptics(int style, float intensity);//0 = Light, 1=Medium, 2=Heavy |
| 11 | + [DllImport("__Internal")] |
| 12 | + private static extern bool _Synchronize(); |
30 | 13 |
|
31 | | - [DllImport("__Internal")] |
32 | | - private static extern void _Share(string message, string url, string imagePath); |
| 14 | + [DllImport("__Internal")] |
| 15 | + private static extern bool _IsICloudAvailable(); |
33 | 16 |
|
34 | | - [DllImport("__Internal")] |
35 | | - private static extern bool _IsICloudAvailable(); |
| 17 | + [DllImport("__Internal")] |
| 18 | + private static extern bool _ClearICloudSave(); |
36 | 19 |
|
37 | | - [DllImport("__Internal")] |
38 | | - private static extern bool _ClearICloudSave(); |
| 20 | + [DllImport("__Internal")] |
| 21 | + private static extern string _iCloudGetString(string key, string defaultValue); |
39 | 22 |
|
40 | | - [DllImport("__Internal")] |
41 | | - private static extern string _iCloudGetString(string key, string defaultValue); |
| 23 | + [DllImport("__Internal")] |
| 24 | + private static extern bool _iCloudSaveString(string key, string value); |
42 | 25 |
|
43 | | - [DllImport("__Internal")] |
44 | | - private static extern bool _iCloudSaveString(string key, string value); |
| 26 | + [DllImport("__Internal")] |
| 27 | + private static extern int _iCloudGetInt(string key, int defaultValue); |
45 | 28 |
|
46 | | - [DllImport("__Internal")] |
47 | | - private static extern int _iCloudGetInt(string key, int defaultValue); |
| 29 | + [DllImport("__Internal")] |
| 30 | + private static extern bool _iCloudSaveInt(string key, int value); |
48 | 31 |
|
49 | | - [DllImport("__Internal")] |
50 | | - private static extern bool _iCloudSaveInt(string key, int value); |
| 32 | + [DllImport("__Internal")] |
| 33 | + private static extern float _iCloudGetFloat(string key, float defaultValue); |
51 | 34 |
|
52 | | - [DllImport("__Internal")] |
53 | | - private static extern float _iCloudGetFloat(string key, float defaultValue); |
| 35 | + [DllImport("__Internal")] |
| 36 | + private static extern bool _iCloudSaveFloat(string key, float value); |
54 | 37 |
|
55 | | - [DllImport("__Internal")] |
56 | | - private static extern bool _iCloudSaveFloat(string key, float value); |
57 | | - |
58 | | - [DllImport("__Internal")] |
59 | | - private static extern bool _iCloudGetBool(string key, bool defaultValue); |
| 38 | + [DllImport("__Internal")] |
| 39 | + private static extern bool _iCloudGetBool(string key, bool defaultValue); |
60 | 40 |
|
61 | | - [DllImport("__Internal")] |
62 | | - private static extern bool _iCloudSaveBool(string key, bool value); |
| 41 | + [DllImport("__Internal")] |
| 42 | + private static extern bool _iCloudSaveBool(string key, bool value); |
63 | 43 | #endif |
64 | | - public static void Initialize() |
65 | | - { |
66 | | -#if UNITY_IOS && !UNITY_EDITOR |
67 | | - _initialize(); |
68 | | -#endif |
69 | | - } |
70 | | - |
71 | | - public static void ShowTempAlert(string alertString, int duration = 5) |
72 | | - { |
73 | | -#if UNITY_IOS && !UNITY_EDITOR |
74 | | - _ShowTempAlert(alertString, duration); |
75 | | -#endif |
76 | | - } |
77 | | - |
78 | | - public static bool Synchronize() |
79 | | - { |
80 | | -#if UNITY_IOS && !UNITY_EDITOR |
81 | | - return _Synchronize(); |
82 | | -#else |
83 | | - return default(bool); |
84 | | -#endif |
85 | | - } |
86 | | - public static bool IsICloudAvailable() |
87 | | - { |
| 44 | + public static bool IsICloudAvailable() |
| 45 | + { |
88 | 46 | #if UNITY_IOS && !UNITY_EDITOR |
89 | 47 | return _IsICloudAvailable(); |
90 | 48 | #else |
91 | | - return default(bool); |
| 49 | + return false; |
92 | 50 | #endif |
93 | | - } |
94 | | - /// <summary> |
95 | | - /// PlayHaptics |
96 | | - /// </summary> |
97 | | - /// <param name="style">0 = Light, 1=Medium, 2=Heavy</param> |
98 | | - /// <param name="intensity">Intensity 0.0 - 1.0</param> |
99 | | - public static void PlayHaptics(int style, float intensity)//0 = Light, 1=Medium, 2=Heavy; Intensity 0.0 - 1.0 |
100 | | - { |
| 51 | + } |
| 52 | + public static bool Synchronize() |
| 53 | + { |
101 | 54 | #if UNITY_IOS && !UNITY_EDITOR |
102 | | - _PlayHaptics(style, intensity); |
103 | | -#endif |
104 | | - } |
105 | | - |
106 | | - |
107 | | - public static void Share(string message, string url = "", string imagePath = "", Action closeCallback = null) |
108 | | - { |
109 | | -#if UNITY_IOS && !UNITY_EDITOR |
110 | | - _Share(message, url, imagePath); |
111 | | -#endif |
112 | | - iOSCallbackHelper.INSTANCE.SetShareCloseCallback(closeCallback); |
113 | | - } |
114 | | - public static void PushNotification(string msg, string title, string identifier, int delay) |
115 | | - { |
116 | | -#if UNITY_IOS && !UNITY_EDITOR |
117 | | - _PushNotification(msg, title, identifier, delay); |
118 | | -#endif |
119 | | - } |
120 | | - public static void RemovePendingNotifications(string identifier) |
121 | | - { |
122 | | -#if UNITY_IOS && !UNITY_EDITOR |
123 | | - _RemovePendingNotifications(identifier); |
124 | | -#endif |
125 | | - } |
126 | | - public static void RemoveAllPendingNotifications() |
127 | | - { |
128 | | -#if UNITY_IOS && !UNITY_EDITOR |
129 | | - _RemoveAllPendingNotifications(); |
| 55 | + return _Synchronize(); |
| 56 | +#else |
| 57 | + return false; |
130 | 58 | #endif |
131 | | - } |
132 | | - |
133 | | - |
134 | | - |
135 | | - |
136 | | - |
137 | | - public static bool ClearICloudSave() |
138 | | - { |
| 59 | + } |
| 60 | + public static bool ClearICloudSave() |
| 61 | + { |
139 | 62 | #if UNITY_IOS && !UNITY_EDITOR |
140 | 63 | return _ClearICloudSave(); |
141 | 64 | #else |
142 | | - return default(bool); |
| 65 | + return default(bool); |
143 | 66 | #endif |
144 | | - } |
| 67 | + } |
145 | 68 |
|
146 | | - public static string iCloudGetStringValue(string key, string defaultValue) |
147 | | - { |
| 69 | + public static string iCloudGetStringValue(string key, string defaultValue) |
| 70 | + { |
148 | 71 | #if UNITY_IOS && !UNITY_EDITOR |
149 | 72 | return _iCloudGetString(key, defaultValue); |
150 | 73 | #else |
151 | | - return default(string); |
| 74 | + return string.Empty; |
152 | 75 | #endif |
153 | | - } |
| 76 | + } |
154 | 77 |
|
155 | | - public static bool iCloudSaveStringValue(string key, string value) |
156 | | - { |
| 78 | + public static bool iCloudSaveStringValue(string key, string value) |
| 79 | + { |
157 | 80 | #if UNITY_IOS && !UNITY_EDITOR |
158 | 81 | return _iCloudSaveString(key, value); |
159 | 82 | #else |
160 | | - return default(bool); |
| 83 | + return false; |
161 | 84 | #endif |
162 | | - } |
| 85 | + } |
163 | 86 |
|
164 | | - public static int iCloudGetIntValue(string key, int defaultValue) |
165 | | - { |
| 87 | + public static int iCloudGetIntValue(string key, int defaultValue) |
| 88 | + { |
166 | 89 | #if UNITY_IOS && !UNITY_EDITOR |
167 | 90 | return _iCloudGetInt(key, defaultValue); |
168 | 91 | #else |
169 | | - return default(int); |
| 92 | + return 0; |
170 | 93 | #endif |
171 | | - } |
| 94 | + } |
172 | 95 |
|
173 | | - public static bool iCloudSaveIntValue(string key, int value) |
174 | | - { |
| 96 | + public static bool iCloudSaveIntValue(string key, int value) |
| 97 | + { |
175 | 98 | #if UNITY_IOS && !UNITY_EDITOR |
176 | 99 | return _iCloudSaveInt(key, value); |
177 | 100 | #else |
178 | | - return default(bool); |
| 101 | + return false; |
179 | 102 | #endif |
180 | | - } |
| 103 | + } |
181 | 104 |
|
182 | | - public static float iCloudGetFloatValue(string key, float defaultValue) |
183 | | - { |
| 105 | + public static float iCloudGetFloatValue(string key, float defaultValue) |
| 106 | + { |
184 | 107 | #if UNITY_IOS && !UNITY_EDITOR |
185 | 108 | return _iCloudGetFloat(key, defaultValue); |
186 | 109 | #else |
187 | | - return default(float); |
| 110 | + return 0; |
188 | 111 | #endif |
189 | | - } |
| 112 | + } |
190 | 113 |
|
191 | | - public static bool iCloudSaveFloatValue(string key, float value) |
192 | | - { |
| 114 | + public static bool iCloudSaveFloatValue(string key, float value) |
| 115 | + { |
193 | 116 | #if UNITY_IOS && !UNITY_EDITOR |
194 | 117 | return _iCloudSaveFloat(key, value); |
195 | 118 | #else |
196 | | - return default(bool); |
| 119 | + return false; |
197 | 120 | #endif |
198 | | - } |
| 121 | + } |
199 | 122 |
|
200 | | - public static bool iCloudGetBoolValue(string key, bool defaultValue) |
201 | | - { |
| 123 | + public static bool iCloudGetBoolValue(string key, bool defaultValue) |
| 124 | + { |
202 | 125 | #if UNITY_IOS && !UNITY_EDITOR |
203 | 126 | return _iCloudGetBool(key, defaultValue); |
204 | 127 | #else |
205 | | - return default(bool); |
| 128 | + return false; |
206 | 129 | #endif |
207 | | - } |
| 130 | + } |
208 | 131 |
|
209 | | - public static bool iCloudSaveBoolValue(string key, bool value) |
210 | | - { |
| 132 | + public static bool iCloudSaveBoolValue(string key, bool value) |
| 133 | + { |
211 | 134 | #if UNITY_IOS && !UNITY_EDITOR |
212 | 135 | return _iCloudSaveBool(key, value); |
213 | 136 | #else |
214 | | - return default(bool); |
| 137 | + return false; |
| 138 | +#endif |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + public static class iOSNotification |
| 145 | + { |
| 146 | +#if UNITY_IOS && !UNITY_EDITOR |
| 147 | + [DllImport("__Internal")] |
| 148 | + private static extern void _PushNotification(string msg, string title, string identifier, int delay); |
| 149 | + |
| 150 | + [DllImport("__Internal")] |
| 151 | + private static extern void _RemovePendingNotifications(string identifier); |
| 152 | + |
| 153 | + [DllImport("__Internal")] |
| 154 | + private static extern void _RemoveAllPendingNotifications(); |
| 155 | +#endif |
| 156 | + public static void PushNotification(string msg, string title, string identifier, int delay) |
| 157 | + { |
| 158 | +#if UNITY_IOS && !UNITY_EDITOR |
| 159 | + _PushNotification(msg, title, identifier, delay); |
| 160 | +#endif |
| 161 | + } |
| 162 | + public static void RemovePendingNotifications(string identifier) |
| 163 | + { |
| 164 | +#if UNITY_IOS && !UNITY_EDITOR |
| 165 | + _RemovePendingNotifications(identifier); |
| 166 | +#endif |
| 167 | + } |
| 168 | + public static void RemoveAllPendingNotifications() |
| 169 | + { |
| 170 | +#if UNITY_IOS && !UNITY_EDITOR |
| 171 | + _RemoveAllPendingNotifications(); |
| 172 | +#endif |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + public static class iOSUIView |
| 179 | + { |
| 180 | +#if UNITY_IOS && !UNITY_EDITOR |
| 181 | + [DllImport("__Internal")] |
| 182 | + private static extern void _ShowTempAlert(string alertString, int duration = 5); |
| 183 | +#endif |
| 184 | + public static void ShowTempAlert(string alertString, int duration = 5) |
| 185 | + { |
| 186 | +#if UNITY_IOS && !UNITY_EDITOR |
| 187 | + _ShowTempAlert(alertString, duration); |
| 188 | +#endif |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + public static class iOSDevice |
| 195 | + { |
| 196 | +#if UNITY_IOS && !UNITY_EDITOR |
| 197 | + [DllImport("__Internal")] |
| 198 | + private static extern void _PlayHaptics(int style, float intensity);//0 = Light, 1=Medium, 2=Heavy |
| 199 | + |
| 200 | +#endif |
| 201 | + /// <summary> |
| 202 | + /// PlayHaptics |
| 203 | + /// </summary> |
| 204 | + /// <param name="style">0 = Light, 1=Medium, 2=Heavy</param> |
| 205 | + /// <param name="intensity">Intensity 0.0 - 1.0</param> |
| 206 | + public static void PlayHaptics(int style, float intensity) |
| 207 | + { |
| 208 | +#if UNITY_IOS && !UNITY_EDITOR |
| 209 | + _PlayHaptics(style, intensity); |
| 210 | +#endif |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + public static class iOSShare |
| 217 | + { |
| 218 | +#if UNITY_IOS && !UNITY_EDITOR |
| 219 | + [DllImport("__Internal")] |
| 220 | + private static extern void _Share(string message, string url, string imagePath); |
| 221 | + |
| 222 | +#endif |
| 223 | + public static void Share(string message, string url = "", string imagePath = "", Action closeCallback = null) |
| 224 | + { |
| 225 | +#if UNITY_IOS && !UNITY_EDITOR |
| 226 | + _Share(message, url, imagePath); |
| 227 | + iOSCallbackHelper.INSTANCE.SetShareCloseCallback(closeCallback); |
| 228 | +#endif |
| 229 | + } |
| 230 | + |
| 231 | + } |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | +#if UNITY_IOS && !UNITY_EDITOR |
| 236 | + [DllImport("__Internal")] |
| 237 | + private static extern void _initialize(); |
| 238 | +#endif |
| 239 | + public static void Initialize(){ |
| 240 | +#if UNITY_IOS && !UNITY_EDITOR |
| 241 | + _initialize(); |
215 | 242 | #endif |
| 243 | + } |
216 | 244 | } |
217 | | -} |
|
0 commit comments