SDKManagerNew.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace FrameWork.SDKManager
  6. {
  7. public static class SDKManagerNew
  8. {
  9. const string c_callBackObjectName = "CallBackObject";
  10. static bool isInit = false;
  11. static SDKCallBackListener s_callBackListener;
  12. static Dictionary<string, OtherCallBack> s_callBackDict = new Dictionary<string, OtherCallBack>();
  13. #region 外部调用
  14. #region 初始化
  15. /// <summary>
  16. /// 初始化
  17. /// </summary>
  18. public static void Init()
  19. {
  20. if(!isInit)
  21. {
  22. GameObject go = new GameObject(c_callBackObjectName);
  23. s_callBackListener = go.AddComponent<SDKCallBackListener>();
  24. s_callBackListener.sdkCallBack = OnSDKCallBack;
  25. Dictionary<string, string> data = new Dictionary<string, string>();
  26. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Init);
  27. data.Add(SDKInterfaceDefine.ListenerName, c_callBackObjectName);
  28. Call(data);
  29. isInit = true;
  30. ApplicationManager.s_OnApplicationQuit += OnAppplicationQuit;
  31. }
  32. }
  33. public static void Dispose()
  34. {
  35. if(isInit)
  36. {
  37. Dictionary<string, string> data = new Dictionary<string, string>();
  38. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Dispose);
  39. Call(data);
  40. s_callBackListener.sdkCallBack = null;
  41. GameObject.Destroy(s_callBackListener.gameObject);
  42. s_callBackListener = null;
  43. isInit = false;
  44. }
  45. }
  46. #endregion
  47. #region 登录
  48. /// <summary>
  49. /// 登陆,默认访问第一个接口
  50. /// </summary>
  51. public static void Login()
  52. {
  53. Dictionary<string, string> data = new Dictionary<string, string>();
  54. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Login);
  55. data.Add(SDKInterfaceDefine.Login_ParameterName_Device, Application.identifier);
  56. Call(data);
  57. }
  58. /// <summary>
  59. /// 登陆
  60. /// </summary>
  61. public static void Login(string SDKName,string tag)
  62. {
  63. Dictionary<string, string> data = new Dictionary<string, string>();
  64. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Login);
  65. data.Add(SDKInterfaceDefine.Login_ParameterName_Device, SystemInfo.deviceUniqueIdentifier);
  66. data.Add(SDKInterfaceDefine.SDKName, SDKName);
  67. data.Add(SDKInterfaceDefine.Tag, tag);
  68. Call(data);
  69. }
  70. public static List<LoginPlatform> GetSupportLoginPlatform()
  71. {
  72. #if UNITY_EDITOR
  73. return new List<LoginPlatform>();
  74. #elif UNITY_ANDROID
  75. if (androidInterface == null)
  76. {
  77. androidInterface = new AndroidJavaClass("sdkInterface.SdkInterface");
  78. }
  79. string result = androidInterface.CallStatic<String>("GetSupportLoginPlatform");
  80. if(string.IsNullOrEmpty(result))
  81. {
  82. return new List<LoginPlatform>();
  83. }
  84. else
  85. {
  86. string[] strs = result.Split('|');
  87. List<LoginPlatform> list = new List<LoginPlatform>();
  88. for (int i = 0; i < strs.Length; i++)
  89. {
  90. try
  91. {
  92. list.Add((LoginPlatform)Enum.Parse(typeof(LoginPlatform), strs[i]));
  93. }
  94. catch (Exception e)
  95. {
  96. Debug.LogError("SDKManagerNew GetSupportLoginPlatform error:" + e.ToString());
  97. }
  98. }
  99. return list;
  100. }
  101. #elif UNITY_IOS
  102. return new List<LoginPlatform>();
  103. #endif
  104. }
  105. #endregion
  106. #region 支付
  107. /// <summary>
  108. /// 支付,默认访问第一个接口
  109. /// </summary>
  110. public static void Pay(PayInfo payInfo)
  111. {
  112. Pay(null, payInfo);
  113. }
  114. /// <summary>
  115. /// 支付,默认访问第一个接口
  116. /// </summary>
  117. public static void Pay(string SDKName, PayInfo payInfo)
  118. {
  119. Dictionary<string, string> data = new Dictionary<string, string>();
  120. if (SDKName != null)
  121. {
  122. data.Add(SDKInterfaceDefine.SDKName, SDKName);
  123. }
  124. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Pay); //支付不传FunctionName
  125. data.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsID, payInfo.goodsID);
  126. data.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsType, payInfo.goodsType.ToString());
  127. data.Add(SDKInterfaceDefine.Pay_ParameterName_OrderID, payInfo.orderID);
  128. data.Add(SDKInterfaceDefine.Pay_ParameterName_Price, payInfo.price.ToString());
  129. data.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsName, payInfo.goodsName.ToString());
  130. data.Add(SDKInterfaceDefine.Pay_ParameterName_Currency, payInfo.currency);
  131. data.Add(SDKInterfaceDefine.Tag, payInfo.tag);
  132. Call(data);
  133. }
  134. #endregion
  135. #region 广告
  136. /// <summary>
  137. /// 加载广告,默认访问第一个接口
  138. /// </summary>
  139. public static void LoadAD(ADType adType, string tag = "")
  140. {
  141. }
  142. /// <summary>
  143. /// 加载广告,默认访问第一个接口
  144. /// </summary>
  145. public static void LoadAD(string SDKName,ADType adType, string tag = "")
  146. {
  147. }
  148. /// <summary>
  149. /// 显示广告
  150. /// </summary>
  151. public static void PlayAD(ADType adType, string tag = "")
  152. {
  153. }
  154. /// <summary>
  155. /// 显示广告
  156. /// </summary>
  157. public static void PlayAD(string SDKName, ADType adType, string tag = "")
  158. {
  159. }
  160. /// <summary>
  161. /// 隐藏广告
  162. /// </summary>
  163. /// <param name="adType"></param>
  164. public static void CloseAD(ADType adType, string tag = "")
  165. {
  166. }
  167. /// <summary>
  168. /// 隐藏广告
  169. /// </summary>
  170. /// <param name="adType"></param>
  171. public static void CloseAD(string SDKName, ADType adType, string tag = "")
  172. {
  173. }
  174. /// <summary>
  175. /// 隐藏广告
  176. /// </summary>
  177. /// <param name="adType"></param>
  178. public static void CloseAD<T>(string SDKName, ADType adType, string tag = "") where T : ADInterface
  179. {
  180. }
  181. #endregion
  182. #region 数据上报
  183. public static void Log(string eventID, Dictionary<string, string> data = null)
  184. {
  185. Log(eventID, null, data);
  186. }
  187. public static void Log(string eventID, string label, Dictionary<string, string> data = null)
  188. {
  189. Dictionary<string, string> msg = new Dictionary<string, string>();
  190. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  191. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_Event);
  192. msg.Add(SDKInterfaceDefine.Log_ParameterName_EventID, eventID);
  193. msg.Add(SDKInterfaceDefine.Log_ParameterName_EventLabel, label);
  194. if (data != null)
  195. {
  196. msg.Add(SDKInterfaceDefine.Log_ParameterName_EventMap, Json.Serialize(data));
  197. }
  198. Call(msg);
  199. }
  200. public static void LogLogin(string accountId, Dictionary<string, string> data = null)
  201. {
  202. Dictionary<string, string> msg = new Dictionary<string, string>();
  203. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  204. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_Login);
  205. msg.Add(SDKInterfaceDefine.Log_ParameterName_AccountId, accountId);
  206. if (data != null)
  207. {
  208. msg.Add(SDKInterfaceDefine.Log_ParameterName_EventMap, Json.Serialize(data));
  209. }
  210. Call(msg);
  211. }
  212. public static void LogLoginOut(string AccountId, Dictionary<string, string> data = null)
  213. {
  214. Dictionary<string, string> msg = new Dictionary<string, string>();
  215. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  216. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_LoginOut);
  217. msg.Add(SDKInterfaceDefine.Log_ParameterName_AccountId, AccountId);
  218. if (data != null)
  219. {
  220. msg.Add(SDKInterfaceDefine.Log_ParameterName_EventMap, Json.Serialize(data));
  221. }
  222. Call(msg);
  223. }
  224. public static void LogPay(string orderID, string goodsID,int count, float price, string currency, string payment)
  225. {
  226. Dictionary<string, string> msg = new Dictionary<string, string>();
  227. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  228. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_LogPay);
  229. msg.Add(SDKInterfaceDefine.Pay_ParameterName_OrderID, orderID);
  230. msg.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsID, goodsID);
  231. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Price, price.ToString());
  232. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Currency, currency);
  233. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Payment, payment);
  234. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Count, count.ToString());
  235. Call(msg);
  236. }
  237. public static void LogPaySuccess(string orderID)
  238. {
  239. Dictionary<string, string> msg = new Dictionary<string, string>();
  240. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  241. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_LogPaySuccess);
  242. msg.Add(SDKInterfaceDefine.Pay_ParameterName_OrderID, orderID);
  243. Call(msg);
  244. }
  245. //以下三个配合使用,用于追踪虚拟物品的产出消耗
  246. public static void LogRewardVirtualCurrency(float count, string reason)
  247. {
  248. Dictionary<string, string> msg = new Dictionary<string, string>();
  249. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  250. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_RewardVirtualCurrency);
  251. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Count, count.ToString());
  252. msg.Add(SDKInterfaceDefine.Log_ParameterName_RewardReason, reason);
  253. Call(msg);
  254. }
  255. public static void LogPurchaseVirtualCurrency(string goodsID, int num, float price)
  256. {
  257. Dictionary<string, string> msg = new Dictionary<string, string>();
  258. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  259. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_PurchaseVirtualCurrency);
  260. msg.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsID, goodsID);
  261. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Count, num.ToString());
  262. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Price, price.ToString());
  263. Call(msg);
  264. }
  265. public static void LogUseItem(string goodsID, int num)
  266. {
  267. Dictionary<string, string> msg = new Dictionary<string, string>();
  268. msg.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Log);
  269. msg.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Log_FunctionName_UseItem);
  270. msg.Add(SDKInterfaceDefine.Pay_ParameterName_GoodsID, goodsID);
  271. msg.Add(SDKInterfaceDefine.Pay_ParameterName_Count, num.ToString());
  272. Call(msg);
  273. }
  274. #endregion
  275. #region 其他
  276. public static void Exit()
  277. {
  278. Dictionary<string, string> data = new Dictionary<string, string>();
  279. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Other);
  280. data.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Other_FunctionName_Exit);
  281. Call(data);
  282. }
  283. public static void ToClipboard(String content)
  284. {
  285. Dictionary<string, string> data = new Dictionary<string, string>();
  286. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Other);
  287. data.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Other_FunctionName_CopyToClipboard);
  288. data.Add(SDKInterfaceDefine.Other_ParameterName_Content, content);
  289. Call(data);
  290. }
  291. public static void DownloadApk(string url = null)
  292. {
  293. Dictionary<string, string> data = new Dictionary<string, string>();
  294. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Other);
  295. data.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Other_FunctionName_DownloadAPK);
  296. if(url != null)
  297. {
  298. data.Add(SDKInterfaceDefine.Other_ParameterName_DownloadURL, url);
  299. }
  300. Call(data);
  301. }
  302. public static void GetAPKSize(string url = null)
  303. {
  304. Dictionary<string, string> data = new Dictionary<string, string>();
  305. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_Other);
  306. data.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.Other_FunctionName_GetAPKSize);
  307. if (url != null)
  308. {
  309. data.Add(SDKInterfaceDefine.Other_ParameterName_DownloadURL, url);
  310. }
  311. Call(data);
  312. }
  313. #region 事件监听
  314. public static void AddOtherCallBackListener(string functionName,OtherCallBack callBack)
  315. {
  316. if(s_callBackDict.ContainsKey(functionName))
  317. {
  318. s_callBackDict[functionName] += callBack;
  319. }
  320. else
  321. {
  322. s_callBackDict.Add(functionName, callBack);
  323. }
  324. }
  325. public static void RemoveOtherCallBackListener(string functionName, OtherCallBack callBack)
  326. {
  327. if (s_callBackDict.ContainsKey(functionName))
  328. {
  329. s_callBackDict[functionName] -= callBack;
  330. }
  331. else
  332. {
  333. Debug.LogError("RemoveOtherCallBackListener 不存在的 function Name ->" + functionName + "<-");
  334. }
  335. }
  336. #endregion
  337. #endregion 特殊回调
  338. static void OnAppplicationQuit()
  339. {
  340. Dictionary<string, string> data = new Dictionary<string, string>();
  341. data.Add(SDKInterfaceDefine.ModuleName, SDKInterfaceDefine.ModuleName_LifeCycle);
  342. data.Add(SDKInterfaceDefine.FunctionName, SDKInterfaceDefine.LifeCycle_FunctionName_OnApplicationQuit);
  343. Call(data);
  344. }
  345. #region
  346. #endregion
  347. #endregion
  348. #region 回调接口
  349. static void OnSDKCallBack(Dictionary<string, string> data)
  350. {
  351. string mouduleName = data[SDKInterfaceDefine.ModuleName];
  352. switch (mouduleName)
  353. {
  354. case SDKInterfaceDefine.ModuleName_Debug:
  355. OnDebug(data);
  356. break;
  357. case SDKInterfaceDefine.ModuleName_Login:
  358. OnLogin(data);
  359. break;
  360. case SDKInterfaceDefine.ModuleName_Pay:
  361. OnPay(data);
  362. break;
  363. case SDKInterfaceDefine.ModuleName_AD:
  364. OnAD(data);
  365. break;
  366. case SDKInterfaceDefine.ModuleName_Log:
  367. OnLog(data);
  368. break;
  369. case SDKInterfaceDefine.ModuleName_Other:
  370. OnOther(data);
  371. break;
  372. }
  373. }
  374. #endregion
  375. #region SDK接口
  376. #if UNITY_EDITOR
  377. #elif UNITY_ANDROID
  378. static AndroidJavaClass androidInterface = null;
  379. #elif UNITY_IOS
  380. #endif
  381. static void Call(Dictionary<string, string> data)
  382. {
  383. try
  384. {
  385. #if UNITY_EDITOR
  386. //Debug.LogWarning("SDKManagerNew Call 目前是在 Editor 下运行 ->" + content);
  387. #elif UNITY_ANDROID
  388. string content = Serializer.Serialize(data);
  389. if (androidInterface == null)
  390. {
  391. androidInterface = new AndroidJavaClass("sdkInterface.SdkInterface");
  392. }
  393. if (androidInterface != null)
  394. {
  395. androidInterface.CallStatic("UnityRequestFunction", content);
  396. }
  397. #elif UNITY_IOS
  398. #endif
  399. }
  400. catch (Exception e)
  401. {
  402. Debug.LogError("SDKManagerNew Call Error " + e);
  403. }
  404. }
  405. #endregion
  406. #region 回调处理
  407. #region Debug
  408. static void OnDebug(Dictionary<string, string> data)
  409. {
  410. string functionName = data[SDKInterfaceDefine.FunctionName];
  411. string content = "SDKManagerNew "+ functionName + " : " + data[SDKInterfaceDefine.ParameterName_Content];
  412. switch(functionName)
  413. {
  414. case SDKInterfaceDefine.FunctionName_OnError:Debug.LogError(content);break;
  415. case SDKInterfaceDefine.FunctionName_OnLog: Debug.Log(content); break;
  416. }
  417. }
  418. #endregion
  419. #region Login
  420. //public static LoginCallBack OnLoginCallBack;
  421. static void OnLogin(Dictionary<string, string> data)
  422. {
  423. bool isSuccess = bool.Parse(data[SDKInterfaceDefine.ParameterName_IsSuccess]);
  424. string accountId = data[SDKInterfaceDefine.Login_ParameterName_AccountId];
  425. OnLoginInfo info = new OnLoginInfo();
  426. info.isSuccess = isSuccess;
  427. info.accountId = accountId;
  428. Debug.Log("SDKManagerNew OnLogin " + accountId);
  429. if (data.ContainsKey(SDKInterfaceDefine.Login_ParameterName_loginPlatform))
  430. {
  431. info.loginPlatform = (LoginPlatform)Enum.Parse(typeof(LoginPlatform), data[SDKInterfaceDefine.Login_ParameterName_loginPlatform]);
  432. }
  433. if (SDKManager.LoginCallBack != null)
  434. {
  435. try
  436. {
  437. SDKManager.LoginCallBack(info);
  438. }
  439. catch (Exception e)
  440. {
  441. Debug.LogError("OnLogin Error " + e.ToString());
  442. }
  443. }
  444. }
  445. #endregion
  446. #region Pay
  447. static void OnPay(Dictionary<string, string> data)
  448. {
  449. bool isSuccess = bool.Parse(data[SDKInterfaceDefine.ParameterName_IsSuccess]);
  450. StoreName storeName = (StoreName)Enum.Parse(typeof(StoreName), data[SDKInterfaceDefine.Pay_ParameterName_Payment]);
  451. string goodsId = data[SDKInterfaceDefine.Pay_ParameterName_GoodsID];
  452. string orderID = data[SDKInterfaceDefine.Pay_ParameterName_OrderID];
  453. string currency = data[SDKInterfaceDefine.Pay_ParameterName_Currency];
  454. string goodsName = data[SDKInterfaceDefine.Pay_ParameterName_GoodsName];
  455. string receipt = data[SDKInterfaceDefine.Pay_ParameterName_Receipt];
  456. float price = float.Parse(data[SDKInterfaceDefine.Pay_ParameterName_Price]);
  457. GoodsType goodsType =(GoodsType) Enum.Parse(typeof(GoodsType), data[SDKInterfaceDefine.Pay_ParameterName_GoodsType]);
  458. OnPayInfo info = new OnPayInfo();
  459. info.isSuccess = isSuccess;
  460. info.storeName = storeName;
  461. info.goodsId = goodsId;
  462. info.orderID = orderID;
  463. info.currency = currency;
  464. info.goodsName = goodsName;
  465. info.receipt = receipt;
  466. info.price = price;
  467. info.goodsType = goodsType;
  468. try
  469. {
  470. if(SDKManager.PayCallBack!= null)
  471. {
  472. SDKManager.PayCallBack(info);
  473. }
  474. }
  475. catch(Exception e)
  476. {
  477. Debug.LogError("OnPayCallBack Error" + e.ToString() + e.StackTrace);
  478. }
  479. }
  480. #endregion
  481. #region AD
  482. static void OnAD(Dictionary<string, string> data)
  483. {
  484. }
  485. #endregion
  486. #region Log
  487. static void OnLog(Dictionary<string, string> data)
  488. {
  489. }
  490. #endregion
  491. #region Other
  492. static void OnOther(Dictionary<string, string> data)
  493. {
  494. OnOtherInfo info = new OnOtherInfo();
  495. info.data = data;
  496. string functionName = data[SDKInterfaceDefine.FunctionName];
  497. DispatchOtherCallBack(functionName, info);
  498. }
  499. static void DispatchOtherCallBack(string functionName, OnOtherInfo info)
  500. {
  501. if(s_callBackDict.ContainsKey(functionName))
  502. {
  503. try
  504. {
  505. if (s_callBackDict[functionName] != null)
  506. {
  507. s_callBackDict[functionName](info);
  508. }
  509. }
  510. catch (Exception e)
  511. {
  512. Debug.LogError("DispatchOtherCallBack Error " + e.ToString());
  513. }
  514. }
  515. }
  516. public static string GetProperties(string properties, string key, string defaultValue)
  517. {
  518. #if UNITY_EDITOR
  519. return defaultValue;
  520. #elif UNITY_ANDROID
  521. try
  522. {
  523. if (androidInterface == null)
  524. {
  525. androidInterface = new AndroidJavaClass("sdkInterface.SdkInterface");
  526. }
  527. if (androidInterface != null)
  528. {
  529. return androidInterface.CallStatic<string>("GetProperties", properties, key, defaultValue);
  530. }
  531. else
  532. {
  533. return defaultValue;
  534. }
  535. }
  536. catch(Exception e)
  537. {
  538. Debug.LogError("GetProperties Error:" + e.ToString());
  539. return defaultValue;
  540. }
  541. #else
  542. return defaultValue;
  543. #endif
  544. }
  545. #endregion
  546. #endregion
  547. }
  548. #region 声明
  549. public class SDKCallBackListener : MonoBehaviour
  550. {
  551. Deserializer deserializer = new Deserializer();
  552. public CallBack<Dictionary<string, string>> sdkCallBack;
  553. public void OnSDKCallBack(string str)
  554. {
  555. Dictionary<string, string> data = deserializer.Deserialize<Dictionary<string, string>>(str);
  556. sdkCallBack(data);
  557. }
  558. }
  559. public struct OnPayInfo
  560. {
  561. //必填
  562. public bool isSuccess;
  563. public string goodsId;
  564. public string orderID;
  565. public StoreName storeName;
  566. public string goodsName;
  567. public float price;
  568. public string currency; //货币类型
  569. public string receipt; //支付回执
  570. //选填
  571. public GoodsType goodsType;
  572. }
  573. public struct OnADInfo
  574. {
  575. public ADType aDType;
  576. public string tag;
  577. }
  578. public struct OnLoginInfo
  579. {
  580. public bool isSuccess;
  581. public string accountId;
  582. public string nickName;
  583. public string headPortrait;
  584. public string password;
  585. public LoginPlatform loginPlatform;
  586. public LoginErrorEnum error;
  587. }
  588. public struct OnOtherInfo
  589. {
  590. public Dictionary<string, string> data;
  591. }
  592. public enum GoodsType
  593. {
  594. NORMAL, //可以反复购买的商品
  595. ONCE_ONLY, //只能购买一次的商品
  596. RIGHTS, //购买持续一段时间的商品,例如会员
  597. }
  598. public enum LoginErrorEnum
  599. {
  600. None,
  601. GameCenterNotOpen,
  602. /// <summary>
  603. /// 没有安装相应的app
  604. /// </summary>
  605. NoInstallApp,
  606. }
  607. public struct PayInfo
  608. {
  609. public string goodsID;
  610. public string goodsName;
  611. public string tag;
  612. public GoodsType goodsType ;
  613. public string orderID ;
  614. public float price ;
  615. public string currency; //货币类型
  616. public PayInfo(string goodsID, string goodsName, string tag, GoodsType goodsType, string orderID, float price,string currency)
  617. {
  618. this.goodsID = goodsID;
  619. this.goodsName = goodsName;
  620. this.tag = tag;
  621. this.goodsType = goodsType;
  622. this.orderID = orderID;
  623. this.price = price;
  624. this.currency = currency;
  625. }
  626. }
  627. #endregion
  628. }