AnySDKCrash.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 AnySDKCrash
  9. {
  10. private static AnySDKCrash _instance;
  11. public static AnySDKCrash getInstance() {
  12. if( null == _instance ) {
  13. _instance = new AnySDKCrash();
  14. }
  15. return _instance;
  16. }
  17. /**
  18. * set user identifier
  19. *
  20. * @param userInfo
  21. */
  22. public void setUserIdentifier(string identifier)
  23. {
  24. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  25. AnySDKCrash_nativeSetUserIdentifier (identifier);
  26. #else
  27. Debug.Log("This platform does not support!");
  28. #endif
  29. }
  30. /**
  31. * The uploader captured in exception information
  32. *
  33. * @param message Set the custom information
  34. * @param exception The exception
  35. */
  36. public void reportException(string message, string exception)
  37. {
  38. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  39. AnySDKCrash_nativeReportException (message, exception);
  40. #else
  41. Debug.Log("This platform does not support!");
  42. #endif
  43. }
  44. /**
  45. * customize logging
  46. *
  47. * @param String Custom log
  48. */
  49. public void leaveBreadcrumb(string breadcrumb)
  50. {
  51. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  52. AnySDKCrash_nativeLeaveBreadcrumb (breadcrumb);
  53. #else
  54. Debug.Log("This platform does not support!");
  55. #endif
  56. }
  57. /**
  58. @brief Check function the plugin support or not
  59. */
  60. public bool isFunctionSupported (string functionName)
  61. {
  62. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  63. return AnySDKCrash_nativeIsFunctionSupported (functionName);
  64. #else
  65. Debug.Log("This platform does not support!");
  66. return false;
  67. #endif
  68. }
  69. /**
  70. * set debugmode for plugin
  71. *
  72. */
  73. [Obsolete("This interface is obsolete!",false)]
  74. public void setDebugMode(bool bDebug)
  75. {
  76. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  77. AnySDKCrash_nativeSetDebugMode (bDebug);
  78. #else
  79. Debug.Log("This platform does not support!");
  80. #endif
  81. }
  82. /**
  83. * Get Plugin version
  84. *
  85. * @return string
  86. */
  87. public string getPluginVersion()
  88. {
  89. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  90. StringBuilder version = new StringBuilder();
  91. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  92. AnySDKCrash_nativeGetPluginVersion (version);
  93. return version.ToString();
  94. #else
  95. Debug.Log("This platform does not support!");
  96. return "";
  97. #endif
  98. }
  99. /**
  100. * Get SDK version
  101. *
  102. * @return string
  103. */
  104. public string getSDKVersion()
  105. {
  106. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  107. StringBuilder version = new StringBuilder();
  108. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  109. AnySDKCrash_nativeGetSDKVersion (version);
  110. return version.ToString();
  111. #else
  112. Debug.Log("This platform does not support!");
  113. return "";
  114. #endif
  115. }
  116. /**
  117. *@brief methods for reflections
  118. *@param function name
  119. *@param AnySDKParam param
  120. *@return void
  121. */
  122. public void callFuncWithParam(string functionName, AnySDKParam param)
  123. {
  124. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  125. List<AnySDKParam> list = new List<AnySDKParam> ();
  126. list.Add (param);
  127. AnySDKCrash_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  128. #else
  129. Debug.Log("This platform does not support!");
  130. #endif
  131. }
  132. /**
  133. *@brief methods for reflections
  134. *@param function name
  135. *@param List<AnySDKParam> param
  136. *@return void
  137. */
  138. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  139. {
  140. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  141. if (param == null)
  142. {
  143. AnySDKCrash_nativeCallFuncWithParam (functionName, null, 0);
  144. } else {
  145. AnySDKCrash_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  146. }
  147. #else
  148. Debug.Log("This platform does not support!");
  149. #endif
  150. }
  151. /**
  152. *@brief methods for reflections
  153. *@param function name
  154. *@param AnySDKParam param
  155. *@return int
  156. */
  157. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  158. {
  159. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  160. List<AnySDKParam> list = new List<AnySDKParam> ();
  161. list.Add (param);
  162. return AnySDKCrash_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  163. #else
  164. Debug.Log("This platform does not support!");
  165. return -1;
  166. #endif
  167. }
  168. /**
  169. *@brief methods for reflections
  170. *@param function name
  171. *@param List<AnySDKParam> param
  172. *@return int
  173. */
  174. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  175. {
  176. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  177. if (param == null)
  178. {
  179. return AnySDKCrash_nativeCallIntFuncWithParam (functionName, null, 0);
  180. } else {
  181. return AnySDKCrash_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  182. }
  183. #else
  184. Debug.Log("This platform does not support!");
  185. return -1;
  186. #endif
  187. }
  188. /**
  189. *@brief methods for reflections
  190. *@param function name
  191. *@param AnySDKParam param
  192. *@return float
  193. */
  194. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  195. {
  196. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  197. List<AnySDKParam> list = new List<AnySDKParam> ();
  198. list.Add (param);
  199. return AnySDKCrash_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  200. #else
  201. Debug.Log("This platform does not support!");
  202. return 0;
  203. #endif
  204. }
  205. /**
  206. *@brief methods for reflections
  207. *@param function name
  208. *@param List<AnySDKParam> param
  209. *@return float
  210. */
  211. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  212. {
  213. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  214. if (param == null)
  215. {
  216. return AnySDKCrash_nativeCallFloatFuncWithParam (functionName, null, 0);
  217. } else {
  218. return AnySDKCrash_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  219. }
  220. #else
  221. Debug.Log("This platform does not support!");
  222. return 0;
  223. #endif
  224. }
  225. /**
  226. *@brief methods for reflections
  227. *@param function name
  228. *@param AnySDKParam param
  229. *@return string
  230. */
  231. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  232. {
  233. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  234. List<AnySDKParam> list = new List<AnySDKParam> ();
  235. list.Add (param);
  236. return AnySDKCrash_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  237. #else
  238. Debug.Log("This platform does not support!");
  239. return false;
  240. #endif
  241. }
  242. /**
  243. *@brief methods for reflections
  244. *@param function name
  245. *@param List<AnySDKParam> param
  246. *@return string
  247. */
  248. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  249. {
  250. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  251. if (param == null)
  252. {
  253. return AnySDKCrash_nativeCallBoolFuncWithParam (functionName, null, 0);
  254. } else {
  255. return AnySDKCrash_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  256. }
  257. #else
  258. Debug.Log("This platform does not support!");
  259. return false;
  260. #endif
  261. }
  262. /**
  263. *@brief methods for reflections
  264. *@param function name
  265. *@param List<AnySDKParam> param
  266. *@return string
  267. */
  268. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  269. {
  270. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  271. List<AnySDKParam> list = new List<AnySDKParam> ();
  272. list.Add (param);
  273. StringBuilder value = new StringBuilder();
  274. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  275. AnySDKCrash_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  276. return value.ToString ();
  277. #else
  278. Debug.Log("This platform does not support!");
  279. return "";
  280. #endif
  281. }
  282. /**
  283. *@brief methods for reflections
  284. *@param function name
  285. *@param List<AnySDKParam> param
  286. *@return string
  287. */
  288. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  289. {
  290. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  291. StringBuilder value = new StringBuilder();
  292. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  293. if (param == null)
  294. {
  295. AnySDKCrash_nativeCallStringFuncWithParam (functionName, null, 0,value);
  296. } else {
  297. AnySDKCrash_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  298. }
  299. return value.ToString ();
  300. #else
  301. Debug.Log("This platform does not support!");
  302. return "";
  303. #endif
  304. }
  305. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  306. private static extern void AnySDKCrash_nativeSetUserIdentifier(string identifier);
  307. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  308. private static extern void AnySDKCrash_nativeReportException(string message, string exception);
  309. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  310. private static extern void AnySDKCrash_nativeLeaveBreadcrumb(string breadcrumb);
  311. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  312. private static extern bool AnySDKCrash_nativeIsFunctionSupported(string functionName);
  313. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  314. private static extern void AnySDKCrash_nativeSetDebugMode(bool bDebug);
  315. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  316. private static extern void AnySDKCrash_nativeGetPluginVersion(StringBuilder version);
  317. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  318. private static extern void AnySDKCrash_nativeGetSDKVersion(StringBuilder version);
  319. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  320. private static extern void AnySDKCrash_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  321. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  322. private static extern int AnySDKCrash_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  323. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  324. private static extern float AnySDKCrash_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  325. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  326. private static extern bool AnySDKCrash_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  327. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  328. private static extern void AnySDKCrash_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  329. }
  330. }