GameController.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. if (GameGlobal.isOfflineVisitor)
  57. {
  58. GameProxy.ReqRoleInfo(GameGlobal.userId);
  59. }
  60. else
  61. {
  62. User user = result.user;
  63. GameGlobal.userId = user.id;
  64. GameGlobal.userAge = user.age;
  65. if (GameGlobal.isVisitor)
  66. {
  67. PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  68. }
  69. else
  70. {
  71. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, user.account);
  72. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, user.password);
  73. }
  74. GameController.CheckSpecialAccount(user.account);
  75. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  76. PlayerPrefs.Save();
  77. GameProxy.ReqRoleInfo(GameGlobal.userId);
  78. }
  79. }
  80. public static void OnLoginFail(LoginResult result)
  81. {
  82. if (result.code == 107)
  83. {
  84. string promptStr = "您属于未成年人,已被纳入防沉迷系统。每日22时至次日8时,本游戏将无法为未成年人用户提供游戏服务。";
  85. Alert.Show(promptStr)
  86. .SetRightButton(true, "知道啦", (object data) =>
  87. {
  88. });
  89. }
  90. else
  91. {
  92. ViewManager.Show<LoginInputView>();
  93. }
  94. }
  95. public static void CheckSpecialAccount(string account)
  96. {
  97. GameGlobal.antiAddiction = !(account.IndexOf("sygfg") == 0);
  98. }
  99. public static void ShowCreateRole()
  100. {
  101. ViewManager.Show(ViewName.CREATE_ROLE_VIEW);
  102. Alert.Show("是否跳过引导?如果您是第一次体验,建议不要跳过引导!")
  103. .SetLeftButton(true, "不用")
  104. .SetRightButton(true, "跳过", (obj) =>
  105. {
  106. GameGlobal.skipGuide = true;
  107. });
  108. }
  109. public static void PreEnterGame(GameResult result)
  110. {
  111. RoleInfo roleInfo = null;
  112. GetSuitItemController.enable = false;
  113. DressUpMenuSuitDataManager.InitData();
  114. DressUpMenuItemDataManager.InitData();
  115. if (!GameGlobal.isOfflineVisitor)
  116. {
  117. roleInfo = result.roleInfo;
  118. bool rerult = AntiAddictionController.CheckAntiAddiction(roleInfo.onlineTimeSecs, roleInfo.onlineDurationSecs, roleInfo.onlineDurationSecsDay);
  119. if (rerult)
  120. {
  121. return;
  122. }
  123. ServerDataManager.SetServerTime(roleInfo.serverTime);
  124. RoleDataManager.InitServerData(roleInfo);
  125. ItemDataManager.InitServerData(result.roleItemList);
  126. CustomSuitDataManager.InitServerData(roleInfo.suitIndex, result.roleSuitList);
  127. StoryDataManager.InitServerData(roleInfo);
  128. GuideDataManager.InitServerData(result.roleGuideList);
  129. DressUpMenuSuitDataManager.InitServerData(result.systemSuitList);
  130. CardDataManager.InitServerData(result.roleCardList);
  131. }
  132. else
  133. {
  134. RoleDataManager.InitServerData(null);
  135. ItemDataManager.InitServerData(null);
  136. CustomSuitDataManager.InitServerData(0, null);
  137. StoryDataManager.InitServerData(null);
  138. GuideDataManager.InitServerData(null);
  139. DressUpMenuSuitDataManager.InitServerData(null);
  140. CardDataManager.InitServerData(null);
  141. }
  142. GetSuitItemController.enable = true;
  143. RoleDataHandler.StartUpdate();
  144. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  145. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  146. if (GameGlobal.isOfflineVisitor)
  147. {
  148. Alert.Show("离线体验可以选择跳过引导并获取所有衣服。")
  149. .SetLeftButton(true, "跳过引导", (object data) =>
  150. {
  151. GameGlobal.skipGuide = true;
  152. GMController.GetAllDressUpItem();
  153. EnterGame();
  154. })
  155. .SetRightButton(true, "体验引导", (object data) =>
  156. {
  157. GameGlobal.skipGuide = false;
  158. EnterGame();
  159. });
  160. }
  161. else
  162. {
  163. if (RoleDataManager.lvl >= 50)
  164. {
  165. GameGlobal.skipGuide = true;
  166. }
  167. EnterGame();
  168. }
  169. }
  170. public static void QuitToLoginView(bool logout)
  171. {
  172. GetSuitItemController.enable = false;
  173. GameGlobal.isVisitor = false;
  174. GameGlobal.antiAddiction = true;
  175. GameGlobal.userId = 0;
  176. GameGlobal.userAge = 0;
  177. GameGlobal.skipGuide = false;
  178. RoleDataHandler.StopUpdate();
  179. CardDataManager.Clear();
  180. DecomposeDataManager.Instance.Clear();
  181. PhotographDataManager.Instance.Clear();
  182. if (logout)
  183. {
  184. Logout();
  185. }
  186. ViewManager.Hide(ViewName.ROLE_INFO_VIEW);
  187. ViewManager.Hide(ViewName.MAINUI_VIEW);
  188. ViewManager.Show<LoginView>();
  189. if (logout)
  190. {
  191. ViewManager.Show<LoginInputView>();
  192. }
  193. }
  194. //注销
  195. public static void Logout()
  196. {
  197. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  198. }
  199. public static void GoBackToMainView()
  200. {
  201. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  202. }
  203. private static void EnterGame()
  204. {
  205. ViewManager.Hide<LoginView>();
  206. if (StoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  207. {
  208. ViewManager.Show(ViewName.MAINUI_VIEW);
  209. }
  210. else
  211. {
  212. StoryDataManager.currentChapter = 1;
  213. if (!StoryDataManager.CheckLevelPass(1, 1))
  214. {
  215. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  216. StoryController.ShowLevelView(StoryDataManager.currentChapter, 1);
  217. }
  218. else
  219. {
  220. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  221. }
  222. }
  223. AfterEnterGame();
  224. }
  225. private static void AfterEnterGame()
  226. {
  227. GameProxy.ReqGetStoryScoreList();
  228. GameProxy.ReqGetStoryStarList();
  229. }
  230. public static void PrepareUpdateTreasure()
  231. {
  232. if (!Timers.inst.Exists(UpdateTreasure))
  233. {
  234. Timers.inst.Add(0.1f, 1, UpdateTreasure);
  235. }
  236. }
  237. private static void UpdateTreasure(object param)
  238. {
  239. GameProxy.ReqUpdateTreasure();
  240. }
  241. }
  242. }