GameController.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using FairyGUI;
  2. using UnityEngine;
  3. using ET;
  4. using System.Threading.Tasks;
  5. namespace GFGGame
  6. {
  7. public class GameController
  8. {
  9. public static async ET.ETTask Start()
  10. {
  11. await LoginController.CheckVersion();
  12. CheckShowLoginView();
  13. }
  14. private static void CheckShowLoginView()
  15. {
  16. LauncherView.Instance.Close();
  17. ViewManager.Show<LoginView>();
  18. }
  19. public static bool CheckLoginCache(bool doLogin)
  20. {
  21. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  22. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  23. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  24. if (lastLoginIsVisitor)
  25. {
  26. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  27. if (id >= 0)
  28. {
  29. if (doLogin)
  30. {
  31. //LoginProxy.LoginAsVisitor();
  32. }
  33. return true;
  34. }
  35. }
  36. else if (!string.IsNullOrEmpty(account))
  37. {
  38. if (!string.IsNullOrEmpty(password))
  39. {
  40. if (doLogin)
  41. {
  42. LoginController.Login(account, password, true).Coroutine();
  43. }
  44. return true;
  45. }
  46. else if(LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  47. {
  48. if(doLogin)
  49. {
  50. if(PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
  51. {
  52. LoginController.LoginTest(account).Coroutine();
  53. }
  54. }
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. public static void CheckSpecialAccount(string account)
  61. {
  62. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  63. }
  64. public static void ShowCreateRole()
  65. {
  66. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  67. }
  68. public static async Task PreEnterGameAsync()
  69. {
  70. //RoleInfo roleInfo = null;
  71. GetSuitItemController.enable = false;
  72. //roleInfo = result.roleInfo;
  73. //bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  74. //if (rerult)
  75. //{
  76. // return;
  77. //}
  78. //ServerDataManager.SetServerTime(roleInfo.serverTime);
  79. RoleDataManager.InitServerData();
  80. //ItemDataManager.InitServerData(result.roleItemList);
  81. //CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  82. //StoryDataManager.InitServerData(roleInfo);
  83. //GuideDataManager.InitServerData(result.roleGuideList);
  84. //CardDataManager.InitServerData(result.roleCardList);
  85. //SkillDataManager.Instance.InitServerData(result.roleSkillList);
  86. //SkillDataManager.Instance.SetDicPassivitySkillCfg();
  87. GetSuitItemController.enable = true;
  88. RoleDataHandler.StartUpdate();
  89. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  90. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  91. InstanceZonesSProxy.GetInstanceZonesInfos().Coroutine();
  92. await StorageSProxy.ReqGetClientValues();
  93. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  94. if (skipGuide <= 0)
  95. {
  96. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  97. .SetLeftButton(true, "不用", (obj) =>
  98. {
  99. EnterGame();
  100. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  101. })
  102. .SetRightButton(true, "跳过", (obj) =>
  103. {
  104. GameGlobal.skipGuide = true;
  105. EnterGame();
  106. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 2).Coroutine();
  107. });
  108. }
  109. else
  110. {
  111. if (skipGuide == 2) GameGlobal.skipGuide = true;
  112. EnterGame();
  113. }
  114. }
  115. public static void QuitToLoginView(bool logout)
  116. {
  117. GetSuitItemController.enable = false;
  118. GameGlobal.isVisitor = false;
  119. GameGlobal.antiAddiction = true;
  120. GameGlobal.userId = 0;
  121. GameGlobal.userAge = 0;
  122. GameGlobal.skipGuide = false;
  123. RoleDataHandler.StopUpdate();
  124. CardDataManager.Clear();
  125. DecomposeDataManager.Instance.Clear();
  126. PhotographDataManager.Instance.Clear();
  127. SkillDataManager.Instance.Clear();
  128. SuitFosterDataManager.Instance.Clear();
  129. StudioDataManager.Instance.Clear();
  130. StorageDataManager.Instance.Clear();
  131. RechargeDataManager.Instance.Clear();
  132. GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
  133. GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
  134. if (logout)
  135. {
  136. Logout();
  137. }
  138. ViewManager.Show<LoginView>(null, null, true);
  139. if (logout)
  140. {
  141. ViewManager.Show<LoginInputView>();
  142. }
  143. LoginController.Logout();
  144. }
  145. //注销
  146. public static void Logout()
  147. {
  148. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  149. }
  150. public static void GoBackToMainView()
  151. {
  152. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  153. }
  154. private static void EnterGame()
  155. {
  156. ViewManager.Hide<LoginView>();
  157. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  158. {
  159. ViewManager.Show(ViewName.MAINUI_VIEW);
  160. }
  161. else
  162. {
  163. MainStoryDataManager.currentChapterCfgId = 10001;
  164. if (GameGlobal.isFirstEntry == true)
  165. {
  166. // ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  167. StoryController.ShowPriorStoryDialog();
  168. }
  169. else
  170. {
  171. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  172. }
  173. }
  174. Timers.inst.CallLater(AfterEnterGame);
  175. }
  176. private static void AfterEnterGame(object param)
  177. {
  178. //GameProxy.ReqGetStoryScoreList();
  179. //GameProxy.ReqGetStoryStarList();
  180. ItemHelper.GetItemAttributeInfos().Coroutine();
  181. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  182. MainStorySProxy.GetStoryInfos().Coroutine();
  183. CardSProxy.GetCardInfos().Coroutine();
  184. RechargeSProxy.ReqRechargeInfo().Coroutine();
  185. RechargeSProxy.ReqRequestGiftBagInfo().Coroutine();
  186. RechargeSProxy.ReqExchangeInfo().Coroutine();
  187. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  188. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  189. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  190. }
  191. }
  192. }