AnySDKAdTracking.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 class AnySDKAdTracking
  9. {
  10. private static AnySDKAdTracking _instance;
  11. public static AnySDKAdTracking getInstance() {
  12. if( null == _instance ) {
  13. _instance = new AnySDKAdTracking();
  14. }
  15. return _instance;
  16. }
  17. /**
  18. *
  19. * @Title: onRegister
  20. * @Description: Call this method if you want to track register events as happening during a section.
  21. * @param userId user identifier
  22. * @return void
  23. */
  24. public void onRegister(string userId)
  25. {
  26. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  27. AnySDKAdTracking_nativeOnRegister (userId);
  28. #else
  29. Debug.Log("This platform does not support!");
  30. #endif
  31. }
  32. /**
  33. *
  34. * @Title: onLogin
  35. * @Description:Call this method if you want to track login events as happening during a section.
  36. * @param userInfo The details of this parameters are already covered by document.
  37. * @return void
  38. */
  39. public void onLogin(Dictionary<string,string> userInfo)
  40. {
  41. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  42. string info = AnySDKUtil.dictionaryToString (userInfo);
  43. Debug.Log("onLogin " + info);
  44. AnySDKAdTracking_nativeOnLogin (info);
  45. #else
  46. Debug.Log("This platform does not support!");
  47. #endif
  48. }
  49. /**
  50. *
  51. * @Title: onPay
  52. * @Description: Call this method if you want to track pay events as happening during a section.
  53. * @param productInfo The details of this parameters are already covered by document.
  54. * @return void
  55. */
  56. public void onPay(Dictionary<string,string> userInfo)
  57. {
  58. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  59. string info = AnySDKUtil.dictionaryToString (userInfo);
  60. Debug.Log("onPay " + info);
  61. AnySDKAdTracking_nativeOnPay (info);
  62. #else
  63. Debug.Log("This platform does not support!");
  64. #endif
  65. }
  66. /**
  67. *
  68. * @Title: trackEvent
  69. * @Description: Call this method if you want to track custom events with parameters as happening during a section.
  70. * @param eventId The custom event name.
  71. * @param paramMap The details of this parameters are already covered by document.
  72. */
  73. public void trackEvent (string eventId,Dictionary<string,string> paramMap = null)
  74. {
  75. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  76. string value;
  77. if (paramMap == null) value = null;
  78. else value = AnySDKUtil.dictionaryToString (paramMap);
  79. AnySDKAdTracking_nativeTrackEvent (eventId,value);
  80. #else
  81. Debug.Log("This platform does not support!");
  82. #endif
  83. }
  84. /**
  85. @brief Check function the plugin support or not
  86. */
  87. public bool isFunctionSupported (string functionName)
  88. {
  89. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  90. return AnySDKAdTracking_nativeIsFunctionSupported (functionName);
  91. #else
  92. Debug.Log("This platform does not support!");
  93. return false;
  94. #endif
  95. }
  96. /**
  97. * set debugmode for plugin
  98. *
  99. */
  100. [Obsolete("This interface is obsolete!",false)]
  101. public void setDebugMode(bool bDebug)
  102. {
  103. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  104. AnySDKAdTracking_nativeSetDebugMode (bDebug);
  105. #else
  106. Debug.Log("This platform does not support!");
  107. #endif
  108. }
  109. /**
  110. * Get Plugin version
  111. *
  112. * @return string
  113. */
  114. public string getPluginVersion()
  115. {
  116. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  117. StringBuilder version = new StringBuilder();
  118. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  119. AnySDKAdTracking_nativeGetPluginVersion (version);
  120. return version.ToString();
  121. #else
  122. Debug.Log("This platform does not support!");
  123. return "";
  124. #endif
  125. }
  126. /**
  127. * Get SDK version
  128. *
  129. * @return string
  130. */
  131. public string getSDKVersion()
  132. {
  133. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  134. StringBuilder version = new StringBuilder();
  135. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  136. AnySDKAdTracking_nativeGetSDKVersion (version);
  137. return version.ToString();
  138. #else
  139. Debug.Log("This platform does not support!");
  140. return "";
  141. #endif
  142. }
  143. /**
  144. *@brief methods for reflections
  145. *@param function name
  146. *@param AnySDKParam param
  147. *@return void
  148. */
  149. public void callFuncWithParam(string functionName, AnySDKParam param)
  150. {
  151. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  152. List<AnySDKParam> list = new List<AnySDKParam> ();
  153. list.Add (param);
  154. AnySDKAdTracking_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  155. #else
  156. Debug.Log("This platform does not support!");
  157. #endif
  158. }
  159. /**
  160. *@brief methods for reflections
  161. *@param function name
  162. *@param List<AnySDKParam> param
  163. *@return void
  164. */
  165. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  166. {
  167. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  168. if (param == null)
  169. {
  170. AnySDKAdTracking_nativeCallFuncWithParam (functionName, null, 0);
  171. } else {
  172. AnySDKAdTracking_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  173. }
  174. #else
  175. Debug.Log("This platform does not support!");
  176. #endif
  177. }
  178. /**
  179. *@brief methods for reflections
  180. *@param function name
  181. *@param AnySDKParam param
  182. *@return int
  183. */
  184. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  185. {
  186. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  187. List<AnySDKParam> list = new List<AnySDKParam> ();
  188. list.Add (param);
  189. return AnySDKAdTracking_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  190. #else
  191. Debug.Log("This platform does not support!");
  192. return -1;
  193. #endif
  194. }
  195. /**
  196. *@brief methods for reflections
  197. *@param function name
  198. *@param List<AnySDKParam> param
  199. *@return int
  200. */
  201. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  202. {
  203. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  204. if (param == null)
  205. {
  206. return AnySDKAdTracking_nativeCallIntFuncWithParam (functionName, null, 0);
  207. } else {
  208. return AnySDKAdTracking_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  209. }
  210. #else
  211. Debug.Log("This platform does not support!");
  212. return -1;
  213. #endif
  214. }
  215. /**
  216. *@brief methods for reflections
  217. *@param function name
  218. *@param AnySDKParam param
  219. *@return float
  220. */
  221. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  222. {
  223. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  224. List<AnySDKParam> list = new List<AnySDKParam> ();
  225. list.Add (param);
  226. return AnySDKAdTracking_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  227. #else
  228. Debug.Log("This platform does not support!");
  229. return 0;
  230. #endif
  231. }
  232. /**
  233. *@brief methods for reflections
  234. *@param function name
  235. *@param List<AnySDKParam> param
  236. *@return float
  237. */
  238. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  239. {
  240. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  241. if (param == null)
  242. {
  243. return AnySDKAdTracking_nativeCallFloatFuncWithParam (functionName, null, 0);
  244. } else {
  245. return AnySDKAdTracking_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  246. }
  247. #else
  248. Debug.Log("This platform does not support!");
  249. return 0;
  250. #endif
  251. }
  252. /**
  253. *@brief methods for reflections
  254. *@param function name
  255. *@param AnySDKParam param
  256. *@return string
  257. */
  258. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  259. {
  260. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  261. List<AnySDKParam> list = new List<AnySDKParam> ();
  262. list.Add (param);
  263. return AnySDKAdTracking_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  264. #else
  265. Debug.Log("This platform does not support!");
  266. return false;
  267. #endif
  268. }
  269. /**
  270. *@brief methods for reflections
  271. *@param function name
  272. *@param List<AnySDKParam> param
  273. *@return string
  274. */
  275. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  276. {
  277. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  278. if (param == null)
  279. {
  280. return AnySDKAdTracking_nativeCallBoolFuncWithParam (functionName, null, 0);
  281. } else {
  282. return AnySDKAdTracking_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  283. }
  284. #else
  285. Debug.Log("This platform does not support!");
  286. return false;
  287. #endif
  288. }
  289. /**
  290. *@brief methods for reflections
  291. *@param function name
  292. *@param List<AnySDKParam> param
  293. *@return string
  294. */
  295. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  296. {
  297. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  298. List<AnySDKParam> list = new List<AnySDKParam> ();
  299. list.Add (param);
  300. StringBuilder value = new StringBuilder();
  301. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  302. AnySDKAdTracking_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  303. return value.ToString ();
  304. #else
  305. Debug.Log("This platform does not support!");
  306. return "";
  307. #endif
  308. }
  309. /**
  310. *@brief methods for reflections
  311. *@param function name
  312. *@param List<AnySDKParam> param
  313. *@return string
  314. */
  315. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  316. {
  317. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  318. StringBuilder value = new StringBuilder();
  319. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  320. if (param == null)
  321. {
  322. AnySDKAdTracking_nativeCallStringFuncWithParam (functionName, null, 0,value);
  323. } else {
  324. AnySDKAdTracking_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  325. }
  326. return value.ToString ();
  327. #else
  328. Debug.Log("This platform does not support!");
  329. return "";
  330. #endif
  331. }
  332. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  333. private static extern void AnySDKAdTracking_nativeOnRegister(string userId);
  334. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  335. private static extern void AnySDKAdTracking_nativeOnLogin(string info);
  336. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  337. private static extern void AnySDKAdTracking_nativeOnPay(string info);
  338. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  339. private static extern void AnySDKAdTracking_nativeTrackEvent(string eventId, string message);
  340. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  341. private static extern bool AnySDKAdTracking_nativeIsFunctionSupported(string functionName);
  342. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  343. private static extern void AnySDKAdTracking_nativeSetDebugMode(bool bDebug);
  344. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  345. private static extern void AnySDKAdTracking_nativeGetPluginVersion(StringBuilder version);
  346. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  347. private static extern void AnySDKAdTracking_nativeGetSDKVersion(StringBuilder version);
  348. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  349. private static extern void AnySDKAdTracking_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  350. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  351. private static extern int AnySDKAdTracking_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  352. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  353. private static extern float AnySDKAdTracking_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  354. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  355. private static extern bool AnySDKAdTracking_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  356. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  357. private static extern void AnySDKAdTracking_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  358. }
  359. }