QuickSDKImp.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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 profession;
  32. public string gameRoleGender;
  33. public string gameRolePower;
  34. public string partyId;
  35. public String professionId;
  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. QUICK_SDK_FUNC_TYPE_OPEN_FLOAT_CENTER = 209 /*打开浮球的用户中心*/
  65. }
  66. public enum ToolbarPlace
  67. {
  68. QUICK_SDK_TOOLBAR_TOP_LEFT = 1, /* 左上 */
  69. QUICK_SDK_TOOLBAR_TOP_RIGHT = 2, /* 右上 */
  70. QUICK_SDK_TOOLBAR_MID_LEFT = 3, /* 左中 */
  71. QUICK_SDK_TOOLBAR_MID_RIGHT = 4, /* 右中 */
  72. QUICK_SDK_TOOLBAR_BOT_LEFT = 5, /* 左下 */
  73. QUICK_SDK_TOOLBAR_BOT_RIGHT = 6 /* 右下 */
  74. }
  75. // 错误信息
  76. public class ErrorMsg
  77. {
  78. public string errMsg;
  79. }
  80. // 用户信息,登录回调中使用
  81. public class UserInfo : ErrorMsg
  82. {
  83. public string uid;
  84. public string userName;
  85. public string token;
  86. }
  87. // 支付信息,支付回调中使用
  88. public class PayResult
  89. {
  90. public string orderId;
  91. public string cpOrderId;
  92. public string extraParam;
  93. }
  94. public class QuickSDKImp
  95. {
  96. private static QuickSDKImp _instance;
  97. public static QuickSDKImp getInstance() {
  98. if( null == _instance ) {
  99. _instance = new QuickSDKImp();
  100. }
  101. return _instance;
  102. }
  103. public void setListener(QuickSDKListener listener)
  104. {
  105. #if UNITY_IOS && !UNITY_EDITOR
  106. string gameObjectName = listener.gameObject.name;
  107. quicksdk_nativeSetListener(gameObjectName);
  108. #elif UNITY_ANDROID && !UNITY_EDITOR
  109. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  110. androidSupport.setListener(listener);
  111. #endif
  112. }
  113. public void callShowPrivace()
  114. {
  115. #if UNITY_IOS && !UNITY_EDITOR
  116. #elif UNITY_ANDROID && !UNITY_EDITOR
  117. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  118. androidSupport.showPrivace();
  119. #endif
  120. }
  121. public void init()
  122. {
  123. #if UNITY_IOS && !UNITY_EDITOR
  124. #elif UNITY_ANDROID && !UNITY_EDITOR
  125. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  126. androidSupport.init();
  127. #endif
  128. }
  129. public void exit()
  130. {
  131. #if UNITY_ANDROID && !UNITY_EDITOR
  132. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  133. androidSupport.exit();
  134. #endif
  135. }
  136. public void login ()
  137. {
  138. #if UNITY_IOS && !UNITY_EDITOR
  139. quicksdk_nativeLogin();
  140. #elif UNITY_ANDROID && !UNITY_EDITOR
  141. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  142. androidSupport.login();
  143. #endif
  144. }
  145. public void logout ()
  146. {
  147. #if UNITY_IOS && !UNITY_EDITOR
  148. quicksdk_nativeLogout();
  149. #elif UNITY_ANDROID && !UNITY_EDITOR
  150. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  151. androidSupport.logout();
  152. #endif
  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, gameRoleInfo.gameRolePower, gameRoleInfo.profession);
  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 String 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 String 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处理应用跳转(新),8实名认证
  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 String 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. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  269. quicksdk_nativeRealNameAuth(1);
  270. return "";
  271. default:
  272. return "";
  273. }
  274. #elif UNITY_ANDROID && !UNITY_EDITOR
  275. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  276. return androidSupport.callFunc(type)+"";
  277. #else
  278. return "";
  279. #endif
  280. }
  281. public String callFuncWithResult(FuncType type)
  282. {
  283. #if UNITY_IOS && !UNITY_EDITOR
  284. return "";
  285. #elif UNITY_ANDROID && !UNITY_EDITOR
  286. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  287. return androidSupport.callFuncWithResult(type);
  288. #else
  289. return "";
  290. #endif
  291. }
  292. public string channelName() //获取渠道名称
  293. {
  294. #if UNITY_IOS && !UNITY_EDITOR
  295. IntPtr intPtr = quicksdk_nativeChannelName();
  296. return Marshal.PtrToStringAnsi(intPtr);
  297. #elif UNITY_ANDROID && !UNITY_EDITOR
  298. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  299. return androidSupport.getChannelName();
  300. #else
  301. return "";
  302. #endif
  303. }
  304. public string channelVersion() //获取渠道版本
  305. {
  306. #if UNITY_IOS && !UNITY_EDITOR
  307. IntPtr intPtr = quicksdk_nativeChannelVersion();
  308. return Marshal.PtrToStringAnsi(intPtr);
  309. #elif UNITY_ANDROID && !UNITY_EDITOR
  310. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  311. return androidSupport.getChannelVersion();
  312. #else
  313. return "";
  314. #endif
  315. }
  316. public String getParentChannelType()
  317. {
  318. #if UNITY_IOS && !UNITY_EDITOR
  319. return "";
  320. #elif UNITY_ANDROID && !UNITY_EDITOR
  321. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  322. return androidSupport.getParentChannelType();
  323. #else
  324. return "";
  325. #endif
  326. }
  327. public String getOaid()
  328. {
  329. #if UNITY_IOS && !UNITY_EDITOR
  330. return "";
  331. #elif UNITY_ANDROID && !UNITY_EDITOR
  332. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  333. return androidSupport.getOaid();
  334. #else
  335. return "";
  336. #endif
  337. }
  338. public int channelType() //获取渠道类别 渠道唯一标识
  339. {
  340. #if UNITY_IOS && !UNITY_EDITOR
  341. return quicksdk_nativeChannelType();
  342. #elif UNITY_ANDROID && !UNITY_EDITOR
  343. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  344. return androidSupport.getChannelType();
  345. #else
  346. return 0;
  347. #endif
  348. }
  349. public string SDKVersion() //QuickSDK版本
  350. {
  351. #if UNITY_IOS && !UNITY_EDITOR
  352. IntPtr intPtr = quicksdk_nativeSDKVersion();
  353. return Marshal.PtrToStringAnsi(intPtr);
  354. #elif UNITY_ANDROID && !UNITY_EDITOR
  355. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  356. return androidSupport.getSDKVersion();
  357. #else
  358. return "";
  359. #endif
  360. }
  361. public string getConfigValue(string key) //QuickSDK版本
  362. {
  363. #if UNITY_IOS && !UNITY_EDITOR
  364. IntPtr intPtr = quicksdk_nativeGetConfigValue(key);
  365. return Marshal.PtrToStringAnsi(intPtr);
  366. #elif UNITY_ANDROID && !UNITY_EDITOR
  367. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  368. return androidSupport.getConfigValue(key);
  369. #else
  370. return "";
  371. #endif
  372. }
  373. //返回为0代表不支持该funcType,返回1则代表支持
  374. public int callFunctionWithParams(int funcType,String[] param)
  375. {
  376. #if UNITY_IOS && !UNITY_EDITOR
  377. return 0;
  378. #elif UNITY_ANDROID && !UNITY_EDITOR
  379. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  380. return androidSupport.callFunctionWithParams(funcType,param);
  381. #else
  382. return 0;
  383. #endif
  384. }
  385. public bool isChannelHasExitDialog()
  386. {
  387. #if UNITY_ANDROID && !UNITY_EDITOR
  388. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  389. return androidSupport.isChannelHasExitDialog();
  390. #else
  391. return false;
  392. #endif
  393. }
  394. public void exitGame()
  395. {
  396. #if UNITY_ANDROID && !UNITY_EDITOR
  397. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  398. androidSupport.exitGame();
  399. #endif
  400. }
  401. public String openFloatUserCenter() //打开浮球的用户中心
  402. {
  403. #if UNITY_IOS && !UNITY_EDITOR
  404. return "0";
  405. #elif UNITY_ANDROID && !UNITY_EDITOR
  406. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  407. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_OPEN_FLOAT_CENTER);
  408. #else
  409. return "0";
  410. #endif
  411. }
  412. public void updateRoleInfoWith(GameRoleInfo gameRoleInfo, bool isCreateRole)
  413. {
  414. #if UNITY_IOS && !UNITY_EDITOR
  415. quicksdk_nativeUpdateRoleInfo(gameRoleInfo.serverID, gameRoleInfo.serverName, gameRoleInfo.gameRoleName, gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleBalance, gameRoleInfo.vipLevel, gameRoleInfo.gameRoleLevel, gameRoleInfo.partyName, gameRoleInfo.roleCreateTime, gameRoleInfo.gameRolePower, gameRoleInfo.profession, isCreateRole);
  416. #elif UNITY_ANDROID && !UNITY_EDITOR
  417. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  418. androidSupport.updateRoleInfo(gameRoleInfo, isCreateRole);
  419. #endif
  420. }
  421. public String enterUserCenter() //用户中心
  422. {
  423. #if UNITY_IOS && !UNITY_EDITOR
  424. return (quicksdk_nativeEnterUserCenter() == -100?"0":"1"
  425. );
  426. #elif UNITY_ANDROID && !UNITY_EDITOR
  427. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  428. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER);
  429. #else
  430. return "0";
  431. #endif
  432. }
  433. public void enterYunKeFuCenter(GameRoleInfo gameRoleInfo){
  434. #if UNITY_IOS && !UNITY_EDITOR
  435. quicksdk_nativeEnterYunKeFuCenter(gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleName, gameRoleInfo.serverName, gameRoleInfo.vipLevel);
  436. #elif UNITY_ANDROID && !UNITY_EDITOR
  437. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  438. androidSupport.callCustomPlugin(gameRoleInfo.gameRoleID, gameRoleInfo.gameRoleName, gameRoleInfo.serverName, gameRoleInfo.vipLevel);
  439. #endif
  440. }
  441. public void callSDKShare(ShareInfo shareInfo){
  442. #if UNITY_IOS && !UNITY_EDITOR
  443. #elif UNITY_ANDROID && !UNITY_EDITOR
  444. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  445. androidSupport.callSDKShare(shareInfo.title, shareInfo.content, shareInfo.imgPath, shareInfo.imgUrl,shareInfo.url,shareInfo.type,shareInfo.shareTo,shareInfo.extenal);
  446. #endif
  447. }
  448. private int enterCustomerCenter() ////客服
  449. {
  450. #if UNITY_IOS && !UNITY_EDITOR
  451. return (quicksdk_nativeEnterCustomerCenter() == -100?0:1);
  452. #elif UNITY_ANDROID && !UNITY_EDITOR
  453. return 0;
  454. #else
  455. return 0;
  456. #endif
  457. }
  458. private String enterBBS()//BBS
  459. {
  460. #if UNITY_IOS && !UNITY_EDITOR
  461. return (quicksdk_nativeEnterBBS() == -100?"0":"1");
  462. #elif UNITY_ANDROID && !UNITY_EDITOR
  463. QuickUnitySupportAndroid androidSupport = QuickUnitySupportAndroid.getInstance();
  464. return androidSupport.callFunc(FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS);
  465. #else
  466. return "0";
  467. #endif
  468. }
  469. #if UNITY_IOS && !UNITY_EDITOR
  470. [DllImport("__Internal")]
  471. private static extern void quicksdk_nativeSetListener(string gameObjectName);
  472. [DllImport("__Internal")]
  473. private static extern void quicksdk_nativeLogin();
  474. [DllImport("__Internal")]
  475. private static extern void quicksdk_nativeLogout();
  476. [DllImport("__Internal")]
  477. private static extern void quicksdk_nativeRealNameAuth(int show);
  478. [DllImport("__Internal")]
  479. 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,
  480. string serverId, string serverName, string gameRoleName, string gameRoleId, string gameRoleBalance, string vipLevel, string gameRoleLevel, string partyName, string fightPower, string profession);
  481. [DllImport("__Internal")]
  482. private static extern IntPtr quicksdk_nativeUserId();
  483. [DllImport("__Internal")]
  484. private static extern void quicksdk_nativeUpdateRoleInfo(string serverId, string serverName, string gameRoleName, string gameRoleId, string gameRoleBalance, string vipLevel, string gameRoleLevel, string partyName, string roleCreateTime, string fightPower, string profession, bool isCreate);
  485. [DllImport("__Internal")]
  486. private static extern void quicksdk_nativeEnterYunKeFuCenter(string gameRoleID, string gameRoleName, string serverName, string vipLevel);
  487. [DllImport("__Internal")]
  488. private static extern int quicksdk_nativeEnterUserCenter();
  489. [DllImport("__Internal")]
  490. private static extern int quicksdk_nativeEnterCustomerCenter();
  491. [DllImport("__Internal")]
  492. private static extern int quicksdk_nativeEnterBBS();
  493. [DllImport("__Internal")]
  494. private static extern int quicksdk_nativeShowToolBar(int place);
  495. [DllImport("__Internal")]
  496. private static extern int quicksdk_nativeHideToolBar();
  497. [DllImport("__Internal")]
  498. private static extern int quicksdk_nativePausedGame();
  499. [DllImport("__Internal")]
  500. private static extern bool quicksdk_nativeIsFunctionTypeSupported(int type);
  501. [DllImport("__Internal")]
  502. private static extern IntPtr quicksdk_nativeChannelName();
  503. [DllImport("__Internal")]
  504. private static extern IntPtr quicksdk_nativeChannelVersion();
  505. [DllImport("__Internal")]
  506. private static extern int quicksdk_nativeChannelType();
  507. [DllImport("__Internal")]
  508. private static extern IntPtr quicksdk_nativeSDKVersion();
  509. [DllImport("__Internal")]
  510. private static extern IntPtr quicksdk_nativeGetConfigValue(string key);
  511. #endif
  512. }
  513. #if UNITY_ANDROID && !UNITY_EDITOR
  514. public class QuickUnitySupportAndroid {
  515. AndroidJavaObject ao;
  516. private static QuickUnitySupportAndroid instance;
  517. private QuickUnitySupportAndroid() {
  518. AndroidJavaClass ac = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  519. ao = ac.GetStatic<AndroidJavaObject>("currentActivity");
  520. }
  521. public static QuickUnitySupportAndroid getInstance()
  522. {
  523. if (instance == null)
  524. {
  525. instance = new QuickUnitySupportAndroid();
  526. }
  527. return instance;
  528. }
  529. public void setListener(QuickSDKListener listener)
  530. {
  531. Debug.Log("gameObject is " + listener.gameObject.name);
  532. if (listener == null)
  533. {
  534. Debug.LogError("set QuickSDKListener error, listener is null");
  535. return;
  536. }
  537. string gameObjectName = listener.gameObject.name;
  538. if (ao == null)
  539. {
  540. Debug.LogError("setListener error, current activity is null");
  541. }
  542. else
  543. {
  544. ao.Call("setUnityGameObjectName", gameObjectName);
  545. }
  546. }
  547. public void init()
  548. {
  549. ao.Call("requestInit");
  550. }
  551. public void showPrivace()
  552. {
  553. ao.Call("showPrivace");
  554. }
  555. public void exit()
  556. {
  557. ao.Call("requestExit");
  558. }
  559. public void login()
  560. {
  561. ao.Call("requestLogin");
  562. }
  563. public void logout()
  564. {
  565. ao.Call("requestLogout");
  566. }
  567. public void callCustomPlugin(String roleId,String roleName,String serverName,String vip)
  568. {
  569. ao.Call("requestCallCustomPlugin",roleId,roleName,serverName,vip);
  570. }
  571. public void callSDKShare(String title,String content,String imgPath,String imgUrl,String url,String type,String shareTo,String extenal)
  572. {
  573. ao.Call("requestCallSDKShare",title,content,imgPath,imgUrl,url,type,shareTo,extenal);
  574. }
  575. public void pay(OrderInfo orderInfo, GameRoleInfo gameRoleInfo)
  576. {
  577. if (orderInfo == null)
  578. {
  579. Debug.LogError("call pay error, orderInfo is null");
  580. return;
  581. }
  582. ao.Call("requestPay",
  583. orderInfo.goodsID, orderInfo.goodsName,
  584. orderInfo.goodsDesc, orderInfo.quantifier,
  585. orderInfo.cpOrderID, orderInfo.callbackUrl,
  586. orderInfo.extrasParams, orderInfo.price+"",
  587. orderInfo.amount + "", orderInfo.count+"",
  588. gameRoleInfo.serverName, gameRoleInfo.serverID,
  589. gameRoleInfo.gameRoleName, gameRoleInfo.gameRoleID,
  590. gameRoleInfo.gameRoleBalance, gameRoleInfo.vipLevel,
  591. gameRoleInfo.gameRoleLevel, gameRoleInfo.partyName, gameRoleInfo.roleCreateTime);
  592. }
  593. public string getUserId()
  594. {
  595. return ao.Call<string>("getUserId");
  596. }
  597. public string getDeviceId()
  598. {
  599. return ao.Call<string>("getDeviceID");
  600. }
  601. public void updateRoleInfo(GameRoleInfo gameRoleInfo, bool isCreate)
  602. {
  603. if (gameRoleInfo.Equals(null))
  604. {
  605. Debug.LogError("updateRoleInfo is error, gameRoleInfo is null");
  606. return;
  607. }
  608. string serverName = String.IsNullOrEmpty(gameRoleInfo.serverName) ? "" : gameRoleInfo.serverName;
  609. string serverId = String.IsNullOrEmpty(gameRoleInfo.serverID) ? "" : gameRoleInfo.serverID;
  610. string roleName = String.IsNullOrEmpty(gameRoleInfo.gameRoleName) ? "" : gameRoleInfo.gameRoleName;
  611. string roleId = String.IsNullOrEmpty(gameRoleInfo.gameRoleID) ? "" : gameRoleInfo.gameRoleID;
  612. string roleBalance = String.IsNullOrEmpty(gameRoleInfo.gameRoleBalance) ? "" : gameRoleInfo.gameRoleBalance;
  613. string vipLevel = String.IsNullOrEmpty(gameRoleInfo.vipLevel) ? "" : gameRoleInfo.vipLevel;
  614. string roleLevel = String.IsNullOrEmpty(gameRoleInfo.gameRoleLevel) ? "" : gameRoleInfo.gameRoleLevel;
  615. string partyName = String.IsNullOrEmpty(gameRoleInfo.partyName) ? "" : gameRoleInfo.partyName;
  616. string roleCreateTime = String.IsNullOrEmpty(gameRoleInfo.roleCreateTime) ? "" : gameRoleInfo.roleCreateTime;
  617. string gameRoleGender = String.IsNullOrEmpty(gameRoleInfo.gameRoleGender) ? "" : gameRoleInfo.gameRoleGender;
  618. string gameRolePower = String.IsNullOrEmpty(gameRoleInfo.gameRolePower) ? "" : gameRoleInfo.gameRolePower;
  619. string partyId = String.IsNullOrEmpty(gameRoleInfo.partyId) ? "" : gameRoleInfo.partyId;
  620. string professionId = String.IsNullOrEmpty(gameRoleInfo.professionId) ? "" : gameRoleInfo.professionId;
  621. string profession = String.IsNullOrEmpty(gameRoleInfo.profession) ? "" : gameRoleInfo.profession;
  622. string partyRoleId = String.IsNullOrEmpty(gameRoleInfo.partyRoleId) ? "" : gameRoleInfo.partyRoleId;
  623. string partyRoleName = String.IsNullOrEmpty(gameRoleInfo.partyRoleName) ? "" : gameRoleInfo.partyRoleName;
  624. string friendlist = String.IsNullOrEmpty(gameRoleInfo.friendlist) ? "" : gameRoleInfo.friendlist;
  625. ao.Call("requestUpdateRole",
  626. serverId,
  627. serverName,
  628. roleName,
  629. roleId,
  630. roleBalance,
  631. vipLevel,
  632. roleLevel,
  633. partyName,
  634. roleCreateTime,
  635. gameRoleGender,
  636. gameRolePower,
  637. partyId,
  638. professionId,
  639. profession,
  640. partyRoleId,
  641. partyRoleName,
  642. friendlist,
  643. isCreate + "");
  644. Debug.LogWarning("updateRoleInfo executed");
  645. }
  646. /**
  647. * return 0 success, -100 false or not support such function
  648. */
  649. public String callFunc(FuncType funcType)
  650. {
  651. int androidFuncType = 0;
  652. switch (funcType)
  653. {
  654. case FuncType.QUICK_SDK_FUNC_TYPE_UNDEFINED:
  655. // Do nothing
  656. break;
  657. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  658. androidFuncType = 101;
  659. break;
  660. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  661. androidFuncType = 102;
  662. break;
  663. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  664. androidFuncType = 103;
  665. break;
  666. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  667. androidFuncType = 104;
  668. break;
  669. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  670. androidFuncType = 105;
  671. break;
  672. case FuncType.QUICK_SDK_FUNC_TYPE_ANTI_ADDICTION_QUERY:
  673. androidFuncType = 106;
  674. break;
  675. case FuncType.QUICK_SDK_FUNC_TYPE_OPEN_FLOAT_CENTER:
  676. androidFuncType = 209;
  677. break;
  678. }
  679. // TODO
  680. return ao.Call<String>("callFunc", androidFuncType);
  681. }
  682. public String callFunc(FuncType funcType,string s)
  683. {
  684. int androidFuncType =(int) funcType;
  685. // TODO
  686. return ao.Call<String>("callFunc", androidFuncType,s);
  687. }
  688. public String callFuncWithResult(FuncType funcType)
  689. {
  690. int androidFuncType =(int) funcType;
  691. // TODO
  692. return ao.Call<String>("callFuncWithResult", androidFuncType);
  693. }
  694. public bool isFuncSupport(FuncType funcType)
  695. {
  696. int androidFuncType = 0;
  697. switch (funcType)
  698. {
  699. case FuncType.QUICK_SDK_FUNC_TYPE_UNDEFINED:
  700. // Do nothing
  701. break;
  702. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_BBS:
  703. androidFuncType = 101;
  704. break;
  705. case FuncType.QUICK_SDK_FUNC_TYPE_ENTER_USER_CENTER:
  706. androidFuncType = 102;
  707. break;
  708. case FuncType.QUICK_SDK_FUNC_TYPE_SHOW_TOOLBAR:
  709. androidFuncType = 103;
  710. break;
  711. case FuncType.QUICK_SDK_FUNC_TYPE_HIDE_TOOLBAR:
  712. androidFuncType = 104;
  713. break;
  714. case FuncType.QUICK_SDK_FUNC_TYPE_REAL_NAME_REGISTER:
  715. androidFuncType = 105;
  716. break;
  717. case FuncType.QUICK_SDK_FUNC_TYPE_ANTI_ADDICTION_QUERY:
  718. androidFuncType = 106;
  719. break;
  720. }
  721. return ao.Call<bool>("isFuncSupport", androidFuncType);
  722. }
  723. public string getChannelName()
  724. {
  725. return ao.Call<string>("getChannelName");
  726. }
  727. public string getChannelVersion()
  728. {
  729. return ao.Call<string>("getChannelVersion");
  730. }
  731. public string getOaid()
  732. {
  733. return ao.Call<string>("getOaid");
  734. }
  735. public int getChannelType()
  736. {
  737. return ao.Call<int>("getChannelType");
  738. }
  739. public string getSDKVersion()
  740. {
  741. return ao.Call<string>("getSDKVersion");
  742. }
  743. public string getParentChannelType()
  744. {
  745. return ao.Call<string>("getParentChannelType");
  746. }
  747. public string getConfigValue(string key)
  748. {
  749. if (String.IsNullOrEmpty(key))
  750. {
  751. return null;
  752. }
  753. return ao.Call<string>("getConfigValue", key);
  754. }
  755. public bool isChannelHasExitDialog()
  756. {
  757. return ao.Call<bool>("isChannelHasExitDialog");
  758. }
  759. public void exitGame()
  760. {
  761. ao.Call("exitGame");
  762. }
  763. public int callFunctionWithParams(int funcType, String[] param)
  764. {
  765. return ao.Call<int>("callFunctionWithParams",funcType,param);
  766. }
  767. }
  768. #endif
  769. }