GameController.cs 6.4 KB

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