GameController.cs 8.8 KB

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