QKGame.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Runtime.InteropServices;
  4. //using Newtonsoft.Json;
  5. #if UNITY_IOS
  6. using System.Collections.Generic;
  7. namespace quicksdk
  8. {
  9. public enum QKSDKInitState
  10. {
  11. None,
  12. Initing,
  13. Success,
  14. Fail,
  15. }
  16. public class ProductInfo
  17. {
  18. public string ID;
  19. public string Name;
  20. public string CID;
  21. }
  22. public class QKGame
  23. {
  24. public static QKSDKInitState InitState = QKSDKInitState.None;
  25. public Dictionary<string, ProductInfo> ProductInfos = new Dictionary<string, ProductInfo>()
  26. {
  27. { "0.99",new ProductInfo(){ CID = "1",Name = "0.99禮包"} },
  28. { "1.99",new ProductInfo(){ CID = "2",Name = "1.99禮包"} },
  29. { "2.99",new ProductInfo(){ CID = "3",Name = "2.99禮包"} },
  30. { "4.99",new ProductInfo(){ CID = "4",Name = "4.99禮包"} },
  31. { "9.99",new ProductInfo(){ CID = "5",Name = "9.99禮包"} },
  32. { "14.99",new ProductInfo(){ CID = "6",Name = "14.99禮包"} },
  33. { "19.99",new ProductInfo(){ CID = "7",Name = "19.99禮包"} },
  34. { "49.99",new ProductInfo(){ CID = "8",Name = "49.99禮包"} },
  35. { "99.99",new ProductInfo(){ CID = "9",Name = "99.99禮包"} },
  36. };
  37. public void InitProductCfg(Dictionary<string, Dictionary<string, string>> cfg)
  38. {
  39. foreach (var item in ProductInfos)
  40. {
  41. Dictionary<string, string> keyValues;
  42. if (cfg.ContainsKey(item.Value.CID))
  43. {
  44. keyValues = cfg[item.Value.CID];
  45. item.Value.ID = keyValues["productID"];
  46. item.Value.Name = keyValues["productName"];
  47. }
  48. }
  49. }
  50. [DllImport("__Internal")]
  51. private static extern void LuluSetListener(string gameObjectName);
  52. public void loginKitSetListener(LoginKitListener listener)
  53. {
  54. Debug.Log("gameObject is " + listener.gameObject.name);
  55. if (listener == null)
  56. {
  57. Debug.LogError("set LoginKitListener error, listener is null");
  58. return;
  59. }
  60. if (Application.platform != RuntimePlatform.OSXEditor)
  61. {
  62. string gameObjectName = listener.gameObject.name;
  63. #if !UNITY_EDITOR
  64. LuluSetListener(gameObjectName);
  65. #endif
  66. }
  67. }
  68. [DllImport("__Internal")]
  69. private static extern void luLuInit();
  70. //init
  71. public static void txQKInit()
  72. {
  73. if (Application.platform != RuntimePlatform.OSXEditor || InitState == QKSDKInitState.None || InitState == QKSDKInitState.Fail)
  74. {
  75. InitState = QKSDKInitState.Initing;
  76. #if !UNITY_EDITOR
  77. luLuInit();
  78. #endif
  79. }
  80. }
  81. [DllImport("__Internal")]
  82. private static extern void luLuLogin(bool isShowMenu);
  83. //Login
  84. public static void txQKLogin(bool isShowMenu)
  85. {
  86. if (Application.platform != RuntimePlatform.OSXEditor)
  87. {
  88. luLuLogin(isShowMenu);
  89. }
  90. }
  91. [DllImport("__Internal")]
  92. private static extern void loginKitLoginWithType(int type);
  93. //Login
  94. public static void loginKitLoginWithType_Thread(int type)
  95. {
  96. if (Application.platform != RuntimePlatform.OSXEditor)
  97. {
  98. loginKitLoginWithType(type);
  99. }
  100. }
  101. [DllImport("__Internal")]
  102. private static extern void luLuFastStartGame();
  103. //Login
  104. public static void txQKFastStartGame()
  105. {
  106. if (Application.platform != RuntimePlatform.OSXEditor)
  107. {
  108. luLuFastStartGame();
  109. }
  110. }
  111. [DllImport("__Internal")]
  112. private static extern string luLuGetUserBindInfo();
  113. //luLuUserCenter
  114. //public static Dictionary<string, int> loginkitGetUserBindInfo()
  115. //{
  116. // if (Application.platform != RuntimePlatform.OSXEditor)
  117. // {
  118. // string jsonString = luLuGetUserBindInfo();
  119. // return JsonConvert.deserializeobject(jsonString);
  120. // }
  121. //}
  122. [DllImport("__Internal")]
  123. private static extern void luLuUserCenter();
  124. //luLuUserCenter
  125. public static void txQKCenter()
  126. {
  127. if (Application.platform != RuntimePlatform.OSXEditor)
  128. {
  129. luLuUserCenter();
  130. }
  131. }
  132. [DllImport("__Internal")]
  133. private static extern void luLuLogout();
  134. //Logout
  135. public static void txQKLogout()
  136. {
  137. if (Application.platform != RuntimePlatform.OSXEditor)
  138. {
  139. luLuLogout();
  140. }
  141. }
  142. [DllImport("__Internal")]
  143. private static extern void luLuBindAccount();
  144. //bindAccount
  145. public static void txQKBindAccount()
  146. {
  147. if (Application.platform != RuntimePlatform.OSXEditor)
  148. {
  149. luLuBindAccount();
  150. }
  151. }
  152. [DllImport("__Internal")]
  153. private static extern void luLuBindAccountWithType(int type);
  154. //bindAccountType
  155. public static void txQKBindAccountWithType(int type)
  156. {
  157. if (Application.platform != RuntimePlatform.OSXEditor)
  158. {
  159. luLuBindAccountWithType(type);
  160. }
  161. }
  162. [DllImport("__Internal")]
  163. private static extern void luLuUnbindAccountWithType(int type);
  164. //unbindAccountType
  165. public static void txQKUnbindAccountWithType(int type)
  166. {
  167. if (Application.platform != RuntimePlatform.OSXEditor)
  168. {
  169. luLuUnbindAccountWithType(type);
  170. }
  171. }
  172. [DllImport("__Internal")]
  173. private static extern void luLuAccountDeletion();
  174. //accountDeletion
  175. public static void txQKAccountDeletion()
  176. {
  177. if (Application.platform != RuntimePlatform.OSXEditor)
  178. {
  179. luLuAccountDeletion();
  180. }
  181. }
  182. [DllImport("__Internal")]
  183. private static extern void luLuShowMenu(float y);
  184. //luLuShowMenu
  185. public static void txQKShowMenu(float y)
  186. {
  187. if (Application.platform != RuntimePlatform.OSXEditor)
  188. {
  189. luLuShowMenu(y);
  190. }
  191. }
  192. [DllImport("__Internal")]
  193. private static extern void luLuDismissMenu();
  194. //luLuDismissMenu
  195. public static void txQKDismissMenu()
  196. {
  197. if (Application.platform != RuntimePlatform.OSXEditor)
  198. {
  199. luLuDismissMenu();
  200. }
  201. }
  202. [DllImport("__Internal")]
  203. private static extern void luluSetRoleInfo(string serverName, string serverId, string roleId, string roleName, string roleLevel, string roleVipLevel);
  204. //setRoleInfo,参数 游戏服名 游戏服id 角色名 角色id 角色等级 角色vip等级
  205. public static void txQKSetRoleInfo(string serverName, string serverId, string roleId, string roleName, string roleLevel, string roleVipLevel)
  206. {
  207. if (Application.platform != RuntimePlatform.OSXEditor)
  208. {
  209. luluSetRoleInfo(serverName, serverId, roleId, roleName, roleLevel, roleLevel);
  210. }
  211. }
  212. [DllImport("__Internal")]
  213. private static extern void luLuCongzi(string productId, string productName, string amount, string orderNo, string callBackUrl, string extrasParams);
  214. //Pay RMB,参数 苹果商品ID 商品名称 价格 游戏订单号 游戏收单服务器地址 透传参数
  215. public static void txQKCongzi(string productId, string productName, string amount, string orderNo, string callBackUrl, string extrasParams)
  216. {
  217. if (Application.platform != RuntimePlatform.OSXEditor)
  218. {
  219. luLuCongzi(productId, productName, amount, orderNo, callBackUrl, extrasParams);
  220. }
  221. }
  222. [DllImport("__Internal")]
  223. private static extern void luluRestoreNonConsumptionProducts();
  224. //lulurestoreNonConsumptionProducts
  225. public static void txQKRestoreNonConsumptionProducts()
  226. {
  227. if (Application.platform != RuntimePlatform.OSXEditor)
  228. {
  229. luluRestoreNonConsumptionProducts();
  230. }
  231. }
  232. [DllImport("__Internal")]
  233. private static extern void luluFindProductInfo(string productIds);
  234. //luLuDismissMenu
  235. public static void txQKFindProductInfo(List<string> goodsIds)
  236. {
  237. if (Application.platform != RuntimePlatform.OSXEditor)
  238. {
  239. luluFindProductInfo(string.Join(",", goodsIds.ToArray()));
  240. }
  241. }
  242. [DllImport("__Internal")]
  243. private static extern string LuluGetUserId();
  244. public string loginKitGetUserId()
  245. {
  246. if (Application.platform != RuntimePlatform.OSXEditor)
  247. {
  248. return LuluGetUserId();
  249. }
  250. return "";
  251. }
  252. [DllImport("__Internal")]
  253. private static extern string LuluGetDeviceId();
  254. public string loginKitGetDeviceId()
  255. {
  256. if (Application.platform != RuntimePlatform.OSXEditor)
  257. {
  258. return LuluGetDeviceId();
  259. }
  260. return "";
  261. }
  262. }
  263. }
  264. #endif