GameController.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 (account != null && account.Length > 0)
  37. {
  38. if (password != null && password.Length > 0)
  39. {
  40. if (doLogin)
  41. {
  42. LoginController.Login(account, password, true).Coroutine();
  43. }
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. public static void CheckSpecialAccount(string account)
  50. {
  51. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  52. }
  53. public static void ShowCreateRole()
  54. {
  55. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  56. }
  57. public static async Task PreEnterGameAsync()
  58. {
  59. //RoleInfo roleInfo = null;
  60. GetSuitItemController.enable = false;
  61. //roleInfo = result.roleInfo;
  62. //bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  63. //if (rerult)
  64. //{
  65. // return;
  66. //}
  67. //ServerDataManager.SetServerTime(roleInfo.serverTime);
  68. RoleDataManager.InitServerData();
  69. //ItemDataManager.InitServerData(result.roleItemList);
  70. //CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  71. //StoryDataManager.InitServerData(roleInfo);
  72. //GuideDataManager.InitServerData(result.roleGuideList);
  73. //CardDataManager.InitServerData(result.roleCardList);
  74. //SkillDataManager.Instance.InitServerData(result.roleSkillList);
  75. //SkillDataManager.Instance.SetDicPassivitySkillCfg();
  76. GetSuitItemController.enable = true;
  77. RoleDataHandler.StartUpdate();
  78. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  79. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  80. InstanceZonesSProxy.GetInstanceZonesInfos().Coroutine();
  81. await StorageSProxy.ReqGetClientValues();
  82. int skipGuide = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_SKIP_GUIDE);
  83. if (skipGuide < 0)
  84. {
  85. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  86. .SetLeftButton(true, "不用", (obj) =>
  87. {
  88. EnterGame();
  89. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 0).Coroutine();
  90. })
  91. .SetRightButton(true, "跳过", (obj) =>
  92. {
  93. GameGlobal.skipGuide = true;
  94. EnterGame();
  95. StorageSProxy.ReqSetClientValue(ConstStorageId.STORAGE_SKIP_GUIDE, 1).Coroutine();
  96. });
  97. }
  98. else
  99. {
  100. if (skipGuide == 1) GameGlobal.skipGuide = true;
  101. EnterGame();
  102. }
  103. }
  104. public static void QuitToLoginView(bool logout)
  105. {
  106. GetSuitItemController.enable = false;
  107. GameGlobal.isVisitor = false;
  108. GameGlobal.antiAddiction = true;
  109. GameGlobal.userId = 0;
  110. GameGlobal.userAge = 0;
  111. GameGlobal.skipGuide = false;
  112. RoleDataHandler.StopUpdate();
  113. CardDataManager.Clear();
  114. DecomposeDataManager.Instance.Clear();
  115. PhotographDataManager.Instance.Clear();
  116. SkillDataManager.Instance.Clear();
  117. SuitFosterDataManager.Instance.Clear();
  118. StudioDataManager.Instance.Clear();
  119. StorageDataManager.Instance.Clear();
  120. if (logout)
  121. {
  122. Logout();
  123. }
  124. ViewManager.Hide(ViewName.ROLE_INFO_VIEW);
  125. ViewManager.Hide(ViewName.MAINUI_VIEW);
  126. ViewManager.Show<LoginView>();
  127. if (logout)
  128. {
  129. ViewManager.Show<LoginInputView>();
  130. }
  131. }
  132. //注销
  133. public static void Logout()
  134. {
  135. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  136. }
  137. public static void GoBackToMainView()
  138. {
  139. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  140. }
  141. private static void EnterGame()
  142. {
  143. ViewManager.Hide<LoginView>();
  144. if (MainStoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  145. {
  146. ViewManager.Show(ViewName.MAINUI_VIEW);
  147. }
  148. else
  149. {
  150. MainStoryDataManager.currentChapterCfgId = 10001;
  151. if (GameGlobal.isFirstEntry == true)
  152. {
  153. // ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  154. StoryController.ShowPriorStoryDialog();
  155. }
  156. else
  157. {
  158. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, MainStoryDataManager.currentChapterCfgId, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  159. }
  160. }
  161. Timers.inst.CallLater(AfterEnterGame);
  162. }
  163. private static void AfterEnterGame(object param)
  164. {
  165. //GameProxy.ReqGetStoryScoreList();
  166. //GameProxy.ReqGetStoryStarList();
  167. ItemHelper.GetItemAttributeInfos().Coroutine();
  168. SuitFosterProxy.SendGetSuitInfos().Coroutine();
  169. MainStorySProxy.GetStoryInfos().Coroutine();
  170. CardSProxy.GetCardInfos().Coroutine();
  171. EquipDataCache.cacher.autoPlay = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY) <= 0 ? false : true;
  172. EquipDataCache.cacher.fightSpeed = StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED) <= 1 ? 1 : StorageDataManager.Instance.GetStorageValue(ConstStorageId.STORAGE_AUTO_PLAY_SPEED);
  173. GameGlobal.skipCheckOpen = StorageDataManager.Instance.GetStorageValue(ConstStorageId.SKIP_CHECK_OPEN) <= 0 ? false : true;
  174. }
  175. public static void PrepareUpdateTreasure()
  176. {
  177. if (!Timers.inst.Exists(UpdateTreasure))
  178. {
  179. Timers.inst.Add(0.1f, 1, UpdateTreasure);
  180. }
  181. }
  182. private static void UpdateTreasure(object param)
  183. {
  184. GameProxy.ReqUpdateTreasure();
  185. }
  186. }
  187. }