AnySDKAnalytics.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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 AccountType
  9. {
  10. ANONYMOUS,/**< enum value is anonymous typek. */
  11. REGISTED,/**< enum value is registed type. */
  12. SINA_WEIBO,/**< enum value is sineweibo type. */
  13. TENCENT_WEIBO,/**< enum value is tecentweibo type */
  14. QQ,/**< enum value is qq type */
  15. ND91,/**< enum value is nd91 type. */
  16. } ;
  17. public enum AccountOperate
  18. {
  19. LOGIN,/**< enum value is the login operate. */
  20. LOGOUT,/**< enum value is the logout operate. */
  21. REGISTER,/**< enum value is the register operate. */
  22. } ;
  23. public enum AccountGender
  24. {
  25. MALE,/**< enum value is male. */
  26. FEMALE,/**< enum value is female. */
  27. UNKNOWN,/**< enum value is unknow. */
  28. } ;
  29. public enum TaskType
  30. {
  31. GUIDE_LINE,/**< enum value is the guideline type.. */
  32. MAIN_LINE,/**< enum value is the mainline type.. */
  33. BRANCH_LINE,/**<enum value is the branchline type.. */
  34. DAILY,/**< enum value is the daily type.. */
  35. ACTIVITY,/**< enum value is the activity type. */
  36. OTHER,/**< enum value is other type. */
  37. } ;
  38. public class AnySDKAnalytics
  39. {
  40. private static AnySDKAnalytics _instance;
  41. public static AnySDKAnalytics getInstance() {
  42. if( null == _instance ) {
  43. _instance = new AnySDKAnalytics();
  44. }
  45. return _instance;
  46. }
  47. /**
  48. @brief Start a new session.
  49. */
  50. public void startSession()
  51. {
  52. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  53. AnySDKAnalytics_nativeStartSession ();
  54. #else
  55. Debug.Log("This platform does not support!");
  56. #endif
  57. }
  58. /**
  59. @brief Stop a session.
  60. @warning This interface only worked on android
  61. */
  62. public void stopSession()
  63. {
  64. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  65. AnySDKAnalytics_nativeStopSession ();
  66. #else
  67. Debug.Log("This platform does not support!");
  68. #endif
  69. }
  70. /**
  71. @brief Set the timeout for expiring a session.
  72. @param millis In milliseconds as the unit of time.
  73. @note It must be invoked before calling startSession.
  74. */
  75. public void setSessionContinueMillis(long millis)
  76. {
  77. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  78. AnySDKAnalytics_nativeSetSessionContinueMillis (millis);
  79. #else
  80. Debug.Log("This platform does not support!");
  81. #endif
  82. }
  83. /**
  84. @brief log an error
  85. @param errorId The identity of error
  86. @param message Extern message for the error
  87. */
  88. public void logError(string errorId, string message)
  89. {
  90. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  91. AnySDKAnalytics_nativeLogError (errorId, message);
  92. #else
  93. Debug.Log("This platform does not support!");
  94. #endif
  95. }
  96. /**
  97. @brief log an event.
  98. @param eventId The identity of event
  99. @param paramMap Extern parameters of the event, use NULL if not needed.
  100. */
  101. public void logEvent (string eventId,Dictionary<string,string> paramMap = null)
  102. {
  103. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  104. string value;
  105. if (paramMap == null) value = null;
  106. else value = AnySDKUtil.dictionaryToString (paramMap);
  107. AnySDKAnalytics_nativeLogEvent (eventId,value);
  108. #else
  109. Debug.Log("This platform does not support!");
  110. #endif
  111. }
  112. /**
  113. @brief Track an event begin.
  114. @param eventId The identity of event
  115. */
  116. public void logTimedEventBegin (string errorId)
  117. {
  118. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  119. AnySDKAnalytics_nativeLogTimedEventBegin (errorId);
  120. #else
  121. Debug.Log("This platform does not support!");
  122. #endif
  123. }
  124. /**
  125. @brief Track an event end.
  126. @param eventId The identity of event
  127. */
  128. public void logTimedEventEnd (string eventId)
  129. {
  130. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  131. AnySDKAnalytics_nativeLogTimedEventEnd (eventId);
  132. #else
  133. Debug.Log("This platform does not support!");
  134. #endif
  135. }
  136. /**
  137. @brief Whether to catch uncaught exceptions to server.
  138. @warning This interface only worked on android.
  139. */
  140. public void setCaptureUncaughtException (bool enabled)
  141. {
  142. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  143. AnySDKAnalytics_nativeSetCaptureUncaughtException (enabled);
  144. #else
  145. Debug.Log("This platform does not support!");
  146. #endif
  147. }
  148. /**
  149. @brief Check function the plugin support or not
  150. */
  151. public bool isFunctionSupported (string functionName)
  152. {
  153. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  154. return AnySDKAnalytics_nativeIsFunctionSupported (functionName);
  155. #else
  156. Debug.Log("This platform does not support!");
  157. return false;
  158. #endif
  159. }
  160. /**
  161. * set debugmode for plugin
  162. *
  163. */
  164. [Obsolete("This interface is obsolete!",false)]
  165. public void setDebugMode(bool bDebug)
  166. {
  167. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  168. AnySDKAnalytics_nativeSetDebugMode (bDebug);
  169. #else
  170. Debug.Log("This platform does not support!");
  171. #endif
  172. }
  173. /**
  174. * Get Plugin version
  175. *
  176. * @return string
  177. */
  178. public string getPluginVersion()
  179. {
  180. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  181. StringBuilder version = new StringBuilder();
  182. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  183. AnySDKAnalytics_nativeGetPluginVersion (version);
  184. return version.ToString();
  185. #else
  186. Debug.Log("This platform does not support!");
  187. return "";
  188. #endif
  189. }
  190. /**
  191. * Get SDK version
  192. *
  193. * @return string
  194. */
  195. public string getSDKVersion()
  196. {
  197. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  198. StringBuilder version = new StringBuilder();
  199. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  200. AnySDKAnalytics_nativeGetSDKVersion (version);
  201. return version.ToString();
  202. #else
  203. Debug.Log("This platform does not support!");
  204. return "";
  205. #endif
  206. }
  207. /**
  208. *@brief methods for reflections
  209. *@param function name
  210. *@param AnySDKParam param
  211. *@return void
  212. */
  213. public void callFuncWithParam(string functionName, AnySDKParam param)
  214. {
  215. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  216. List<AnySDKParam> list = new List<AnySDKParam> ();
  217. list.Add (param);
  218. AnySDKAnalytics_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  219. #else
  220. Debug.Log("This platform does not support!");
  221. #endif
  222. }
  223. /**
  224. *@brief methods for reflections
  225. *@param function name
  226. *@param List<AnySDKParam> param
  227. *@return void
  228. */
  229. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  230. {
  231. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  232. if (param == null)
  233. {
  234. AnySDKAnalytics_nativeCallFuncWithParam (functionName, null, 0);
  235. } else {
  236. AnySDKAnalytics_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  237. }
  238. #else
  239. Debug.Log("This platform does not support!");
  240. #endif
  241. }
  242. /**
  243. *@brief methods for reflections
  244. *@param function name
  245. *@param AnySDKParam param
  246. *@return int
  247. */
  248. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  249. {
  250. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  251. List<AnySDKParam> list = new List<AnySDKParam> ();
  252. list.Add (param);
  253. return AnySDKAnalytics_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  254. #else
  255. Debug.Log("This platform does not support!");
  256. return -1;
  257. #endif
  258. }
  259. /**
  260. *@brief methods for reflections
  261. *@param function name
  262. *@param List<AnySDKParam> param
  263. *@return int
  264. */
  265. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  266. {
  267. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  268. if (param == null)
  269. {
  270. return AnySDKAnalytics_nativeCallIntFuncWithParam (functionName, null, 0);
  271. } else {
  272. return AnySDKAnalytics_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  273. }
  274. #else
  275. Debug.Log("This platform does not support!");
  276. return -1;
  277. #endif
  278. }
  279. /**
  280. *@brief methods for reflections
  281. *@param function name
  282. *@param AnySDKParam param
  283. *@return float
  284. */
  285. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  286. {
  287. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  288. List<AnySDKParam> list = new List<AnySDKParam> ();
  289. list.Add (param);
  290. return AnySDKAnalytics_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  291. #else
  292. Debug.Log("This platform does not support!");
  293. return 0;
  294. #endif
  295. }
  296. /**
  297. *@brief methods for reflections
  298. *@param function name
  299. *@param List<AnySDKParam> param
  300. *@return float
  301. */
  302. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  303. {
  304. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  305. if (param == null)
  306. {
  307. return AnySDKAnalytics_nativeCallFloatFuncWithParam (functionName, null, 0);
  308. } else {
  309. return AnySDKAnalytics_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  310. }
  311. #else
  312. Debug.Log("This platform does not support!");
  313. return 0;
  314. #endif
  315. }
  316. /**
  317. *@brief methods for reflections
  318. *@param function name
  319. *@param AnySDKParam param
  320. *@return string
  321. */
  322. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  323. {
  324. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  325. List<AnySDKParam> list = new List<AnySDKParam> ();
  326. list.Add (param);
  327. return AnySDKAnalytics_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  328. #else
  329. Debug.Log("This platform does not support!");
  330. return false;
  331. #endif
  332. }
  333. /**
  334. *@brief methods for reflections
  335. *@param function name
  336. *@param List<AnySDKParam> param
  337. *@return string
  338. */
  339. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  340. {
  341. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  342. if (param == null)
  343. {
  344. return AnySDKAnalytics_nativeCallBoolFuncWithParam (functionName, null, 0);
  345. } else {
  346. return AnySDKAnalytics_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  347. }
  348. #else
  349. Debug.Log("This platform does not support!");
  350. return false;
  351. #endif
  352. }
  353. /**
  354. *@brief methods for reflections
  355. *@param function name
  356. *@param List<AnySDKParam> param
  357. *@return string
  358. */
  359. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  360. {
  361. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  362. List<AnySDKParam> list = new List<AnySDKParam> ();
  363. list.Add (param);
  364. StringBuilder value = new StringBuilder();
  365. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  366. AnySDKAnalytics_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  367. return value.ToString ();
  368. #else
  369. Debug.Log("This platform does not support!");
  370. return "";
  371. #endif
  372. }
  373. /**
  374. *@brief methods for reflections
  375. *@param function name
  376. *@param List<AnySDKParam> param
  377. *@return string
  378. */
  379. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  380. {
  381. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  382. StringBuilder value = new StringBuilder();
  383. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  384. if (param == null)
  385. {
  386. AnySDKAnalytics_nativeCallStringFuncWithParam (functionName, null, 0,value);
  387. } else {
  388. AnySDKAnalytics_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  389. }
  390. return value.ToString ();
  391. #else
  392. Debug.Log("This platform does not support!");
  393. return "";
  394. #endif
  395. }
  396. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  397. private static extern void AnySDKAnalytics_nativeStartSession();
  398. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  399. private static extern void AnySDKAnalytics_nativeStopSession();
  400. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  401. private static extern void AnySDKAnalytics_nativeSetSessionContinueMillis(long milli);
  402. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  403. private static extern void AnySDKAnalytics_nativeLogError(string errorId, string message);
  404. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  405. private static extern void AnySDKAnalytics_nativeLogEvent(string eventId, string message);
  406. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  407. private static extern void AnySDKAnalytics_nativeLogTimedEventBegin(string eventId);
  408. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  409. private static extern void AnySDKAnalytics_nativeLogTimedEventEnd(string eventId);
  410. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  411. private static extern void AnySDKAnalytics_nativeSetCaptureUncaughtException(bool enabled);
  412. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  413. private static extern bool AnySDKAnalytics_nativeIsFunctionSupported(string functionName);
  414. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  415. private static extern void AnySDKAnalytics_nativeSetDebugMode(bool bDebug);
  416. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  417. private static extern void AnySDKAnalytics_nativeGetPluginVersion(StringBuilder version);
  418. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  419. private static extern void AnySDKAnalytics_nativeGetSDKVersion(StringBuilder version);
  420. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  421. private static extern void AnySDKAnalytics_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  422. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  423. private static extern int AnySDKAnalytics_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  424. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  425. private static extern float AnySDKAnalytics_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  426. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  427. private static extern bool AnySDKAnalytics_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  428. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  429. private static extern void AnySDKAnalytics_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  430. }
  431. }