GameController.cs 10 KB

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