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