GameController.cs 8.1 KB

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