GameController.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using FairyGUI;
  2. using UnityEngine;
  3. using ET;
  4. using static GFGGame.LauncherConfig;
  5. using TapTap.Bootstrap;
  6. namespace GFGGame
  7. {
  8. public class GameController
  9. {
  10. public static void Start()
  11. {
  12. //界面
  13. ViewManager.Init();
  14. //日志
  15. LogController.Instance.Init();
  16. //全局
  17. GameGlobal.Init();
  18. //缓存
  19. LocalCache.InitLocalData();
  20. //sqlite
  21. SqliteController.Instance.Init(false, ResPathUtil.SQLITE_FILE_PATH);
  22. //全局点击效果
  23. ViewGlobal.CreatClickEffect();
  24. //获取游戏配置
  25. GetGameCfg();
  26. }
  27. /// <summary>
  28. /// 获取游戏配置
  29. /// </summary>
  30. public static void GetGameCfg()
  31. {
  32. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", GameGlobal.cfgName);
  33. HttpTool.Instance.Get(url, (string data) => {
  34. //初始化游戏配置
  35. GameConfig.InitData(data);
  36. //初始化平台配置
  37. PlatformManager.InitPlatform();
  38. //显示登录
  39. LoginController.ShowLogin();
  40. });
  41. }
  42. public static bool CheckLoginCache(bool doLogin)
  43. {
  44. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  45. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  46. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  47. if (lastLoginIsVisitor)
  48. {
  49. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  50. if (id >= 0)
  51. {
  52. if (doLogin)
  53. {
  54. //LoginProxy.LoginAsVisitor();
  55. }
  56. return true;
  57. }
  58. }
  59. else if (!string.IsNullOrEmpty(account))
  60. {
  61. if (!string.IsNullOrEmpty(password))
  62. {
  63. if (doLogin)
  64. {
  65. LoginController.Login(account, password, true).Coroutine();
  66. }
  67. return true;
  68. }
  69. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL && PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
  70. {
  71. if (doLogin)
  72. {
  73. LoginController.LoginTest(account).Coroutine();
  74. }
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. public static void CheckSpecialAccount(string account)
  81. {
  82. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  83. }
  84. public static void ShowCreateRole()
  85. {
  86. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  87. }
  88. public static async ETTask PreEnterGameAsync()
  89. {
  90. PlatformTapManager.OnEnterGame();
  91. RoleDataHandler.StartUpdate();
  92. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  93. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  94. await InstanceZonesSProxy.GetInstanceZonesInfos();
  95. await StorageSProxy.ReqGetClientValues();
  96. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  97. if (skipGuide <= 0 && LauncherConfig.netType == EnumNetType.LOCAL)
  98. {
  99. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  100. .SetLeftButton(true, "不用", (obj) =>
  101. {
  102. EnterGame();
  103. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  104. })
  105. .SetRightButton(true, "跳过", (obj) =>
  106. {
  107. GameGlobal.skipGuide = true;
  108. EnterGame();
  109. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  110. });
  111. }
  112. else
  113. {
  114. if (skipGuide == 2) GameGlobal.skipGuide = true;
  115. EnterGame();
  116. }
  117. }
  118. public static void QuitToLoginView(bool logout)
  119. {
  120. PlatformTapManager.OnQuitGame();
  121. GameGlobal.isVisitor = false;
  122. GameGlobal.antiAddiction = true;
  123. GameGlobal.userId = 0;
  124. GameGlobal.userAge = 0;
  125. GameGlobal.skipGuide = false;
  126. if(GameGlobal.myUnit != null)
  127. {
  128. GameGlobal.myUnit.Dispose();
  129. GameGlobal.myUnit = null;
  130. }
  131. RoleDataHandler.StopUpdate();
  132. CardDataManager.Clear();
  133. DecomposeDataManager.Instance.Clear();
  134. PhotographDataManager.Instance.Clear();
  135. SkillDataManager.Instance.Clear();
  136. SuitFosterDataManager.Instance.Clear();
  137. StudioDataManager.Instance.Clear();
  138. StorageDataManager.Instance.Clear();
  139. RechargeDataManager.Instance.Clear();
  140. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  141. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  142. if (logout)
  143. {
  144. Logout().Coroutine();
  145. }
  146. ViewManager.Show<LoginView>(null, null, true);
  147. if (logout)
  148. {
  149. ViewManager.Show<LoginInputView>();
  150. }
  151. LoginController.Logout();
  152. }
  153. //注销
  154. public static async ETTask Logout()
  155. {
  156. if(PlatformManager.IsTaptap)
  157. {
  158. await TDSUser.Logout();
  159. }
  160. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  161. }
  162. public static void GoBackToMainView()
  163. {
  164. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  165. }
  166. private static void EnterGame()
  167. {
  168. LoadingView.Instance.SetProgress(100, () =>
  169. {
  170. ViewManager.Hide<LoadingView>();
  171. // LoadingView.Instance.Close();
  172. GameGlobal.isEnterGame = true;
  173. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  174. {
  175. ViewManager.Show(ViewName.MAINUI_VIEW);
  176. }
  177. else
  178. {
  179. MainStoryDataManager.currentChapterCfgId = 10001;
  180. if (GameGlobal.isFirstEntry == true)
  181. {
  182. GameGlobal.isFirstEntry = false;
  183. StoryController.ShowPriorStoryDialog();
  184. }
  185. else
  186. {
  187. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  188. }
  189. }
  190. Timers.inst.Add(1f, 1, AfterEnterGame);
  191. });
  192. }
  193. private static async void AfterEnterGame(object param)
  194. {
  195. ItemHelper.GetItemAttributeInfos().Coroutine();
  196. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  197. MainStorySProxy.GetStoryInfos().Coroutine();
  198. CardSProxy.GetCardInfos().Coroutine();
  199. RechargeSProxy.ReqRechargeInfo().Coroutine();
  200. RechargeSProxy.ReqRequestGiftBagInfo().Coroutine();
  201. RechargeSProxy.ReqExchangeInfo().Coroutine();
  202. DailyTaskSProxy.ReqDailyTaskInfos().Coroutine();
  203. ActivitySProxy.ReqDailyLoginInfos().Coroutine();
  204. NoticeSProxy.ReqSystemNoticeList().Coroutine();
  205. StudioSProxy.ReqStudioInfos().Coroutine();
  206. MailSProxy.ReqMailCount().Coroutine();
  207. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  208. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  209. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  210. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  211. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  212. {
  213. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  214. if (result1)
  215. {
  216. ViewManager.Show<FieldFightEndView>();
  217. }
  218. }
  219. }
  220. }
  221. }