AnySDKUser.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 ToolBarPlace
  9. {
  10. kToolBarTopLeft = 1,/**< enum the toolbar is at topleft. */
  11. kToolBarTopRight,/**< enum the toolbar is at topright. */
  12. kToolBarMidLeft,/**< enum the toolbar is at midleft. */
  13. kToolBarMidRight,/**< enum the toolbar is at midright. */
  14. kToolBarBottomLeft,/**< enum the toolbar is at bottomleft. */
  15. kToolBarBottomRight,/**< enum the toolbar is at bottomright. */
  16. } ;
  17. public enum UserActionResultCode
  18. {
  19. kInitSuccess = 0,/**< enum value is callback of succeeding in initing sdk. */
  20. kInitFail,/**< enum value is callback of failing to init sdk. */
  21. kLoginSuccess,/**< enum value is callback of succeeding in login.*/
  22. kLoginNetworkError,/**< enum value is callback of network error*/
  23. kLoginNoNeed,/**< enum value is callback of no need login.*/
  24. kLoginFail,/**< enum value is callback of failing to login. */
  25. kLoginCancel,/**< enum value is callback of canceling to login. */
  26. kLogoutSuccess,/**< enum value is callback of succeeding in logout. */
  27. kLogoutFail,/**< enum value is callback of failing to logout. */
  28. kPlatformEnter,/**< enum value is callback after enter platform. */
  29. kPlatformBack,/**< enum value is callback after exit antiAddiction. */
  30. kPausePage,/**< enum value is callback after exit pause page. */
  31. kExitPage,/**< enum value is callback after exit exit page. */
  32. kAntiAddictionQuery,/**< enum value is callback after querying antiAddiction. */
  33. kRealNameRegister,/**< enum value is callback after registering realname. */
  34. kAccountSwitchSuccess,/**< enum alue is callback of succeeding in switching account. */
  35. kAccountSwitchFail,/**< enum value is callback of failing to switch account. */
  36. kOpenShop,/**< enum value is callback of open the shop. */
  37. kAccountSwitchCancel,/**< enum value is callback of canceling to switch account. */
  38. kGameExitPage,/**< enum value is callback of no channel exit page. */
  39. kUserExtension = 50000 /**< enum value is extension code . */
  40. } ;
  41. public class AnySDKUser
  42. {
  43. private static AnySDKUser _instance;
  44. public static AnySDKUser getInstance() {
  45. if( null == _instance ) {
  46. _instance = new AnySDKUser();
  47. }
  48. return _instance;
  49. }
  50. /**
  51. @brief User login
  52. */
  53. public void login()
  54. {
  55. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  56. AnySDKUser_nativeLogin ();
  57. #else
  58. Debug.Log("This platform does not support!");
  59. #endif
  60. }
  61. /**
  62. @brief User login
  63. if the process of logining need to know the param of server_id ,
  64. you can use the function
  65. and if you must change oauthloginserver, you can add the param of oauthLoginServer
  66. @param server_id
  67. @param oauthLoginServer
  68. */
  69. [Obsolete("Please use Resources.login(Dictionary<string,string> info) instead")]
  70. public void login(string serverID,string authLoginServer = "")
  71. {
  72. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  73. AnySDKUser_nativeLoginWithParam (serverID,authLoginServer);
  74. #else
  75. Debug.Log("This platform does not support!");
  76. #endif
  77. }
  78. /**
  79. @brief User login
  80. if the process of logining need to know the parameters ,
  81. you can use the function
  82. @param the parameters
  83. */
  84. public void login(Dictionary<string,string> info)
  85. {
  86. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  87. string sInfo = AnySDKUtil.dictionaryToString (info);
  88. Debug.Log("login " + sInfo);
  89. AnySDKUser_nativeLoginWithMap (sInfo);
  90. #else
  91. Debug.Log("This platform does not support!");
  92. #endif
  93. }
  94. /**
  95. @brief Get user ID
  96. @return If user logined, return value is userID;
  97. else return value is empty string.
  98. */
  99. public string getUserID()
  100. {
  101. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  102. StringBuilder userID = new StringBuilder();
  103. userID.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  104. AnySDKUser_nativeGetUserID (userID);
  105. return userID.ToString();
  106. #else
  107. Debug.Log("This platform does not support!");
  108. return "";
  109. #endif
  110. }
  111. /**
  112. @brief Check whether the user logined or not
  113. @return If user logined, return value is true;
  114. else return value is false.
  115. */
  116. public bool isLogined()
  117. {
  118. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  119. return AnySDKUser_nativeIsLogined ();
  120. #else
  121. Debug.Log("This platform does not support!");
  122. return false;
  123. #endif
  124. }
  125. /**
  126. @brief Check function the plugin support or not
  127. @param the name of plugin
  128. @return if the function support ,return true
  129. else retur false
  130. */
  131. public bool isFunctionSupported (string functionName)
  132. {
  133. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  134. return AnySDKUser_nativeIsFunctionSupported (functionName);
  135. #else
  136. Debug.Log("This platform does not support!");
  137. return false;
  138. #endif
  139. }
  140. /**
  141. * set debugmode for plugin
  142. *
  143. */
  144. [Obsolete("This interface is obsolete!",false)]
  145. public void setDebugMode(bool bDebug)
  146. {
  147. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  148. AnySDKUser_nativeSetDebugMode (bDebug);
  149. #else
  150. Debug.Log("This platform does not support!");
  151. #endif
  152. }
  153. /**
  154. @brief set pListener The callback object for user result
  155. @param the MonoBehaviour object
  156. @param the callback of function
  157. */
  158. public void setListener(MonoBehaviour gameObject,string functionName)
  159. {
  160. #if !UNITY_EDITOR && UNITY_ANDROID
  161. AnySDKUtil.registerActionCallback (AnySDKType.User, gameObject, functionName);
  162. #elif UNITY_IOS
  163. string gameObjectName = gameObject.gameObject.name;
  164. AnySDKUser_nativeSetListener(gameObjectName,functionName);
  165. #else
  166. Debug.Log("This platform does not support!");
  167. #endif
  168. }
  169. /**
  170. @brief get plugin id
  171. @return the plugin id
  172. */
  173. public string getPluginId()
  174. {
  175. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  176. StringBuilder pluginlId = new StringBuilder();
  177. pluginlId.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  178. AnySDKUser_nativeGetPluginId (pluginlId);
  179. return pluginlId.ToString();
  180. #else
  181. Debug.Log("This platform does not support!");
  182. return "";
  183. #endif
  184. }
  185. /**
  186. * Get Plugin version
  187. *
  188. * @return string
  189. */
  190. public string getPluginVersion()
  191. {
  192. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  193. StringBuilder version = new StringBuilder();
  194. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  195. AnySDKUser_nativeGetPluginVersion (version);
  196. return version.ToString();
  197. #else
  198. Debug.Log("This platform does not support!");
  199. return "";
  200. #endif
  201. }
  202. /**
  203. * Get SDK version
  204. *
  205. * @return string
  206. */
  207. public string getSDKVersion()
  208. {
  209. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  210. StringBuilder version = new StringBuilder();
  211. version.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  212. AnySDKUser_nativeGetSDKVersion (version);
  213. return version.ToString();
  214. #else
  215. Debug.Log("This platform does not support!");
  216. return "";
  217. #endif
  218. }
  219. /**
  220. *@brief methods for reflections
  221. *@param function name
  222. *@param AnySDKParam param
  223. *@return void
  224. */
  225. public void callFuncWithParam(string functionName, AnySDKParam param)
  226. {
  227. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  228. List<AnySDKParam> list = new List<AnySDKParam> ();
  229. list.Add (param);
  230. AnySDKUser_nativeCallFuncWithParam(functionName, list.ToArray(),list.Count);
  231. #else
  232. Debug.Log("This platform does not support!");
  233. #endif
  234. }
  235. /**
  236. *@brief methods for reflections
  237. *@param function name
  238. *@param List<AnySDKParam> param
  239. *@return void
  240. */
  241. public void callFuncWithParam(string functionName, List<AnySDKParam> param = null)
  242. {
  243. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  244. if (param == null)
  245. {
  246. AnySDKUser_nativeCallFuncWithParam (functionName, null, 0);
  247. } else {
  248. AnySDKUser_nativeCallFuncWithParam (functionName, param.ToArray (), param.Count);
  249. }
  250. #else
  251. Debug.Log("This platform does not support!");
  252. #endif
  253. }
  254. /**
  255. *@brief methods for reflections
  256. *@param function name
  257. *@param AnySDKParam param
  258. *@return int
  259. */
  260. public int callIntFuncWithParam(string functionName, AnySDKParam param)
  261. {
  262. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  263. List<AnySDKParam> list = new List<AnySDKParam> ();
  264. list.Add (param);
  265. return AnySDKUser_nativeCallIntFuncWithParam(functionName, list.ToArray(),list.Count);
  266. #else
  267. Debug.Log("This platform does not support!");
  268. return -1;
  269. #endif
  270. }
  271. /**
  272. *@brief methods for reflections
  273. *@param function name
  274. *@param List<AnySDKParam> param
  275. *@return int
  276. */
  277. public int callIntFuncWithParam(string functionName, List<AnySDKParam> param = null)
  278. {
  279. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  280. if (param == null)
  281. {
  282. return AnySDKUser_nativeCallIntFuncWithParam (functionName, null, 0);
  283. } else {
  284. return AnySDKUser_nativeCallIntFuncWithParam (functionName, param.ToArray (), param.Count);
  285. }
  286. #else
  287. Debug.Log("This platform does not support!");
  288. return -1;
  289. #endif
  290. }
  291. /**
  292. *@brief methods for reflections
  293. *@param function name
  294. *@param AnySDKParam param
  295. *@return float
  296. */
  297. public float callFloatFuncWithParam(string functionName, AnySDKParam param)
  298. {
  299. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  300. List<AnySDKParam> list = new List<AnySDKParam> ();
  301. list.Add (param);
  302. return AnySDKUser_nativeCallFloatFuncWithParam(functionName, list.ToArray(),list.Count);
  303. #else
  304. Debug.Log("This platform does not support!");
  305. return 0;
  306. #endif
  307. }
  308. /**
  309. *@brief methods for reflections
  310. *@param function name
  311. *@param List<AnySDKParam> param
  312. *@return float
  313. */
  314. public float callFloatFuncWithParam(string functionName, List<AnySDKParam> param = null)
  315. {
  316. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  317. if (param == null)
  318. {
  319. return AnySDKUser_nativeCallFloatFuncWithParam (functionName, null, 0);
  320. } else {
  321. return AnySDKUser_nativeCallFloatFuncWithParam (functionName, param.ToArray (), param.Count);
  322. }
  323. #else
  324. Debug.Log("This platform does not support!");
  325. return 0;
  326. #endif
  327. }
  328. /**
  329. *@brief methods for reflections
  330. *@param function name
  331. *@param AnySDKParam param
  332. *@return bool
  333. */
  334. public bool callBoolFuncWithParam(string functionName, AnySDKParam param)
  335. {
  336. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  337. List<AnySDKParam> list = new List<AnySDKParam> ();
  338. list.Add (param);
  339. return AnySDKUser_nativeCallBoolFuncWithParam(functionName, list.ToArray(),list.Count);
  340. #else
  341. Debug.Log("This platform does not support!");
  342. return false;
  343. #endif
  344. }
  345. /**
  346. *@brief methods for reflections
  347. *@param function name
  348. *@param List<AnySDKParam> param
  349. *@return bool
  350. */
  351. public bool callBoolFuncWithParam(string functionName, List<AnySDKParam> param = null)
  352. {
  353. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  354. if (param == null)
  355. {
  356. return AnySDKUser_nativeCallBoolFuncWithParam (functionName, null, 0);
  357. } else {
  358. return AnySDKUser_nativeCallBoolFuncWithParam (functionName, param.ToArray (), param.Count);
  359. }
  360. #else
  361. Debug.Log("This platform does not support!");
  362. return false;
  363. #endif
  364. }
  365. /**
  366. *@brief methods for reflections
  367. *@param function name
  368. *@param AnySDKParam param
  369. *@return string
  370. */
  371. public string callStringFuncWithParam(string functionName, AnySDKParam param)
  372. {
  373. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  374. List<AnySDKParam> list = new List<AnySDKParam> ();
  375. list.Add (param);
  376. StringBuilder value = new StringBuilder();
  377. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  378. AnySDKUser_nativeCallStringFuncWithParam(functionName, list.ToArray(),list.Count,value);
  379. return value.ToString ();
  380. #else
  381. Debug.Log("This platform does not support!");
  382. return "";
  383. #endif
  384. }
  385. /**
  386. *@brief methods for reflections
  387. *@param function name
  388. *@param List<AnySDKParam> param
  389. *@return string
  390. */
  391. public string callStringFuncWithParam(string functionName, List<AnySDKParam> param = null)
  392. {
  393. #if !UNITY_EDITOR &&( UNITY_ANDROID || UNITY_IOS)
  394. StringBuilder value = new StringBuilder();
  395. value.Capacity = AnySDKUtil.MAX_CAPACITY_NUM;
  396. if (param == null)
  397. {
  398. AnySDKUser_nativeCallStringFuncWithParam (functionName, null, 0,value);
  399. } else {
  400. AnySDKUser_nativeCallStringFuncWithParam (functionName, param.ToArray (), param.Count,value);
  401. }
  402. return value.ToString ();
  403. #else
  404. Debug.Log("This platform does not support!");
  405. return "";
  406. #endif
  407. }
  408. [DllImport(AnySDKUtil.ANYSDK_PLATFORM,CallingConvention=CallingConvention.Cdecl)]
  409. private static extern void AnySDKUser_RegisterExternalCallDelegate(IntPtr functionPointer);
  410. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  411. private static extern void AnySDKUser_nativeLogin();
  412. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  413. private static extern void AnySDKUser_nativeSetListener(string gameName, string functionName);
  414. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  415. private static extern void AnySDKUser_nativeLoginWithParam(string serverID, string authLoginServer);
  416. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  417. private static extern void AnySDKUser_nativeLoginWithMap(string info);
  418. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  419. private static extern void AnySDKUser_nativeGetUserID(StringBuilder userID);
  420. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  421. private static extern bool AnySDKUser_nativeIsLogined();
  422. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  423. private static extern bool AnySDKUser_nativeIsFunctionSupported(string functionName);
  424. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  425. private static extern void AnySDKUser_nativeSetDebugMode(bool bDebug);
  426. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  427. private static extern void AnySDKUser_nativeGetPluginId(StringBuilder pluginID);
  428. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  429. private static extern void AnySDKUser_nativeGetPluginVersion(StringBuilder version);
  430. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  431. private static extern void AnySDKUser_nativeGetSDKVersion(StringBuilder version);
  432. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  433. private static extern void AnySDKUser_nativeCallFuncWithParam(string functionName, AnySDKParam[] param,int count);
  434. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  435. private static extern int AnySDKUser_nativeCallIntFuncWithParam(string functionName, AnySDKParam[] param,int count);
  436. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  437. private static extern float AnySDKUser_nativeCallFloatFuncWithParam(string functionName, AnySDKParam[] param,int count);
  438. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  439. private static extern bool AnySDKUser_nativeCallBoolFuncWithParam(string functionName, AnySDKParam[] param,int count);
  440. [DllImport(AnySDKUtil.ANYSDK_PLATFORM)]
  441. private static extern void AnySDKUser_nativeCallStringFuncWithParam(string functionName, AnySDKParam[] param,int count,StringBuilder value);
  442. }
  443. }