QDTapTapManager.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using ET;
  2. using TapTap.Bootstrap;
  3. using TapTap.Common;
  4. using TapTap.TapDB;
  5. using Plugins.AntiAddictionUIKit;
  6. using System;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. namespace GFGGame
  10. {
  11. public class QDTapTapManager : SingletonBase<QDTapTapManager>
  12. {
  13. private readonly string ClientID = "K7bDyPGYlVx2AAtk6q";
  14. public void InitSDK()
  15. {
  16. Log.Debug($"tap InitSDK");
  17. if (!QDManager.IsTaptap)
  18. {
  19. return;
  20. }
  21. var config = new TapConfig.Builder()
  22. .ClientID(ClientID)
  23. .ClientToken("fjwWBtibB4Dj3UjyRQxK2tZ3f8fGNgg14tcRW38D")
  24. .ServerURL("https://k7bdypgy.cloud.tds1.tapapis.cn")
  25. .RegionType(RegionType.CN)
  26. .TapDBConfig(true, "tap", null, true)
  27. .ConfigBuilder();
  28. TapBootstrap.Init(config);
  29. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  30. }
  31. public async Task Login()
  32. {
  33. Log.Debug($"tap login");
  34. if (!QDManager.IsTaptap)
  35. {
  36. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, null);
  37. return;
  38. }
  39. ViewManager.Show<ModalStatusView>("登录中...");
  40. TDSUser tdsUser = await TDSUser.GetCurrent();
  41. if (null != tdsUser)
  42. {
  43. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, tdsUser.ObjectId);
  44. InitAntiAddiction(tdsUser.ObjectId);
  45. return;
  46. }
  47. try
  48. {
  49. tdsUser = await TDSUser.LoginWithTapTap();
  50. Log.Debug($"tap login Success:{tdsUser}");
  51. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, tdsUser.ObjectId);
  52. InitAntiAddiction(tdsUser.ObjectId);
  53. }
  54. catch (Exception e)
  55. {
  56. if (e is TapException tapError)
  57. {
  58. if (tapError.code == (int)TapErrorCode.ERROR_CODE_BIND_CANCEL) // 取消登录
  59. {
  60. Log.Debug("登录取消");
  61. ViewManager.Hide<ModalStatusView>();
  62. return;
  63. }
  64. else
  65. {
  66. Log.Error($"Login Error:{tapError.code} message:{tapError.message}");
  67. PromptController.Instance.ShowFloatTextPrompt(tapError.message);
  68. }
  69. }
  70. else
  71. {
  72. Log.Error($"Login Error:{e}");
  73. PromptController.Instance.ShowFloatTextPrompt("登录异常");
  74. }
  75. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, null);
  76. }
  77. }
  78. public void InitAntiAddiction(string objectId)
  79. {
  80. Log.Debug($"tap InitAntiAddiction objectId {objectId}");
  81. ViewManager.Show<ModalStatusView>("登录中...");
  82. string gameIdentifier = ClientID;
  83. // 是否启用时长限制功能
  84. bool useTimeLimit = true;
  85. // 是否启用消费限制功能
  86. bool usePaymentLimit = false;
  87. // 是否显示切换账号按钮
  88. bool showSwitchAccount = true;
  89. AntiAddictionUIKit.Init(gameIdentifier, useTimeLimit, usePaymentLimit, showSwitchAccount,
  90. (antiAddictionCallbackData) =>
  91. {
  92. int code = antiAddictionCallbackData.code;
  93. MsgExtraParams extras = antiAddictionCallbackData.extras;
  94. Log.Debug($"tap antiAddictionCallbackData code {code} extras title \n{extras?.title} description \n{extras?.description}");
  95. ViewManager.Hide<ModalStatusView>();
  96. // 根据 code 不同提示玩家不同信息,详见下面的说明
  97. if (code == 500)
  98. {
  99. ET.Log.Debug("玩家登录后判断当前玩家可以进行游戏");
  100. }
  101. else if(code == 1030)
  102. {
  103. ET.Log.Debug("未成年玩家当前无法进行游戏");
  104. }
  105. else if (code == 1095)
  106. {
  107. ET.Log.Debug("未成年允许游戏弹窗");
  108. }
  109. else if (code == 1000)
  110. {
  111. ET.Log.Debug("退出账号");
  112. }
  113. else if (code == 9002)
  114. {
  115. ET.Log.Debug("实名过程中点击了关闭实名窗");
  116. AntiAddictionUIKit.Startup(true, objectId);
  117. }
  118. else if (code == 1001)
  119. {
  120. ET.Log.Debug("点击切换账号按钮(v1.0.2 新增)");
  121. GameController.QuitToLoginView(true);
  122. }
  123. },
  124. (exception) =>
  125. {
  126. // 处理异常
  127. Log.Debug($"tap exception {exception.ToString()}");
  128. }
  129. );
  130. AntiAddictionUIKit.Startup(true, objectId);
  131. }
  132. public void OnEnterGame()
  133. {
  134. Log.Debug($"tap OnEnterGame");
  135. if (!QDManager.IsTaptap)
  136. {
  137. return;
  138. }
  139. // 开始计时
  140. AntiAddictionUIKit.EnterGame();
  141. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  142. var accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  143. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  144. var currentRole = roleInfosComponent.GetCurrentRole();
  145. TapDB.SetUser(accountInfoComponent.Account);
  146. TapDB.SetName(currentRole.Name);
  147. TapDB.SetLevel(RoleDataManager.lvl);
  148. TapDB.SetServer(serverInfosComponent.GetCurrentServerInfo().ServerName);
  149. Log.Debug($"tap TapDB \nSetUser {accountInfoComponent.Account} \nSetName {currentRole.Name} \nSetLevel {RoleDataManager.lvl} \nSetServer {serverInfosComponent.GetCurrentServerInfo().ServerName}");
  150. }
  151. //回到登录界面,不退出账号
  152. public void OnQuitToLoginView()
  153. {
  154. Log.Debug($"tap OnQuitGame");
  155. TapDB.ClearUser();
  156. AntiAddictionUIKit.LeaveGame();
  157. }
  158. public void Logout()
  159. {
  160. TDSUser.Logout();
  161. AntiAddictionUIKit.Logout();
  162. }
  163. }
  164. }