GameController.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.CommonGame;
  4. using UI.Main;
  5. using UI.Common;
  6. namespace GFGGame
  7. {
  8. public class GameController
  9. {
  10. public static void Start()
  11. {
  12. LoginProxy.SayHi((LoginResult result) =>
  13. {
  14. CheckShowLoginView();
  15. });
  16. }
  17. private static void CheckShowLoginView()
  18. {
  19. LauncherView.Instance.Close();
  20. ViewManager.Show<LoginView>();
  21. }
  22. public static bool CheckLoginCache(bool doLogin)
  23. {
  24. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, null);
  25. string password = PlayerPrefs.GetString(GameConst.PASSWORD_LAST_LOGIN_KEY, null);
  26. bool lastLoginIsVisitor = LocalCache.GetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, false);
  27. if (lastLoginIsVisitor)
  28. {
  29. long id = (long)PlayerPrefs.GetFloat(GameConst.VISITOR_ID_KEY, -1);
  30. if (id >= 0)
  31. {
  32. if (doLogin)
  33. {
  34. LoginProxy.LoginAsVisitor();
  35. }
  36. return true;
  37. }
  38. }
  39. else if (account != null && account.Length > 0)
  40. {
  41. if (password != null && password.Length > 0)
  42. {
  43. if (doLogin)
  44. {
  45. LoginProxy.Login(account, password);
  46. }
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. public static void OnLoginSuccess(LoginResult result)
  53. {
  54. ViewManager.Hide<LoginInputView>();
  55. ViewManager.Hide<RegisterView>();
  56. User user = result.user;
  57. GameGlobal.userId = user.id;
  58. GameGlobal.userAge = user.age;
  59. if (GameGlobal.isVisitor)
  60. {
  61. PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  62. }
  63. else
  64. {
  65. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, user.account);
  66. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, user.password);
  67. }
  68. GameController.CheckSpecialAccount(user.account);
  69. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  70. PlayerPrefs.Save();
  71. GameProxy.ReqRoleInfo(GameGlobal.userId);
  72. }
  73. public static void OnLoginFail(LoginResult result)
  74. {
  75. if (result.code == 107)
  76. {
  77. string promptStr = "您属于未成年人,已被纳入防沉迷系统。每日22时至次日8时,本游戏将无法为未成年人用户提供游戏服务。";
  78. Alert.Show(promptStr)
  79. .SetRightButton(true, "知道啦", (object data) =>
  80. {
  81. });
  82. }
  83. else
  84. {
  85. ViewManager.Show<LoginInputView>();
  86. }
  87. }
  88. public static void CheckSpecialAccount(string account)
  89. {
  90. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  91. }
  92. public static void ShowCreateRole()
  93. {
  94. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  95. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  96. .SetLeftButton(true, "不用")
  97. .SetRightButton(true, "跳过", (obj) =>
  98. {
  99. GameGlobal.skipGuide = true;
  100. });
  101. }
  102. public static void PreEnterGame(GameResult result)
  103. {
  104. RoleInfo roleInfo = null;
  105. GetSuitItemController.enable = false;
  106. DressUpMenuSuitDataManager.InitData();
  107. DressUpMenuItemDataManager.InitData();
  108. roleInfo = result.roleInfo;
  109. bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  110. if (rerult)
  111. {
  112. return;
  113. }
  114. ServerDataManager.SetServerTime(roleInfo.serverTime);
  115. RoleDataManager.InitServerData(roleInfo);
  116. ItemDataManager.InitServerData(result.roleItemList);
  117. CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  118. StoryDataManager.InitServerData(roleInfo);
  119. GuideDataManager.InitServerData(result.roleGuideList);
  120. DressUpMenuSuitDataManager.InitServerData(result.systemSuitList);
  121. CardDataManager.InitServerData(result.roleCardList);
  122. GetSuitItemController.enable = true;
  123. RoleDataHandler.StartUpdate();
  124. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  125. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  126. if (RoleDataManager.lvl >= 50)
  127. {
  128. GameGlobal.skipGuide = true;
  129. }
  130. EnterGame();
  131. }
  132. public static void QuitToLoginView(bool logout)
  133. {
  134. GetSuitItemController.enable = false;
  135. GameGlobal.isVisitor = false;
  136. GameGlobal.antiAddiction = true;
  137. GameGlobal.userId = 0;
  138. GameGlobal.userAge = 0;
  139. GameGlobal.skipGuide = false;
  140. RoleDataHandler.StopUpdate();
  141. CardDataManager.Clear();
  142. PhotographDataManager.Instance.Clear();
  143. if (logout)
  144. {
  145. Logout();
  146. }
  147. ViewManager.Hide(ViewName.ROLE_INFO_VIEW);
  148. ViewManager.Hide(ViewName.MAINUI_VIEW);
  149. ViewManager.Show<LoginView>();
  150. if (logout)
  151. {
  152. ViewManager.Show<LoginInputView>();
  153. }
  154. }
  155. //注销
  156. public static void Logout()
  157. {
  158. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  159. }
  160. public static void GoBackToMainView()
  161. {
  162. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  163. }
  164. private static void EnterGame()
  165. {
  166. ViewManager.Hide<LoginView>();
  167. if (StoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  168. {
  169. ViewManager.Show(ViewName.MAINUI_VIEW);
  170. }
  171. else
  172. {
  173. StoryDataManager.currentChapter = 1;
  174. if (!StoryDataManager.CheckLevelPass(1, 1))
  175. {
  176. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  177. StoryController.ShowLevelView(StoryDataManager.currentChapter, 1);
  178. }
  179. else
  180. {
  181. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  182. }
  183. }
  184. AfterEnterGame();
  185. }
  186. private static void AfterEnterGame()
  187. {
  188. GameProxy.ReqGetStoryScoreList();
  189. GameProxy.ReqGetStoryStarList();
  190. }
  191. public static void PrepareUpdateTreasure()
  192. {
  193. if (!Timers.inst.Exists(UpdateTreasure))
  194. {
  195. Timers.inst.Add(0.1f, 1, UpdateTreasure);
  196. }
  197. }
  198. private static void UpdateTreasure(object param)
  199. {
  200. GameProxy.ReqUpdateTreasure();
  201. }
  202. }
  203. }