GameController.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. SkillDataManager.Instance.InitServerData(result.roleSkillList);
  132. SkillDataManager.Instance.SetDicPassivitySkillCfg();
  133. }
  134. else
  135. {
  136. RoleDataManager.InitServerData(null);
  137. ItemDataManager.InitServerData(null);
  138. CustomSuitDataManager.InitServerData(0, null);
  139. StoryDataManager.InitServerData(null);
  140. GuideDataManager.InitServerData(null);
  141. DressUpMenuSuitDataManager.InitServerData(null);
  142. CardDataManager.InitServerData(null);
  143. SkillDataManager.Instance.InitServerData(null);
  144. SkillDataManager.Instance.SetDicPassivitySkillCfg();
  145. }
  146. GetSuitItemController.enable = true;
  147. RoleDataHandler.StartUpdate();
  148. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("CommonGame"));
  149. GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Main"));
  150. if (GameGlobal.isOfflineVisitor)
  151. {
  152. Alert.Show("离线体验可以选择跳过引导并获取所有衣服。")
  153. .SetLeftButton(true, "跳过引导", (object data) =>
  154. {
  155. GameGlobal.skipGuide = true;
  156. GMController.GetAllDressUpItem();
  157. EnterGame();
  158. })
  159. .SetRightButton(true, "体验引导", (object data) =>
  160. {
  161. GameGlobal.skipGuide = false;
  162. EnterGame();
  163. });
  164. }
  165. else
  166. {
  167. if (RoleDataManager.lvl >= 50)
  168. {
  169. GameGlobal.skipGuide = true;
  170. }
  171. EnterGame();
  172. }
  173. }
  174. public static void QuitToLoginView(bool logout)
  175. {
  176. GetSuitItemController.enable = false;
  177. GameGlobal.isVisitor = false;
  178. GameGlobal.antiAddiction = true;
  179. GameGlobal.userId = 0;
  180. GameGlobal.userAge = 0;
  181. GameGlobal.skipGuide = false;
  182. RoleDataHandler.StopUpdate();
  183. CardDataManager.Clear();
  184. DecomposeDataManager.Instance.Clear();
  185. PhotographDataManager.Instance.Clear();
  186. SkillDataManager.Instance.Clear();
  187. if (logout)
  188. {
  189. Logout();
  190. }
  191. ViewManager.Hide(ViewName.ROLE_INFO_VIEW);
  192. ViewManager.Hide(ViewName.MAINUI_VIEW);
  193. ViewManager.Show<LoginView>();
  194. if (logout)
  195. {
  196. ViewManager.Show<LoginInputView>();
  197. }
  198. }
  199. //注销
  200. public static void Logout()
  201. {
  202. PlayerPrefs.DeleteKey(GameConst.PASSWORD_LAST_LOGIN_KEY);
  203. }
  204. public static void GoBackToMainView()
  205. {
  206. ViewManager.Show(ViewName.MAINUI_VIEW, null, null, true);
  207. }
  208. private static void EnterGame()
  209. {
  210. ViewManager.Hide<LoginView>();
  211. if (StoryDataManager.CheckOpenMainUI() || GameGlobal.skipGuide)
  212. {
  213. ViewManager.Show(ViewName.MAINUI_VIEW);
  214. }
  215. else
  216. {
  217. StoryDataManager.currentChapter = 1;
  218. if (GameGlobal.isFirstEntry == true)
  219. {
  220. // ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW, });
  221. StoryController.ShowPriorStoryDialog();
  222. }
  223. else
  224. {
  225. ViewManager.Show(ViewName.STORY_CHAPTER_VIEW, StoryDataManager.currentChapter, new object[] { ViewName.STORY_CHAPTER_LIST_VIEW });
  226. }
  227. }
  228. AfterEnterGame();
  229. }
  230. private static void AfterEnterGame()
  231. {
  232. GameProxy.ReqGetStoryScoreList();
  233. GameProxy.ReqGetStoryStarList();
  234. }
  235. public static void PrepareUpdateTreasure()
  236. {
  237. if (!Timers.inst.Exists(UpdateTreasure))
  238. {
  239. Timers.inst.Add(0.1f, 1, UpdateTreasure);
  240. }
  241. }
  242. private static void UpdateTreasure(object param)
  243. {
  244. GameProxy.ReqUpdateTreasure();
  245. }
  246. }
  247. }