QDDouYouManager.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using ET;
  3. using UnityEngine;
  4. using GFGGame.Launcher;
  5. namespace GFGGame
  6. {
  7. public class QDDouYouManager : SingletonBase<QDDouYouManager>
  8. {
  9. public bool isLogining;
  10. public string uid;
  11. public string token;
  12. public void Init()
  13. {
  14. Debug.Log("实例化DouYouSDKListener");
  15. QDDouYouManagerInit.Instance.douYouSDKListener = new DouYouSDKListener();
  16. }
  17. public void Login()
  18. {
  19. // if (!string.IsNullOrEmpty(uid))
  20. // {
  21. // EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, uid);
  22. // return;
  23. // }
  24. // if (isLogining) return;
  25. // Debug.Log($"quick Login");
  26. // isLogining = true;
  27. QDDouYouManagerInit.Instance.ShowLogin();
  28. }
  29. public void OnCreateRole()
  30. {
  31. var zoneScene = GameGlobal.zoneScene;
  32. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  33. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  34. QDDouYouManagerInit.Instance.ReportRole((int)DouYouRoleLogReportType.CreateRole,
  35. roleInfo.Id.ToString(), 1.ToString(), roleInfo.Name, roleInfo.ServerId.ToString(),
  36. serverName);
  37. }
  38. public void OnEnterGame()
  39. {
  40. Debug.Log($"DouYou OnEnterGame");
  41. var zoneScene = GameGlobal.zoneScene;
  42. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  43. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  44. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  45. QDDouYouManagerInit.Instance.ReportRoleLogin(roleInfo.Id.ToString(), lvl.ToString(), roleInfo.Name,
  46. roleInfo.ServerId.ToString(), serverName);
  47. QDDouYouManagerInit.Instance.ReportRole((int)DouYouRoleLogReportType.EnterGame,
  48. roleInfo.Id.ToString(), lvl.ToString(), roleInfo.Name, roleInfo.ServerId.ToString(), serverName);
  49. }
  50. public void OnQuitToLoginView()
  51. {
  52. Debug.Log($"DouYou OnQuitToLoginView");
  53. }
  54. public void Logout()
  55. {
  56. Debug.Log($"Game.HotUpdate DouYou Logout");
  57. QDDouYouManagerInit.Instance.ShowLogout();
  58. }
  59. public void LoginOutBefore()
  60. {
  61. var zoneScene = GameGlobal.zoneScene;
  62. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  63. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  64. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  65. QDDouYouManagerInit.Instance.ReportRole((int)DouYouRoleLogReportType.ExitGame,
  66. roleInfo.Id.ToString(), lvl.ToString(), roleInfo.Name, roleInfo.ServerId.ToString(),
  67. serverName);
  68. }
  69. public void Pay(int buyID, int count, string orderID, long price)
  70. {
  71. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyID);
  72. if (shopCfg == null)
  73. {
  74. Log.Error($"recharge {buyID} config not found!");
  75. return;
  76. }
  77. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  78. if (itemCfg == null)
  79. {
  80. Log.Error($"recharge {buyID} itemCfgId:{shopCfg.itemId} config not found!");
  81. return;
  82. }
  83. var zoneScene = GameGlobal.zoneScene;
  84. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  85. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  86. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  87. //自定义参数
  88. string other = orderID + "|gfg|" + roleInfo.Id;
  89. QDDouYouManagerInit.Instance.ShowSwitchPayment(orderID, price.ToString(), buyID.ToString(),
  90. shopCfg.itemName, itemCfg.desc,
  91. roleInfo.ServerId.ToString(), serverName, roleInfo.Id.ToString(), roleInfo.Name, lvl.ToString(), other);
  92. }
  93. public void Exit()
  94. {
  95. var zoneScene = GameGlobal.zoneScene;
  96. var roleInfo = zoneScene.GetComponent<RoleInfosComponent>().GetCurrentRole();
  97. int lvl = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  98. string serverName = zoneScene.GetComponent<ServerInfosComponent>().recentlyServerInfo.ServerName;
  99. QDDouYouManagerInit.Instance.ReportRole((int)DouYouRoleLogReportType.ExitGame,
  100. roleInfo.Id.ToString(), lvl.ToString(), roleInfo.Name, roleInfo.ServerId.ToString(),
  101. serverName);
  102. QDDouYouManagerInit.Instance.ExitApp();
  103. }
  104. }
  105. public class DouYouSDKListener : IDouYouSDKListener
  106. {
  107. // /// <summary>
  108. // /// 测试消息
  109. // /// </summary>
  110. // /// <param name="message"></param>
  111. // public void ReceiveMessageAb(string message)
  112. // {
  113. // Debug.Log($"Game.HotUpdate ReceiveMessageAb:{message}");
  114. // }
  115. // /// <summary>
  116. // /// SDK实例化成功
  117. // /// </summary>
  118. // /// <param name="message">SDK 实例化成功</param>
  119. // public void InitSuccessAb(string message)
  120. // {
  121. // Debug.Log("Game.HotUpdate InitSuccessAb: " + message);
  122. // //UniEvent.SendMessage(new LauncherEvent.InitPlatformResult() { success = true });
  123. // }
  124. /// <summary>
  125. /// 登录成功
  126. /// </summary>
  127. /// <param name="message">resUid + "|gfg|" + token</param>
  128. public void LoginSuccessAb(string message)
  129. {
  130. Debug.Log("Game.HotUpdate LoginSuccessAb: " + message);
  131. string[] result = message.Split(new string[] { "|gfg|" }, StringSplitOptions.None);
  132. QDDouYouManager.Instance.isLogining = false;
  133. QDDouYouManager.Instance.uid = result[0];
  134. QDDouYouManager.Instance.token = result[1];
  135. //登录成功的回调
  136. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, result[0]);
  137. }
  138. /// <summary>
  139. /// 切换账号或退出登录后
  140. /// </summary>
  141. /// <param name="message">退出登录成功!</param>
  142. public void OutLoginSuccessAb(string message)
  143. {
  144. Debug.Log("Game.HotUpdate OutLoginSuccessAb: " + message);
  145. GameController.QuitToLoginView(true);
  146. EventAgent.DispatchEvent(ConstMessage.OUT_LOGIN);
  147. }
  148. /// <summary>
  149. /// 支付失败
  150. /// </summary>
  151. /// <param name="message">code + "|gfg|" + params.toString()</param>
  152. public void PayFailAb(string message)
  153. {
  154. Debug.Log("Game.HotUpdate PayFailAb: " + message);
  155. //改变临时订单状态为失败
  156. }
  157. /// <summary>
  158. /// 支付成功
  159. /// </summary>
  160. /// <param name="message">code + "|gfg|" + params.toString()</param>
  161. public void PaySuccessAb(string message)
  162. {
  163. Debug.Log("Game.HotUpdate PaySuccessAb" + message);
  164. //改变临时订单状态为支付成功
  165. }
  166. #region SDK 生命周期函数
  167. public void SdkOnStartAb(string message)
  168. {
  169. Debug.Log($"Game.HotUpdate SdkOnStartAb:{message}");
  170. }
  171. // public void SdkOnPauseAb(string message)
  172. // {
  173. // Debug.Log($"Game.HotUpdate SdkOnPauseAb:{message}");
  174. // }
  175. // public void SdkOnResumeAb(string message)
  176. // {
  177. // Debug.Log($"Game.HotUpdate SdkOnResumeAb:{message}");
  178. // }
  179. public void SdkOnStopAb(string message)
  180. {
  181. Debug.Log($"Game.HotUpdate SdkOnStopAb:{message}");
  182. }
  183. public void SdkOnDestroyAb(string message)
  184. {
  185. Debug.Log($"Game.HotUpdate SdkOnDestroyAb:{message}");
  186. }
  187. public void SdkOnRestartAb(string message)
  188. {
  189. Debug.Log($"Game.HotUpdate SdkOnRestartAb:{message}");
  190. }
  191. public void SdkOnBackPressedAb(string message)
  192. {
  193. Debug.Log($"Game.HotUpdate SdkOnBackPressedAb:{message}");
  194. }
  195. public void SdkOnNewIntentAb(string message)
  196. {
  197. Debug.Log($"Game.HotUpdate SdkOnNewIntentAb:{message}");
  198. }
  199. public void SdkOnConfigurationChangedAb(string message)
  200. {
  201. Debug.Log($"Game.HotUpdate SdkOnConfigurationChangedAb:{message}");
  202. }
  203. public void SdkOnSaveInstanceStateAb(string message)
  204. {
  205. Debug.Log($"Game.HotUpdate SdkOnSaveInstanceStateAb:{message}");
  206. }
  207. public void SdkOnActivityResultAb(string message)
  208. {
  209. Debug.Log($"Game.HotUpdate SdkOnActivityResultAb:{message}");
  210. }
  211. // public void SdkOnRequestPermissionResultAb(string message)
  212. // {
  213. // Debug.Log($"Game.HotUpdate SdkOnRequestPermissionResultAb:{message}");
  214. // }
  215. // public void SdkOnWindowFocusChangedAb(string message)
  216. // {
  217. // Debug.Log($"Game.HotUpdate SdkOnWindowFocusChangedAb:{message}");
  218. // }
  219. #endregion
  220. }
  221. }