PlatformTapManager.cs 6.0 KB

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