GameController.cs 8.3 KB

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