GameController.cs 9.2 KB

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