GameController.cs 8.6 KB

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