GameController.cs 9.8 KB

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