GameController.cs 8.5 KB

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