QuickSDKImp.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using System;
  6. namespace quicksdk
  7. {
  8. public class OrderInfo{
  9. public string goodsID;
  10. public string goodsName;
  11. public string goodsDesc;
  12. public string quantifier; //商品量词
  13. public string cpOrderID;
  14. public string callbackUrl;
  15. public string extrasParams;
  16. public double price;
  17. public double amount;
  18. public int count;
  19. }
  20. public class GameRoleInfo
  21. {
  22. public string serverName;
  23. public string serverID;
  24. public string gameRoleName;
  25. public string gameRoleID;
  26. public string gameRoleBalance;
  27. public string vipLevel;
  28. public string gameRoleLevel;
  29. public string partyName;
  30. public string roleCreateTime;
  31. public string gameRoleGender;
  32. public string gameRolePower;
  33. public string partyId;
  34. public String professionId;
  35. public String profession;
  36. public String partyRoleId;
  37. public String partyRoleName;
  38. public String friendlist;
  39. }
  40. public class ShareInfo
  41. {
  42. public String title; //分享标题
  43. public String content; //分享内容
  44. public String imgPath; //分享图片本地地址
  45. public String imgUrl; //分享图片网络地址
  46. public String url; //分享链接
  47. public String type; //分享类型
  48. public String shareTo; //分享到哪里
  49. public String extenal; //额外备注
  50. }
  51. public enum FuncType
  52. {
  53. QUICK_SDK_FUNC_TYPE_UNDEFINED = 0,
  54. QUICK_SDK_FUNC_TYPE_ENTER_BBS = 101,/*进入论坛*/
  55. QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER = 102,/*进入用户中心*/
  56. QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR = 103,/*显示浮动工具栏*/
  57. QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR = 104,/*隐藏浮动工具栏*/
  58. QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER = 105,/*实名认证*/
  59. QUICK_SDK_FUNC_TYPE_ANTI_ADDICTION_QUERY = 106, /*防沉迷 (android)*/
  60. QUICK_SDK_FUNC_TYPE_PAUSED_GAME,/*暂停游戏 (iOS)*/
  61. QUICK_SDK_FUNC_TYPE_ENTER_CUSTOMER_CENTER, /*进入客服中心*/
  62. QUICK_SDK_FUNC_TYPE_QUERY_GOODS_INFO,
  63. QUICK_SDK_FUNC_TYPE_GET_DEVICE_ID = 112 /*获取DeviceID*/
  64. }
  65. public enum ToolbarPlace
  66. {
  67. QUICK_SDK_TOOLBAR_TOP_LEFT = 1, /* 左上 */
  68. QUICK_SDK_TOOLBAR_TOP_RIGHT = 2, /* 右上 */
  69. QUICK_SDK_TOOLBAR_MID_LEFT = 3, /* 左中 */
  70. QUICK_SDK_TOOLBAR_MID_RIGHT = 4, /* 右中 */
  71. QUICK_SDK_TOOLBAR_BOT_LEFT = 5, /* 左下 */
  72. QUICK_SDK_TOOLBAR_BOT_RIGHT = 6 /* 右下 */
  73. }
  74. // 错误信息
  75. public class ErrorMsg
  76. {
  77. public string errMsg;
  78. }
  79. // 用户信息,登录回调中使用
  80. public class UserInfo : ErrorMsg
  81. {
  82. public string uid;
  83. public string userName;
  84. public string token;
  85. }
  86. // 支付信息,支付回调中使用
  87. public class PayResult
  88. {
  89. public string orderId;
  90. public string cpOrderId;
  91. public string extraParam;
  92. }
  93. public class QuickSDKImp
  94. {
  95. private static QuickSDKImp _instance;
  96. public static QuickSDKImp getInstance() {
  97. if( null == _instance ) {
  98. _instance = new QuickSDKImp();
  99. }
  100. return _instance;
  101. }
  102. public void setListener(QuickSDKListener listener)
  103. {
  104. #if UNITY_IOS && !UNITY_EDITOR
  105. string gameObjectName = listener.gameObject.name;
  106. quicksdk_nativeSetListener(gameObjectName);
  107. #elif UNITY_ANDROID && !UNITY_EDITOR
  108. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  109. androidSupport.setListener(listener);
  110. #endif
  111. }
  112. public void init()
  113. {
  114. #if UNITY_IOS && !UNITY_EDITOR
  115. #elif UNITY_ANDROID && !UNITY_EDITOR
  116. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  117. androidSupport.init();
  118. #endif
  119. }
  120. public void exit()
  121. {
  122. #if UNITY_ANDROID && !UNITY_EDITOR
  123. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  124. androidSupport.exit();
  125. #endif
  126. }
  127. public void login ()
  128. {
  129. #if UNITY_IOS && !UNITY_EDITOR
  130. quicksdk_nativeLogin();
  131. #elif UNITY_ANDROID && !UNITY_EDITOR
  132. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  133. androidSupport.login();
  134. #endif
  135. }
  136. public void logout ()
  137. {
  138. #if UNITY_IOS && !UNITY_EDITOR
  139. quicksdk_nativeLogout();
  140. #elif UNITY_ANDROID && !UNITY_EDITOR
  141. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  142. androidSupport.logout();
  143. #endif
  144. }
  145. public int getInited()
  146. {
  147. //#if UNITY_IOS && !UNITY_EDITOR
  148. #if UNITY_ANDROID && !UNITY_EDITOR
  149. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  150. return androidSupport.GetInited();
  151. #endif
  152. return 0;
  153. }
  154. public void pay (OrderInfo orderInfo, GameRoleInfo gameRoleInfo)
  155. {
  156. #if UNITY_IOS && !UNITY_EDITOR
  157. quicksdk_nativePay(orderInfo.goodsID, orderInfo.goodsName, orderInfo.goodsDesc, orderInfo.quantifier, orderInfo.cpOrderID, orderInfo.callbackUrl, orderInfo.extrasParams, orderInfo.price, orderInfo.amount, orderInfo.count,
  158. gameRoleInfo.serverID, gameRoleInfo.serverName, gameRoleInfo.gameRoleName, gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleBalance, gameRoleInfo.vipLevel, gameRoleInfo.gameRoleLevel, gameRoleInfo.partyName);
  159. #elif UNITY_ANDROID && !UNITY_EDITOR
  160. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  161. androidSupport.pay(orderInfo, gameRoleInfo);
  162. #endif
  163. }
  164. public string userId()//uid
  165. {
  166. #if UNITY_IOS && !UNITY_EDITOR
  167. IntPtr intPtr = quicksdk_nativeUserId();
  168. return Marshal.PtrToStringAnsi(intPtr);
  169. #elif UNITY_ANDROID && !UNITY_EDITOR
  170. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  171. return androidSupport.getUserId();
  172. #else
  173. return "";
  174. #endif
  175. }
  176. public string getDeviceId()//getDeviceId
  177. {
  178. #if UNITY_IOS && !UNITY_EDITOR
  179. return "";
  180. #elif UNITY_ANDROID && !UNITY_EDITOR
  181. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  182. return androidSupport.getDeviceId();
  183. #else
  184. return "";
  185. #endif
  186. }
  187. public void createRole(GameRoleInfo gameRoleInfo){
  188. updateRoleInfoWith (gameRoleInfo, true);
  189. }
  190. public void enterGame(GameRoleInfo gameRoleInfo){
  191. updateRoleInfoWith (gameRoleInfo, false);
  192. }
  193. public void updateRole(GameRoleInfo gameRoleInfo){
  194. updateRoleInfoWith (gameRoleInfo, false);
  195. }
  196. public int showToolBar(ToolbarPlace place)//1左上,2右上,3左中,4右中,5左下,6右下
  197. {
  198. #if UNITY_IOS && !UNITY_EDITOR
  199. return (quicksdk_nativeShowToolBar((int)place) == -100?0:1);
  200. #elif UNITY_ANDROID && !UNITY_EDITOR
  201. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  202. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR);
  203. #else
  204. return 0;
  205. #endif
  206. }
  207. public int hideToolBar()
  208. {
  209. #if UNITY_IOS && !UNITY_EDITOR
  210. return (quicksdk_nativeHideToolBar() == -100?0:1);
  211. #elif UNITY_ANDROID && !UNITY_EDITOR
  212. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  213. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR);
  214. #else
  215. return 0;
  216. #endif
  217. }
  218. public bool isFunctionSupported(FuncType type)//1暂停游戏,2进入用户中心,3进入论坛,4处理应用跳转(旧),5显示浮动工具栏,6隐藏浮动工具栏,7处理应用跳转(新)
  219. {
  220. #if UNITY_IOS && !UNITY_EDITOR
  221. switch (type) {
  222. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  223. return quicksdk_nativeIsFunctionTypeSupported(3);
  224. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  225. return quicksdk_nativeIsFunctionTypeSupported(2);
  226. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  227. return quicksdk_nativeIsFunctionTypeSupported(5);
  228. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  229. return quicksdk_nativeIsFunctionTypeSupported(6);
  230. case FuncType.QUICK_SDK_FUNC_TYPE_PAUSED_GAME:
  231. return quicksdk_nativeIsFunctionTypeSupported(1);
  232. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_CUSTOMER_CENTER:
  233. return quicksdk_nativeIsFunctionTypeSupported(7);
  234. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  235. return quicksdk_nativeIsFunctionTypeSupported(8);
  236. default:
  237. return false;
  238. }
  239. #elif UNITY_ANDROID && !UNITY_EDITOR
  240. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  241. return androidSupport.isFuncSupport(type);
  242. #else
  243. return false;
  244. #endif
  245. }
  246. public void callFunction(FuncType type)
  247. {
  248. #if UNITY_IOS && !UNITY_EDITOR
  249. switch (type) {
  250. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  251. quicksdk_nativeEnterBBS();
  252. return;
  253. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  254. quicksdk_nativeEnterUserCenter();
  255. return;
  256. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  257. quicksdk_nativeShowToolBar(3);
  258. return;
  259. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  260. quicksdk_nativeHideToolBar();
  261. return;
  262. case FuncType.QUICK_SDK_FUNC_TYPE_PAUSED_GAME:
  263. quicksdk_nativePausedGame();
  264. return;
  265. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_CUSTOMER_CENTER:
  266. quicksdk_nativeEnterCustomerCenter();
  267. return;
  268. default:
  269. return;
  270. }
  271. #elif UNITY_ANDROID && !UNITY_EDITOR
  272. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  273. androidSupport.callFunc(type);
  274. #endif
  275. }
  276. public string channelName() //获取渠道名称
  277. {
  278. #if UNITY_IOS && !UNITY_EDITOR
  279. IntPtr intPtr = quicksdk_nativeChannelName();
  280. return Marshal.PtrToStringAnsi(intPtr);
  281. #elif UNITY_ANDROID && !UNITY_EDITOR
  282. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  283. return androidSupport.getChannelName();
  284. #else
  285. return "";
  286. #endif
  287. }
  288. public string channelVersion() //获取渠道版本
  289. {
  290. #if UNITY_IOS && !UNITY_EDITOR
  291. IntPtr intPtr = quicksdk_nativeChannelVersion();
  292. return Marshal.PtrToStringAnsi(intPtr);
  293. #elif UNITY_ANDROID && !UNITY_EDITOR
  294. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  295. return androidSupport.getChannelVersion();
  296. #else
  297. return "";
  298. #endif
  299. }
  300. public int channelType() //获取渠道类别 渠道唯一标识
  301. {
  302. #if UNITY_IOS && !UNITY_EDITOR
  303. return quicksdk_nativeChannelType();
  304. #elif UNITY_ANDROID && !UNITY_EDITOR
  305. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  306. return androidSupport.getChannelType();
  307. #else
  308. return 0;
  309. #endif
  310. }
  311. public string SDKVersion() //QuickSDK版本
  312. {
  313. #if UNITY_IOS && !UNITY_EDITOR
  314. IntPtr intPtr = quicksdk_nativeSDKVersion();
  315. return Marshal.PtrToStringAnsi(intPtr);
  316. #elif UNITY_ANDROID && !UNITY_EDITOR
  317. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  318. return androidSupport.getSDKVersion();
  319. #else
  320. return "";
  321. #endif
  322. }
  323. public string getConfigValue(string key) //QuickSDK版本
  324. {
  325. #if UNITY_IOS && !UNITY_EDITOR
  326. IntPtr intPtr = quicksdk_nativeGetConfigValue(key);
  327. return Marshal.PtrToStringAnsi(intPtr);
  328. #elif UNITY_ANDROID && !UNITY_EDITOR
  329. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  330. return androidSupport.getConfigValue(key);
  331. #else
  332. return "";
  333. #endif
  334. }
  335. public bool isChannelHasExitDialog()
  336. {
  337. #if UNITY_ANDROID && !UNITY_EDITOR
  338. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  339. return androidSupport.isChannelHasExitDialog();
  340. #else
  341. return false;
  342. #endif
  343. }
  344. public void exitGame()
  345. {
  346. #if UNITY_ANDROID && !UNITY_EDITOR
  347. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  348. androidSupport.exitGame();
  349. #endif
  350. }
  351. public void updateRoleInfoWith(GameRoleInfo gameRoleInfo, bool isCreateRole)
  352. {
  353. #if UNITY_IOS && !UNITY_EDITOR
  354. quicksdk_nativeUpdateRoleInfo(gameRoleInfo.serverID, gameRoleInfo.serverName, gameRoleInfo.gameRoleName, gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleBalance, gameRoleInfo.vipLevel, gameRoleInfo.gameRoleLevel, gameRoleInfo.partyName, gameRoleInfo.roleCreateTime, isCreateRole);
  355. #elif UNITY_ANDROID && !UNITY_EDITOR
  356. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  357. androidSupport.updateRoleInfo(gameRoleInfo, isCreateRole);
  358. #endif
  359. }
  360. public int enterUserCenter() //用户中心
  361. {
  362. #if UNITY_IOS && !UNITY_EDITOR
  363. return (quicksdk_nativeEnterUserCenter() == -100?0:1);
  364. #elif UNITY_ANDROID && !UNITY_EDITOR
  365. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  366. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER);
  367. #else
  368. return 0;
  369. #endif
  370. }
  371. public void enterYunKeFuCenter(GameRoleInfo gameRoleInfo){
  372. #if UNITY_IOS && !UNITY_EDITOR
  373. quicksdk_nativeEnterYunKeFuCenter(gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleName, gameRoleInfo.serverName, gameRoleInfo.vipLevel);
  374. #elif UNITY_ANDROID && !UNITY_EDITOR
  375. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  376. androidSupport.callCustomPlugin(gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleName, gameRoleInfo.serverName, gameRoleInfo.vipLevel);
  377. #endif
  378. }
  379. public void callSDKShare(ShareInfo shareInfo){
  380. #if UNITY_IOS && !UNITY_EDITOR
  381. #elif UNITY_ANDROID && !UNITY_EDITOR
  382. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  383. androidSupport.callSDKShare(shareInfo.title, shareInfo.content, shareInfo.imgPath, shareInfo.imgUrl,shareInfo.url,shareInfo.type,shareInfo.shareTo,shareInfo.extenal);
  384. #endif
  385. }
  386. private int enterCustomerCenter() ////客服
  387. {
  388. #if UNITY_IOS && !UNITY_EDITOR
  389. return (quicksdk_nativeEnterCustomerCenter() == -100?0:1);
  390. #elif UNITY_ANDROID && !UNITY_EDITOR
  391. return 0;
  392. #else
  393. return 0;
  394. #endif
  395. }
  396. private int enterBBS()//BBS
  397. {
  398. #if UNITY_IOS && !UNITY_EDITOR
  399. return (quicksdk_nativeEnterBBS() == -100?0:1);
  400. #elif UNITY_ANDROID && !UNITY_EDITOR
  401. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  402. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS);
  403. #else
  404. return 0;
  405. #endif
  406. }
  407. #if UNITY_IOS && !UNITY_EDITOR
  408. [DllImport("__Internal")]
  409. private static extern void quicksdk_nativeSetListener(string gameObjectName);
  410. [DllImport("__Internal")]
  411. private static extern void quicksdk_nativeLogin();
  412. [DllImport("__Internal")]
  413. private static extern void quicksdk_nativeLogout();
  414. [DllImport("__Internal")]
  415. private static extern void quicksdk_nativePay(string goodsId, string goodsName, string goodsDesc, string quantifier, string cpOrderId, string callbackUrl, string extrasParams, double price, double amount, int count,
  416. string serverId, string serverName, string gameRoleName, string gameRoleId, string gameRoleBalance, string vipLevel, string gameRoleLevel, string partyName);
  417. [DllImport("__Internal")]
  418. private static extern IntPtr quicksdk_nativeUserId();
  419. [DllImport("__Internal")]
  420. private static extern void quicksdk_nativeUpdateRoleInfo(string serverId, string serverName, string gameRoleName, string gameRoleId, string gameRoleBalance, string vipLevel, string gameRoleLevel, string partyName, string creatTime, bool isCreate);
  421. [DllImport("__Internal")]
  422. private static extern void quicksdk_nativeEnterYunKeFuCenter(string gameRoleID, string gameRoleName, string serverName, string vipLevel);
  423. [DllImport("__Internal")]
  424. private static extern int quicksdk_nativeEnterUserCenter();
  425. [DllImport("__Internal")]
  426. private static extern int quicksdk_nativeEnterCustomerCenter();
  427. [DllImport("__Internal")]
  428. private static extern int quicksdk_nativeEnterBBS();
  429. [DllImport("__Internal")]
  430. private static extern int quicksdk_nativeShowToolBar(int place);
  431. [DllImport("__Internal")]
  432. private static extern int quicksdk_nativeHideToolBar();
  433. [DllImport("__Internal")]
  434. private static extern int quicksdk_nativePausedGame();
  435. [DllImport("__Internal")]
  436. private static extern bool quicksdk_nativeIsFunctionTypeSupported(int type);
  437. [DllImport("__Internal")]
  438. private static extern IntPtr quicksdk_nativeChannelName();
  439. [DllImport("__Internal")]
  440. private static extern IntPtr quicksdk_nativeChannelVersion();
  441. [DllImport("__Internal")]
  442. private static extern int quicksdk_nativeChannelType();
  443. [DllImport("__Internal")]
  444. private static extern IntPtr quicksdk_nativeSDKVersion();
  445. [DllImport("__Internal")]
  446. private static extern IntPtr quicksdk_nativeGetConfigValue(string key);
  447. #endif
  448. }
  449. #if UNITY_ANDROID && !UNITY_EDITOR
  450. public class QuickUnitySupportAndroid {
  451. AndroidJavaObject ao;
  452. private static QuickUnitySupportAndroid instance;
  453. private QuickUnitySupportAndroid() {
  454. AndroidJavaClass ac = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  455. ao = ac.GetStatic<AndroidJavaObject>("currentActivity");
  456. }
  457. public static QuickUnitySupportAndroid getInstance()
  458. {
  459. if (instance == null)
  460. {
  461. instance = new QuickUnitySupportAndroid();
  462. }
  463. return instance;
  464. }
  465. public void setListener(QuickSDKListener listener)
  466. {
  467. Debug.Log("gameObject is " + listener.gameObject.name);
  468. if (listener == null)
  469. {
  470. Debug.LogError("set QuickSDKListener error, listener is null");
  471. return;
  472. }
  473. string gameObjectName = listener.gameObject.name;
  474. if (ao == null)
  475. {
  476. Debug.LogError("setListener error, current activity is null");
  477. }
  478. else
  479. {
  480. ao.Call("setUnityGameObjectName", gameObjectName);
  481. }
  482. }
  483. public int GetInited()
  484. {
  485. return ao.Call<int>("GetInitedState");
  486. }
  487. public void init()
  488. {
  489. ao.Call("requestInit");
  490. }
  491. public void exit()
  492. {
  493. ao.Call("requestExit");
  494. }
  495. public void login()
  496. {
  497. ao.Call("requestLogin");
  498. }
  499. public void logout()
  500. {
  501. ao.Call("requestLogout");
  502. }
  503. public void callCustomPlugin(String roleId,String roleName,String serverName,String vip)
  504. {
  505. ao.Call("requestCallCustomPlugin",roleId,roleName,serverName,vip);
  506. }
  507. public void callSDKShare(String title,String content,String imgPath,String imgUrl,String url,String type,String shareTo,String extenal)
  508. {
  509. ao.Call("requestCallSDKShare",title,content,imgPath,imgUrl,url,type,shareTo,extenal);
  510. }
  511. public void pay(OrderInfo orderInfo, GameRoleInfo gameRoleInfo)
  512. {
  513. if (orderInfo == null)
  514. {
  515. Debug.LogError("call pay error, orderInfo is null");
  516. return;
  517. }
  518. ao.Call("requestPay",
  519. orderInfo.goodsID, orderInfo.goodsName,
  520. orderInfo.goodsDesc, orderInfo.quantifier,
  521. orderInfo.cpOrderID, orderInfo.callbackUrl,
  522. orderInfo.extrasParams, orderInfo.price+"",
  523. orderInfo.amount + "", orderInfo.count+"",
  524. gameRoleInfo.serverName, gameRoleInfo.serverID,
  525. gameRoleInfo.gameRoleName, gameRoleInfo.gameRoleID,
  526. gameRoleInfo.gameRoleBalance, gameRoleInfo.vipLevel,
  527. gameRoleInfo.gameRoleLevel, gameRoleInfo.partyName, gameRoleInfo.roleCreateTime);
  528. }
  529. public string getUserId()
  530. {
  531. return ao.Call<string>("getUserId");
  532. }
  533. public string getDeviceId()
  534. {
  535. return ao.Call<string>("getDeviceID");
  536. }
  537. public void updateRoleInfo(GameRoleInfo gameRoleInfo, bool isCreate)
  538. {
  539. if (gameRoleInfo.Equals(null))
  540. {
  541. Debug.LogError("updateRoleInfo is error, gameRoleInfo is null");
  542. return;
  543. }
  544. string serverName = String.IsNullOrEmpty(gameRoleInfo.serverName) ? "" : gameRoleInfo.serverName;
  545. string serverId = String.IsNullOrEmpty(gameRoleInfo.serverID) ? "" : gameRoleInfo.serverID;
  546. string roleName = String.IsNullOrEmpty(gameRoleInfo.gameRoleName) ? "" : gameRoleInfo.gameRoleName;
  547. string roleId = String.IsNullOrEmpty(gameRoleInfo.gameRoleID) ? "" : gameRoleInfo.gameRoleID;
  548. string roleBalance = String.IsNullOrEmpty(gameRoleInfo.gameRoleBalance) ? "" : gameRoleInfo.gameRoleBalance;
  549. string vipLevel = String.IsNullOrEmpty(gameRoleInfo.vipLevel) ? "" : gameRoleInfo.vipLevel;
  550. string roleLevel = String.IsNullOrEmpty(gameRoleInfo.gameRoleLevel) ? "" : gameRoleInfo.gameRoleLevel;
  551. string partyName = String.IsNullOrEmpty(gameRoleInfo.partyName) ? "" : gameRoleInfo.partyName;
  552. string roleCreateTime = String.IsNullOrEmpty(gameRoleInfo.roleCreateTime) ? "" : gameRoleInfo.roleCreateTime;
  553. string gameRoleGender = String.IsNullOrEmpty(gameRoleInfo.gameRoleGender) ? "" : gameRoleInfo.gameRoleGender;
  554. string gameRolePower = String.IsNullOrEmpty(gameRoleInfo.gameRolePower) ? "" : gameRoleInfo.gameRolePower;
  555. string partyId = String.IsNullOrEmpty(gameRoleInfo.partyId) ? "" : gameRoleInfo.partyId;
  556. string professionId = String.IsNullOrEmpty(gameRoleInfo.professionId) ? "" : gameRoleInfo.professionId;
  557. string profession = String.IsNullOrEmpty(gameRoleInfo.profession) ? "" : gameRoleInfo.profession;
  558. string partyRoleId = String.IsNullOrEmpty(gameRoleInfo.partyRoleId) ? "" : gameRoleInfo.partyRoleId;
  559. string partyRoleName = String.IsNullOrEmpty(gameRoleInfo.partyRoleName) ? "" : gameRoleInfo.partyRoleName;
  560. string friendlist = String.IsNullOrEmpty(gameRoleInfo.friendlist) ? "" : gameRoleInfo.friendlist;
  561. ao.Call("requestUpdateRole",
  562. serverId,
  563. serverName,
  564. roleName,
  565. roleId,
  566. roleBalance,
  567. vipLevel,
  568. roleLevel,
  569. partyName,
  570. roleCreateTime,
  571. gameRoleGender,
  572. gameRolePower,
  573. partyId,
  574. professionId,
  575. profession,
  576. partyRoleId,
  577. partyRoleName,
  578. friendlist,
  579. isCreate + "");
  580. Debug.LogWarning("updateRoleInfo executed");
  581. }
  582. /**
  583. * return 0 success, -100 false or not support such function
  584. */
  585. public int callFunc(FuncType funcType)
  586. {
  587. int androidFuncType = 0;
  588. switch (funcType)
  589. {
  590. case FuncType.QUICK_SDK_FUNC_TYPE_UNDEFINED:
  591. // Do nothing
  592. break;
  593. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  594. androidFuncType = 101;
  595. break;
  596. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  597. androidFuncType = 102;
  598. break;
  599. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  600. androidFuncType = 103;
  601. break;
  602. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  603. androidFuncType = 104;
  604. break;
  605. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  606. androidFuncType = 105;
  607. break;
  608. case FuncType.QUICK_SDK_FUNC_TYPE_ANTI_ADDICTION_QUERY:
  609. androidFuncType = 106;
  610. break;
  611. }
  612. // TODO
  613. return ao.Call<int>("callFunc", androidFuncType);
  614. }
  615. public int callFunc(FuncType funcType,string s)
  616. {
  617. int androidFuncType =(int) funcType;
  618. // TODO
  619. return ao.Call<int>("callFunc", androidFuncType,s);
  620. }
  621. public bool isFuncSupport(FuncType funcType)
  622. {
  623. int androidFuncType = 0;
  624. switch (funcType)
  625. {
  626. case FuncType.QUICK_SDK_FUNC_TYPE_UNDEFINED:
  627. // Do nothing
  628. break;
  629. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  630. androidFuncType = 101;
  631. break;
  632. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  633. androidFuncType = 102;
  634. break;
  635. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  636. androidFuncType = 103;
  637. break;
  638. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  639. androidFuncType = 104;
  640. break;
  641. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  642. androidFuncType = 105;
  643. break;
  644. case FuncType.QUICK_SDK_FUNC_TYPE_ANTI_ADDICTION_QUERY:
  645. androidFuncType = 106;
  646. break;
  647. }
  648. return ao.Call<bool>("isFuncSupport", androidFuncType);
  649. }
  650. public string getChannelName()
  651. {
  652. return ao.Call<string>("getChannelName");
  653. }
  654. public string getChannelVersion()
  655. {
  656. return ao.Call<string>("getChannelVersion");
  657. }
  658. public int getChannelType()
  659. {
  660. return ao.Call<int>("getChannelType");
  661. }
  662. public string getSDKVersion()
  663. {
  664. return ao.Call<string>("getSDKVersion");
  665. }
  666. public string getConfigValue(string key)
  667. {
  668. if (String.IsNullOrEmpty(key))
  669. {
  670. return null;
  671. }
  672. return ao.Call<string>("getConfigValue", key);
  673. }
  674. public bool isChannelHasExitDialog()
  675. {
  676. return ao.Call<bool>("isChannelHasExitDialog");
  677. }
  678. public void exitGame()
  679. {
  680. ao.Call("exitGame");
  681. }
  682. }
  683. #endif
  684. }