GameController.cs 9.2 KB

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