GameController.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. GameGlobal.myUnit.Dispose();
  118. GameGlobal.myUnit = null;
  119. RoleDataHandler.StopUpdate();
  120. CardDataManager.Clear();
  121. DecomposeDataManager.Instance.Clear();
  122. PhotographDataManager.Instance.Clear();
  123. SkillDataManager.Instance.Clear();
  124. SuitFosterDataManager.Instance.Clear();
  125. StudioDataManager.Instance.Clear();
  126. StorageDataManager.Instance.Clear();
  127. RechargeDataManager.Instance.Clear();
  128. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  129. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  130. if (logout)
  131. {
  132. Logout();
  133. }
  134. ViewManager.Show<LoginView>(null, null, true);
  135. if (logout)
  136. {
  137. ViewManager.Show<LoginInputView>();
  138. }
  139. LoginController.Logout();
  140. }
  141. //注销
  142. public static void Logout()
  143. {
  144. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  145. }
  146. public static void GoBackToMainView()
  147. {
  148. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  149. }
  150. private static void EnterGame()
  151. {
  152. ViewManager.Hide<LoadingView>();
  153. // LoadingView.Instance.Close();
  154. GameGlobal.isEnterGame = true;
  155. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  156. {
  157. ViewManager.Show(ViewName.MAINUI_VIEW);
  158. }
  159. else
  160. {
  161. MainStoryDataManager.currentChapterCfgId = 10001;
  162. if (GameGlobal.isFirstEntry == true)
  163. {
  164. GameGlobal.isFirstEntry = false;
  165. StoryController.ShowPriorStoryDialog();
  166. }
  167. else
  168. {
  169. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  170. }
  171. }
  172. Timers.inst.Add(1f, 1, AfterEnterGame);
  173. }
  174. private static async void AfterEnterGame(object param)
  175. {
  176. ItemHelper.GetItemAttributeInfos().Coroutine();
  177. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  178. MainStorySProxy.GetStoryInfos().Coroutine();
  179. CardSProxy.GetCardInfos().Coroutine();
  180. RechargeSProxy.ReqRechargeInfo().Coroutine();
  181. RechargeSProxy.ReqRequestGiftBagInfo().Coroutine();
  182. RechargeSProxy.ReqExchangeInfo().Coroutine();
  183. DailyTaskSProxy.ReqDailyTaskInfos().Coroutine();
  184. ActivitySProxy.ReqDailyLoginInfos().Coroutine();
  185. NoticeSProxy.ReqSystemNoticeList().Coroutine();
  186. StudioSProxy.ReqStudioInfos().Coroutine();
  187. MailSProxy.ReqMailCount().Coroutine();
  188. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  189. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  190. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  191. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  192. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  193. {
  194. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  195. if (result1)
  196. {
  197. ViewManager.Show<FieldFightEndView>();
  198. }
  199. }
  200. }
  201. }
  202. }