GameController.cs 8.0 KB

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