GameController.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. //RoleInfo roleInfo = null;
  83. GetSuitItemController.enable = false;
  84. //roleInfo = result.roleInfo;
  85. //bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  86. //if (rerult)
  87. //{
  88. // return;
  89. //}
  90. //ServerDataManager.SetServerTime(roleInfo.serverTime);
  91. RoleDataManager.InitServerData();
  92. //ItemDataManager.InitServerData(result.roleItemList);
  93. //CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  94. //StoryDataManager.InitServerData(roleInfo);
  95. //GuideDataManager.InitServerData(result.roleGuideList);
  96. //CardDataManager.InitServerData(result.roleCardList);
  97. //SkillDataManager.Instance.InitServerData(result.roleSkillList);
  98. //SkillDataManager.Instance.SetDicPassivitySkillCfg();
  99. GetSuitItemController.enable = true;
  100. RoleDataHandler.StartUpdate();
  101. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  102. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  103. InstanceZonesSProxy.GetInstanceZonesInfos().Coroutine();
  104. await StorageSProxy.ReqGetClientValues();
  105. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  106. if (skipGuide <= 0)
  107. {
  108. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  109. .SetLeftButton(true, "不用", (obj) =>
  110. {
  111. EnterGame();
  112. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  113. })
  114. .SetRightButton(true, "跳过", (obj) =>
  115. {
  116. GameGlobal.skipGuide = true;
  117. EnterGame();
  118. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  119. });
  120. }
  121. else
  122. {
  123. if (skipGuide == 2) GameGlobal.skipGuide = true;
  124. EnterGame();
  125. }
  126. }
  127. public static void QuitToLoginView(bool logout)
  128. {
  129. GetSuitItemController.enable = false;
  130. GameGlobal.isVisitor = false;
  131. GameGlobal.antiAddiction = true;
  132. GameGlobal.userId = 0;
  133. GameGlobal.userAge = 0;
  134. GameGlobal.skipGuide = false;
  135. RoleDataHandler.StopUpdate();
  136. CardDataManager.Clear();
  137. DecomposeDataManager.Instance.Clear();
  138. PhotographDataManager.Instance.Clear();
  139. SkillDataManager.Instance.Clear();
  140. SuitFosterDataManager.Instance.Clear();
  141. StudioDataManager.Instance.Clear();
  142. StorageDataManager.Instance.Clear();
  143. RechargeDataManager.Instance.Clear();
  144. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  145. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  146. if (logout)
  147. {
  148. Logout();
  149. }
  150. ViewManager.Show<LoginView>(null, null, true);
  151. if (logout)
  152. {
  153. ViewManager.Show<LoginInputView>();
  154. }
  155. LoginController.Logout();
  156. }
  157. //注销
  158. public static void Logout()
  159. {
  160. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  161. }
  162. public static void GoBackToMainView()
  163. {
  164. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  165. }
  166. private static void EnterGame()
  167. {
  168. ViewManager.Hide<LoginView>();
  169. GameGlobal.isEnterGame = true;
  170. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  171. {
  172. ViewManager.Show(ViewName.MAINUI_VIEW);
  173. }
  174. else
  175. {
  176. MainStoryDataManager.currentChapterCfgId = 10001;
  177. if (GameGlobal.isFirstEntry == true)
  178. {
  179. StoryController.ShowPriorStoryDialog();
  180. }
  181. else
  182. {
  183. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  184. }
  185. }
  186. Timers.inst.CallLater(AfterEnterGame);
  187. }
  188. private static async void AfterEnterGame(object param)
  189. {
  190. //GameProxy.ReqGetStoryScoreList();
  191. //GameProxy.ReqGetStoryStarList();
  192. ItemHelper.GetItemAttributeInfos().Coroutine();
  193. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  194. MainStorySProxy.GetStoryInfos().Coroutine();
  195. CardSProxy.GetCardInfos().Coroutine();
  196. RechargeSProxy.ReqRechargeInfo().Coroutine();
  197. RechargeSProxy.ReqRequestGiftBagInfo().Coroutine();
  198. RechargeSProxy.ReqExchangeInfo().Coroutine();
  199. DailyTaskSProxy.ReqDailyTaskInfos().Coroutine();
  200. ActivitySProxy.ReqDailyLoginInfos().Coroutine();
  201. NoticeSProxy.ReqSystemNoticeList().Coroutine();
  202. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  203. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  204. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  205. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  206. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  207. {
  208. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  209. if (result1)
  210. {
  211. ViewManager.Show<FieldFightEndView>();
  212. }
  213. }
  214. bool result2 = await MailSProxy.ReqMailCount();
  215. if (result2)
  216. {
  217. MailSProxy.ReqMailList(0, MailDataManager.Instance.TotolCount, true).Coroutine();
  218. }
  219. }
  220. }
  221. }