AnySDKPush.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System;
  7. namespace anysdk {
  8. public enum PushActionResultCode
  9. {
  10. kPushReceiveMessage = 0,/**value is callback of Receiving Message . */
  11. kPushExtensionCode = 60000 /**< enum value is extension code . */
  12. } ;
  13. public class AnySDKPush
  14. {
  15. private static AnySDKPush _instance;
  16. public static AnySDKPush getInstance() {
  17. if( null == _instance ) {
  18. _instance = new AnySDKPush();
  19. }
  20. return _instance;
  21. }
  22. /**
  23. *@brief start/register Push services
  24. *@return void
  25. */
  26. public void startPush()
  27. {
  28. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  29. AnySDKPush_nativeStartPush ();
  30. #else
  31. Debug.Log("This platform does not support!");
  32. #endif
  33. }
  34. /**
  35. *@brief close Push services
  36. *@return void
  37. */
  38. public void closePush()
  39. {
  40. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  41. AnySDKPush_nativeClosePush ();
  42. #else
  43. Debug.Log("This platform does not support!");
  44. #endif
  45. }
  46. /**
  47. *@brief set alias
  48. *@param tags
  49. *@return void
  50. */
  51. public void setAlias(string alia)
  52. {
  53. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  54. AnySDKPush_nativeSetAlias (alia);
  55. #else
  56. Debug.Log("This platform does not support!");
  57. #endif
  58. }
  59. /**
  60. *@brief del alias
  61. *@param tags
  62. *@return void
  63. */
  64. public void delAlias(string alia)
  65. {
  66. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  67. AnySDKPush_nativeDelAlias (alia);
  68. #else
  69. Debug.Log("This platform does not support!");
  70. #endif
  71. }
  72. /**
  73. *@brief set tag
  74. *@param tags
  75. *@return void
  76. */
  77. public void setTags (List<string> tags)
  78. {
  79. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  80. string value = AnySDKUtil.ListToString(tags);
  81. AnySDKPush_nativeSetTags (value);
  82. #else
  83. Debug.Log("This platform does not support!");
  84. #endif
  85. }
  86. /**
  87. *@brief del tag
  88. *@param tags
  89. *@return void
  90. */
  91. public void delTags (List<string> tags)
  92. {
  93. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  94. string value = AnySDKUtil.ListToString(tags);
  95. AnySDKPush_nativeDelTags (value);
  96. #else
  97. Debug.Log("This platform does not support!");
  98. #endif
  99. }
  100. /**
  101. @brief Check function the plugin support or not
  102. */
  103. public bool isFunctionSupported (string functionName)
  104. {
  105. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  106. return AnySDKPush_nativeIsFunctionSupported (functionName);
  107. #else
  108. Debug.Log("This platform does not support!");
  109. return false;
  110. #endif
  111. }
  112. /**
  113. * set debugmode for plugin
  114. *
  115. */
  116. [Obsolete("This interface is obsolete!",false)]
  117. public void setDebugMode(bool bDebug)
  118. {
  119. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  120. AnySDKPush_nativeSetDebugMode (bDebug);
  121. #else
  122. Debug.Log("This platform does not support!");
  123. #endif
  124. }
  125. /**
  126. @brief set pListener The callback object for push result
  127. @param the MonoBehaviour object
  128. @param the callback of function
  129. */
  130. public void setListener(MonoBehaviour gameObject,string functionName)
  131. {
  132. #if !UNITY_EDITOR && UNITY_ANDROID
  133. AnySDKUtil.registerActionCallback (AnySDKType.Push, gameObject, functionName);
  134. #elif !UNITY_EDITOR && UNITY_IOS
  135. string gameObjectName = gameObject.gameObject.name;
  136. AnySDKPush_nativeSetListener(gameObjectName,functionName);
  137. #else
  138. Debug.Log("This platform does not support!");
  139. #endif
  140. }
  141. /**
  142. * Get Plugin version
  143. *
  144. * @return string
  145. */
  146. public string getPluginVersion()
  147. {
  148. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  149. StringBuilder version = new StringBuilder();
  150. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  151. AnySDKPush_nativeGetPluginVersion (version);
  152. return version.ToString();
  153. #else
  154. Debug.Log("This platform does not support!");
  155. return "";
  156. #endif
  157. }
  158. /**
  159. * Get SDK version
  160. *
  161. * @return string
  162. */
  163. public string getSDKVersion()
  164. {
  165. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  166. StringBuilder version = new StringBuilder();
  167. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  168. AnySDKPush_nativeGetSDKVersion (version);
  169. return version.ToString();
  170. #else
  171. Debug.Log("This platform does not support!");
  172. return "";
  173. #endif
  174. }
  175. /**
  176. *@brief methods for reflections
  177. *@param function name
  178. *@param AnySDKParam param
  179. *@return void
  180. */
  181. public void callFuncWithParam(string functionName, AnySDKParam param)
  182. {
  183. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  184. List<AnySDKParam> list = new List<AnySDKParam> ();
  185. list.Add (param);
  186. AnySDKPush_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  187. #else
  188. Debug.Log("This platform does not support!");
  189. #endif
  190. }
  191. /**
  192. *@brief methods for reflections
  193. *@param function name
  194. *@param List<AnySDKParam> param
  195. *@return void
  196. */
  197. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  198. {
  199. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  200. if (param == null)
  201. {
  202. AnySDKPush_nativeCallFuncWithParam (functionName, null, 0);
  203. } else {
  204. AnySDKPush_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  205. }
  206. #else
  207. Debug.Log("This platform does not support!");
  208. #endif
  209. }
  210. /**
  211. *@brief methods for reflections
  212. *@param function name
  213. *@param AnySDKParam param
  214. *@return void
  215. */
  216. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  217. {
  218. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  219. List<AnySDKParam> list = new List<AnySDKParam> ();
  220. list.Add (param);
  221. return AnySDKPush_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  222. #else
  223. Debug.Log("This platform does not support!");
  224. return -1;
  225. #endif
  226. }
  227. /**
  228. *@brief methods for reflections
  229. *@param function name
  230. *@param List<AnySDKParam> param
  231. *@return void
  232. */
  233. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  234. {
  235. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  236. if (param == null)
  237. {
  238. return AnySDKPush_nativeCallIntFuncWithParam (functionName, null, 0);
  239. } else {
  240. return AnySDKPush_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  241. }
  242. #else
  243. Debug.Log("This platform does not support!");
  244. return -1;
  245. #endif
  246. }
  247. /**
  248. *@brief methods for reflections
  249. *@param function name
  250. *@param AnySDKParam param
  251. *@return float
  252. */
  253. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  254. {
  255. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  256. List<AnySDKParam> list = new List<AnySDKParam> ();
  257. list.Add (param);
  258. return AnySDKPush_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  259. #else
  260. Debug.Log("This platform does not support!");
  261. return 0;
  262. #endif
  263. }
  264. /**
  265. *@brief methods for reflections
  266. *@param function name
  267. *@param List<AnySDKParam> param
  268. *@return float
  269. */
  270. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  271. {
  272. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  273. if (param == null)
  274. {
  275. return AnySDKPush_nativeCallFloatFuncWithParam (functionName, null, 0);
  276. } else {
  277. return AnySDKPush_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  278. }
  279. #else
  280. Debug.Log("This platform does not support!");
  281. return 0;
  282. #endif
  283. }
  284. /**
  285. *@brief methods for reflections
  286. *@param function name
  287. *@param AnySDKParam param
  288. *@return bool
  289. */
  290. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  291. {
  292. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  293. List<AnySDKParam> list = new List<AnySDKParam> ();
  294. list.Add (param);
  295. return AnySDKPush_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  296. #else
  297. Debug.Log("This platform does not support!");
  298. return false;
  299. #endif
  300. }
  301. /**
  302. *@brief methods for reflections
  303. *@param function name
  304. *@param List<AnySDKParam> param
  305. *@return bool
  306. */
  307. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  308. {
  309. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  310. if (param == null)
  311. {
  312. return AnySDKPush_nativeCallBoolFuncWithParam (functionName, null, 0);
  313. } else {
  314. return AnySDKPush_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  315. }
  316. #else
  317. Debug.Log("This platform does not support!");
  318. return false;
  319. #endif
  320. }
  321. /**
  322. *@brief methods for reflections
  323. *@param function name
  324. *@param AnySDKParam param
  325. *@return string
  326. */
  327. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  328. {
  329. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  330. List<AnySDKParam> list = new List<AnySDKParam> ();
  331. list.Add (param);
  332. StringBuilder value = new StringBuilder();
  333. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  334. AnySDKPush_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  335. return value.ToString ();
  336. #else
  337. Debug.Log("This platform does not support!");
  338. return "";
  339. #endif
  340. }
  341. /**
  342. *@brief methods for reflections
  343. *@param function name
  344. *@param List<AnySDKParam> param
  345. *@return string
  346. */
  347. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  348. {
  349. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  350. StringBuilder value = new StringBuilder();
  351. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  352. if (param == null)
  353. {
  354. AnySDKPush_nativeCallStringFuncWithParam (functionName, null, 0,value);
  355. } else {
  356. AnySDKPush_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  357. }
  358. return value.ToString ();
  359. #else
  360. Debug.Log("This platform does not support!");
  361. return "";
  362. #endif
  363. }
  364. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  365. private static extern void AnySDKPush_RegisterExternalCallDelegate(IntPtr functionPointer);
  366. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  367. private static extern void AnySDKPush_nativeSetListener(string gameName, string functionName);
  368. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  369. private static extern void AnySDKPush_nativeStartPush();
  370. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  371. private static extern void AnySDKPush_nativeClosePush();
  372. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  373. private static extern void AnySDKPush_nativeSetAlias(string alia);
  374. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  375. private static extern void AnySDKPush_nativeDelAlias(string alia);
  376. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  377. private static extern void AnySDKPush_nativeSetTags(string tags);
  378. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  379. private static extern void AnySDKPush_nativeDelTags(string tags);
  380. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  381. private static extern bool AnySDKPush_nativeIsFunctionSupported(string functionName);
  382. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  383. private static extern void AnySDKPush_nativeSetDebugMode(bool bDebug);
  384. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  385. private static extern void AnySDKPush_nativeGetPluginVersion(StringBuilder version);
  386. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  387. private static extern void AnySDKPush_nativeGetSDKVersion(StringBuilder version);
  388. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  389. private static extern void AnySDKPush_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  390. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  391. private static extern int AnySDKPush_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  392. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  393. private static extern float AnySDKPush_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  394. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  395. private static extern bool AnySDKPush_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  396. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  397. private static extern void AnySDKPush_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  398. }
  399. }