QDJGameManager.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using System;
  2. using System.Collections.Generic;
  3. using cfg.GfgCfg;
  4. using ET;
  5. using UnityEngine;
  6. using GFGGame.Launcher;
  7. namespace GFGGame
  8. {
  9. public class QDJGameManager : SingletonBase<QDJGameManager>
  10. {
  11. public bool isLogining;
  12. public string uid;
  13. public string token;
  14. public string UserId;
  15. public string UserName;
  16. public string Uuid;
  17. public string Sign;
  18. public string Timestamp;
  19. public string CpExt;
  20. public void Init()
  21. {
  22. Debug.Log("实例化JHGameSDKListener");
  23. QDJHGameManagerInit.Instance._jhGameSDKListener = new JHGameSDKListener();
  24. string url = Application.absoluteURL;
  25. Dictionary<string, object> sdkParams = WebUrlUtil.ParseSDKParamsFromUrl(url);
  26. UserId = sdkParams["user_id"].ToString();
  27. UserName = sdkParams["user_name"].ToString();
  28. Uuid = sdkParams["uuid"].ToString();
  29. Sign = sdkParams["sign"].ToString();
  30. Timestamp = sdkParams["timestamp"].ToString();
  31. CpExt = sdkParams["cp_ext"].ToString();
  32. }
  33. public void Login()
  34. {
  35. // if (!string.IsNullOrEmpty(uid))
  36. // {
  37. // EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, uid);
  38. // return;
  39. // }
  40. // if (isLogining) return;
  41. // Debug.Log($"quick Login");
  42. // isLogining = true;
  43. QDJHGameManagerInit.Instance.ShowLogin();
  44. }
  45. public void OnCreateRole()
  46. {
  47. QDManager.PushRoleAction(DouYouRoleLogReportType.CreateRole);
  48. }
  49. public void OnEnterGame()
  50. {
  51. var zoneScene = GameGlobal.zoneScene;
  52. if (zoneScene == null) return;
  53. if (zoneScene.GetComponent<RoleInfosComponent>() == null ||
  54. zoneScene.GetComponent<RoleInfosComponent>().IsDisposed) return;
  55. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  56. if (roleInfo == null) return;
  57. if (GameGlobal.myNumericComponent == null) return;
  58. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  59. if (zoneScene.GetComponent<ServerInfosComponent>() == null) return;
  60. if (zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo == null) return;
  61. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  62. QDJHGameManagerInit.Instance.ReportRoleLogin(roleInfo.Id.ToString(), lvl.ToString(), roleInfo.Name,
  63. roleInfo.ServerId.ToString(), serverName);
  64. QDManager.PushRoleAction(DouYouRoleLogReportType.EnterGame);
  65. }
  66. public void OnQuitToLoginView()
  67. {
  68. Debug.Log($"DouYou OnQuitToLoginView");
  69. }
  70. public void Logout()
  71. {
  72. Debug.Log($"Game.HotUpdate DouYou Logout");
  73. QDJHGameManagerInit.Instance.ShowLogout();
  74. }
  75. public void LoginOutBefore()
  76. {
  77. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  78. }
  79. public void Pay(int buyID, int count, string orderID, long price)
  80. {
  81. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(buyID);
  82. if (shopCfg == null)
  83. {
  84. Log.Error($"recharge {buyID} config not found!");
  85. return;
  86. }
  87. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  88. if (itemCfg == null)
  89. {
  90. Log.Error($"recharge {buyID} itemCfgId:{shopCfg.ItemId} config not found!");
  91. return;
  92. }
  93. var zoneScene = GameGlobal.zoneScene;
  94. if (zoneScene == null) return;
  95. if (zoneScene.GetComponent<RoleInfosComponent>() == null ||
  96. zoneScene.GetComponent<RoleInfosComponent>().IsDisposed) return;
  97. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  98. if (roleInfo == null) return;
  99. if (GameGlobal.myNumericComponent == null) return;
  100. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  101. if (zoneScene.GetComponent<ServerInfosComponent>() == null) return;
  102. if (zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo == null) return;
  103. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  104. //自定义参数
  105. string other = orderID + "|gfg|" + roleInfo.Id;
  106. QDJHGameManagerInit.Instance.ShowSwitchPayment(orderID, price.ToString(), buyID.ToString(),
  107. shopCfg.ItemName, string.Empty,
  108. roleInfo.ServerId.ToString(), serverName, roleInfo.Id.ToString(), roleInfo.Name, lvl.ToString(), other);
  109. }
  110. public void Exit()
  111. {
  112. QDManager.PushRoleAction(DouYouRoleLogReportType.ExitGame);
  113. QDDouYouManagerInit.Instance.ExitApp();
  114. }
  115. }
  116. /// <summary>
  117. /// SDK回调
  118. /// </summary>
  119. public class JHGameSDKListener : IJHGameSDKListener
  120. {
  121. //通知Unity准备支付
  122. public void OnRechargeStartAb(string message)
  123. {
  124. }
  125. //支付完成后通知Unity
  126. public void OnRechargeCompleteAb(string message)
  127. {
  128. }
  129. //支付错误
  130. public void OnRechargeErrorAb(string message)
  131. {
  132. }
  133. //创建角色实例化完成
  134. public void OnCreateRoleStartAb(string message)
  135. {
  136. }
  137. //创建角色结果
  138. public void OnCreateRoleCompleteAb(string message)
  139. {
  140. }
  141. //创建角色错误
  142. public void OnCreateRoleErrorAb(string message)
  143. {
  144. }
  145. //角色登录实例化完成
  146. public void OnLoginRoleStartAb(string message)
  147. {
  148. }
  149. //角色登录结果
  150. public void OnLoginRoleCompleteAb(string message)
  151. {
  152. }
  153. //角色登录错误
  154. public void OnLoginRoleErrorAb(string message)
  155. {
  156. }
  157. //角色升级回调实例化完成
  158. public void OnUpgradeRoleStartAb(string message)
  159. {
  160. }
  161. public void OnUpgradeRoleCompleteAb(string message)
  162. {
  163. }
  164. public void OnUpgradeRoleErrorAb(string message)
  165. {
  166. }
  167. //顶号
  168. public void OnRepeatLoginStartAb(string message)
  169. {
  170. }
  171. public void OnRepeatLoginCompleteAb(string message)
  172. {
  173. }
  174. public void OnRepeatLoginErrorAb(string message)
  175. {
  176. }
  177. public void OnCallIcpBeianStartAb(string message)
  178. {
  179. }
  180. public void OnCallIcpBeianCompleteAb(string message)
  181. {
  182. }
  183. public void OnCallIcpBeianErrorAb(string message)
  184. {
  185. }
  186. /// <summary>
  187. /// 切换账号或退出登录后
  188. /// </summary>
  189. /// <param name="message">退出登录成功!</param>
  190. public void OutLoginSuccessAb(string message)
  191. {
  192. Debug.Log("Game.HotUpdate OutLoginSuccessAb: " + message);
  193. GameController.QuitToLoginView(true);
  194. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  195. }
  196. /// <summary>
  197. /// 支付失败
  198. /// </summary>
  199. /// <param name="message">code + "|gfg|" + params.toString()</param>
  200. public void PayFailAb(string message)
  201. {
  202. Debug.Log("Game.HotUpdate PayFailAb: " + message);
  203. //改变临时订单状态为失败
  204. }
  205. /// <summary>
  206. /// 支付成功
  207. /// </summary>
  208. /// <param name="message">code + "|gfg|" + params.toString()</param>
  209. public void PaySuccessAb(string message)
  210. {
  211. Debug.Log("Game.HotUpdate PaySuccessAb" + message);
  212. }
  213. }
  214. }