GameController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. using FairyGUI;
  2. using UnityEngine;
  3. using ET;
  4. using static GFGGame.LauncherConfig;
  5. using TapTap.Bootstrap;
  6. namespace GFGGame
  7. {
  8. public class GameController
  9. {
  10. public static void Start()
  11. {
  12. var shader1 = GFGAsset.Load<Shader>(ResPathUtil.GetShaderPath("Effect_distortion_add"));
  13. Log.Warning($"shader1 null {shader1 == null}");
  14. GFGAsset.Load<Shader>(ResPathUtil.GetShaderPath("Effect_distortion_blend"));
  15. var shader2 = Shader.Find("Effect_distortion_add");
  16. Log.Warning($"shader2 null {shader2 == null}");
  17. //界面
  18. ViewManager.Init();
  19. //日志
  20. LogController.Instance.Init();
  21. //全局
  22. GameGlobal.Init();
  23. //缓存
  24. LocalCache.InitLocalData();
  25. //sqlite
  26. SqliteController.Instance.Init(false, ResPathUtil.SQLITE_FILE_PATH);
  27. //全局点击效果
  28. ViewGlobal.CreatClickEffect();
  29. ViewGlobal.AddShowGMViewEventListener();
  30. //获取游戏配置
  31. GetGameCfg();
  32. }
  33. /// <summary>
  34. /// 获取游戏配置
  35. /// </summary>
  36. public static void GetGameCfg()
  37. {
  38. var url = LauncherConfig.cfgUrl.Replace("{cfgName}", GameGlobal.cfgName);
  39. url = url + "?t=" + TimeHelper.ClientNow();
  40. HttpTool.Instance.Get(url, (string data) =>
  41. {
  42. //初始化游戏配置
  43. GameConfig.InitData(data);
  44. //显示登录
  45. LoginController.ShowLogin();
  46. });
  47. }
  48. public static bool CheckLoginCache(bool doLogin)
  49. {
  50. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  51. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  52. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  53. if (lastLoginIsVisitor)
  54. {
  55. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  56. if (id >= 0)
  57. {
  58. if (doLogin)
  59. {
  60. //LoginProxy.LoginAsVisitor();
  61. }
  62. return true;
  63. }
  64. }
  65. else if (!string.IsNullOrEmpty(account))
  66. {
  67. if (!string.IsNullOrEmpty(password))
  68. {
  69. if (doLogin)
  70. {
  71. LoginController.Login(account, password, true).Coroutine();
  72. }
  73. return true;
  74. }
  75. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL && PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
  76. {
  77. if (doLogin)
  78. {
  79. LoginController.LoginTest(account).Coroutine();
  80. }
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. public static void CheckSpecialAccount(string account)
  87. {
  88. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  89. }
  90. public static void ShowCreateRole()
  91. {
  92. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  93. }
  94. public static async ETTask PreEnterGameAsync()
  95. {
  96. QDTapTapManager.Instance.OnEnterGame();
  97. RoleDataHandler.StartUpdate();
  98. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  99. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  100. await ItemProxy.GetItemInfos();
  101. await InstanceZonesSProxy.GetInstanceZonesInfos();
  102. await StorageSProxy.ReqGetClientValues();
  103. await SuitFosterProxy.SendGetSuitInfos();
  104. await ActivitySProxy.ReqDailyLoginInfos();
  105. await RechargeSProxy.ReqRequestGiftBagInfo();
  106. await StudioSProxy.ReqStudioInfos();
  107. await RoleInfoSProxy.ReqPersonalInfo();
  108. GameGlobal.lastLoginTime = StorageDataManager.Instance.GetStorageValue(ConstStorageId.LAST_LOGIN_TIME);
  109. long lastTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.OnlineTimeSecs);
  110. StorageSProxy.ReqSetClientValue(ConstStorageId.LAST_LOGIN_TIME, (int)lastTime).Coroutine();
  111. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  112. if (skipGuide <= 0 && LauncherConfig.netType == EnumNetType.LOCAL)
  113. {
  114. AlertUI.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  115. .SetLeftButton(true, "不用", (obj) =>
  116. {
  117. EnterGame();
  118. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  119. })
  120. .SetRightButton(true, "跳过", (obj) =>
  121. {
  122. GameGlobal.skipGuide = true;
  123. EnterGame();
  124. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  125. });
  126. }
  127. else
  128. {
  129. if (skipGuide == 2) GameGlobal.skipGuide = true;
  130. EnterGame();
  131. }
  132. }
  133. public static void QuitToLoginView(bool logout)
  134. {
  135. GameGlobal.DataInited = false;
  136. QDManager.OnQuitToLoginView();
  137. GameGlobal.isVisitor = false;
  138. GameGlobal.antiAddiction = true;
  139. GameGlobal.userId = 0;
  140. GameGlobal.userAge = 0;
  141. GameGlobal.skipGuide = false;
  142. GuideDataManager.currentGuideId = 0;
  143. MainDataManager.Instance.ViewType = 0;
  144. RoleDataHandler.StopUpdate();
  145. CardDataManager.Clear();
  146. ItemDataManager.Clear();
  147. DecomposeDataManager.Instance.Clear();
  148. PhotographDataManager.Instance.Clear();
  149. SkillDataManager.Instance.Clear();
  150. SuitFosterDataManager.Instance.Clear();
  151. StudioDataManager.Instance.Clear();
  152. StorageDataManager.Instance.Clear();
  153. RechargeDataManager.Instance.Clear();
  154. DressUpMenuItemDataManager.Clear();
  155. GuideDataManager.Clear();
  156. GetSuitItemController.Clear();
  157. FriendDataManager.Instance.Clear();
  158. RedDotController.Instance.Clear();
  159. BagDataManager.Instance.Clear();
  160. PoemPhotoDataManager.Instance.Clear();
  161. PoemGalleryDataManager.Instance.Clear();
  162. RoleInfoManager.Instance.Clear();
  163. DailyTaskDataManager.Instance.Clear();
  164. TravelDataManager.Instance.Clear();
  165. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  166. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  167. GameGlobal.zoneScene.GetComponent<AccountInfoComponent>()?.Clear();
  168. if (logout)
  169. {
  170. Logout();
  171. }
  172. LoginController.OnLogout();
  173. ViewManager.Hide<GuideView>();
  174. ViewManager.Show<LoginView>(null, null, true);
  175. }
  176. //注销
  177. public static void Logout()
  178. {
  179. QDManager.Logout();
  180. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  181. }
  182. public static void GoBackToMainView()
  183. {
  184. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  185. }
  186. private static void EnterGame()
  187. {
  188. LoadingView.Instance.GetUI();
  189. LoadingView.Instance.SetProgress(100, () =>
  190. {
  191. ViewManager.Hide<LoadingView>();
  192. // LoadingView.Instance.Close();
  193. GameGlobal.isEnterGame = true;
  194. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  195. {
  196. ViewManager.Show(ViewName.MAINUI_VIEW);
  197. }
  198. else
  199. {
  200. MainStoryDataManager.currentChapterCfgId = 10001;
  201. if (GameGlobal.isFirstEntry == true)
  202. {
  203. GameGlobal.isFirstEntry = false;
  204. // StoryController.ShowPriorStoryDialog();
  205. StoryController.ShowLevelView(100001001);
  206. }
  207. else
  208. {
  209. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  210. }
  211. }
  212. Timers.inst.Add(1f, 1, AfterEnterGame);
  213. });
  214. }
  215. private static async void AfterEnterGame(object param)
  216. {
  217. ItemHelper.GetItemAttributeInfos().Coroutine();
  218. MainStorySProxy.GetStoryInfos().Coroutine();
  219. CardSProxy.GetCardInfos().Coroutine();
  220. RechargeSProxy.ReqRechargeInfo().Coroutine();
  221. RechargeSProxy.ReqExchangeInfo().Coroutine();
  222. DailyTaskSProxy.ReqDailyTaskInfos().Coroutine();
  223. NoticeSProxy.ReqSystemNoticeList().Coroutine();
  224. MailSProxy.ReqMailCount().Coroutine();
  225. FriendSProxy.ReqAllFriendInfos().Coroutine();
  226. PoemPhotoSProxy.ReqAllPhotoInfos().Coroutine();
  227. TravelSProxy.ReqTravelInfo().Coroutine();
  228. TravelSProxy.ReqTravelGuideInfo().Coroutine();
  229. PoemGallerySProxy.ReqGalleryTheme().Coroutine();
  230. int storageAutoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY);
  231. FightDataManager.Instance.autoPlay = storageAutoPlay <= 0 ? false : true;
  232. int fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_FIGHT_AUTO_PLAY_SPEED);
  233. FightDataManager.Instance.fightSpeed = fightSpeed <= 0 ? 1 : fightSpeed;
  234. int dialogSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_DIALOG_AUTO_PLAY_SPEED);
  235. FightDataManager.Instance.dialogSpeed = dialogSpeed <= 0 ? 1 : dialogSpeed;
  236. int filingChapterId = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STUDIO_FILING_CHAPTERID);
  237. StudioDataManager.Instance.filingChapterId = filingChapterId <= 0 ? StudioDataManager.Instance.FilingDatas[0].id : filingChapterId;
  238. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  239. bool result = await FieldSProxy.ReqFieldInstanceInfos();
  240. if (result && FieldDataManager.Instance.fieldInfos.hasBonus)
  241. {
  242. bool result1 = await FieldSProxy.ReqFieldInstanceResult();
  243. if (result1)
  244. {
  245. ViewManager.Show<FieldFightEndView>();
  246. }
  247. }
  248. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  249. }
  250. }
  251. }