Initializer.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using LitJson;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Linq.Expressions;
  10. public class LogoSceneLabel
  11. {
  12. public static string DebugText = "DebugText";
  13. public static string ManagerGame = "ManagerGame";
  14. }
  15. public class Initializer : MonoBehaviour
  16. {
  17. #region Config
  18. //public Texture2D Texture2D;
  19. public bool AuditEdition;
  20. public bool DebugMode;
  21. public bool CatchException;
  22. public GameObject DebugModeGo;
  23. public static bool Inited;
  24. public static string InitScriptProgress;
  25. public static Text DebugText;
  26. public static Initializer Instance;
  27. public static List<Regist> RegistList = new List<Regist>();
  28. #endregion
  29. private void Awake()
  30. {
  31. if (CatchException)
  32. {
  33. try
  34. {
  35. InitDataEye();
  36. }
  37. catch (Exception)
  38. {
  39. }
  40. }
  41. else
  42. {
  43. InitDataEye();
  44. }
  45. if (CatchException)
  46. {
  47. try
  48. {
  49. InitScript();
  50. }
  51. catch (Exception e)
  52. {
  53. Text debugText = GameObject.Find(LogoSceneLabel.DebugText).GetComponent<Text>();
  54. debugText.SetAlpha(1);
  55. debugText.text = InitScriptProgress + "\n" + e;
  56. throw new Exception();
  57. }
  58. }
  59. else
  60. {
  61. InitScript();
  62. }
  63. }
  64. private void InitDataEye()
  65. {
  66. if (Application.platform == RuntimePlatform.IPhonePlayer)
  67. {
  68. DataEyeGA.Init("C5790DBD2CFE97BD18C7BE9A95482C05", DataEyeGA.PlatformType.IOS, "Official", "IOS");
  69. }
  70. else if (Application.isMobilePlatform)
  71. {
  72. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.ADR, "Official", "Android");
  73. }
  74. else if (Application.isEditor)
  75. {
  76. DataEyeGA.Init("ADE884FAAF61A2CB45B02431A70932B8", DataEyeGA.PlatformType.WP, "Official", "Windows");
  77. }
  78. }
  79. private void InitScript()
  80. {
  81. int index = 1;
  82. InitScriptProgress = index++.ToString();
  83. Application.targetFrameRate = 50;
  84. InitScriptProgress = index++.ToString();
  85. DontDestroyOnLoad(gameObject);
  86. InitScriptProgress = index++.ToString();
  87. HttpManager.Login(Manager.FirstTimeLoginCallback);
  88. InitScriptProgress = index++.ToString();
  89. HttpManager.GetMailAwardData();
  90. InitScriptProgress = index++.ToString();
  91. HttpManager.GetRankData();
  92. InitScriptProgress = index++.ToString();
  93. HttpManager.GetAlipayFlag();
  94. InitScriptProgress = index++.ToString();
  95. HttpManager.GetAnnounceData();
  96. Instance = this;
  97. InitScriptProgress = index++.ToString();
  98. if (DebugMode)
  99. {
  100. Instantiate(DebugModeGo, transform);
  101. }
  102. else
  103. {
  104. gameObject.AddComponent<Bundle>();
  105. }
  106. InitScriptProgress = index++.ToString();
  107. gameObject.AddComponent<IAPManager>();
  108. InitScriptProgress = index++.ToString();
  109. gameObject.AddComponent<VisitManager>();
  110. InitScriptProgress = index++.ToString();
  111. gameObject.AddComponent<DebugManager>();
  112. InitScriptProgress = index++.ToString();
  113. gameObject.AddScript<Auxiliary>();
  114. InitScriptProgress = index++.ToString();
  115. gameObject.AddScript<ConfigManager>();
  116. InitScriptProgress = index++.ToString();
  117. gameObject.AddScript<ResourceManager>();
  118. InitScriptProgress = index++.ToString();
  119. gameObject.AddScript<TutorialManager>();
  120. InitScriptProgress = index++.ToString();
  121. gameObject.AddScript<LanguageManager>();
  122. InitScriptProgress = index++.ToString();
  123. gameObject.AddScript<AnimManager>();
  124. InitScriptProgress = index++.ToString();
  125. gameObject.AddScript<AudioManager>();
  126. InitScriptProgress = index++.ToString();
  127. gameObject.AddScript<AchieveManager>();
  128. InitScriptProgress = index++.ToString();
  129. gameObject.AddScript<UIManager>();
  130. InitScriptProgress = index++.ToString();
  131. gameObject.AddScript<SignManager>();
  132. InitScriptProgress = index++.ToString();
  133. gameObject.AddScript<Manager>();
  134. InitScriptProgress = index++.ToString();
  135. gameObject.AddScript<GardenManager>();
  136. InitScriptProgress = index++.ToString();
  137. gameObject.AddScript<PlayerManager>();
  138. InitScriptProgress = index++.ToString();
  139. gameObject.AddScript<HttpManager>();
  140. InitScriptProgress = index++.ToString();
  141. gameObject.AddScript<MiniGameManager>();
  142. InitScriptProgress = index++.ToString();
  143. gameObject.AddScript<InfoBoxManager>();
  144. InitScriptProgress = index++.ToString();
  145. gameObject.AddScript<SocialManager>();
  146. InitScriptProgress = index++.ToString();
  147. gameObject.AddScript<NickNameManager>();
  148. InitScriptProgress = index++.ToString();
  149. gameObject.AddScript<SFSManager>();
  150. InitScriptProgress = index++.ToString();
  151. gameObject.AddScript<PlazaRoomManager>();
  152. InitScriptProgress = index++.ToString();
  153. gameObject.AddScript<ChestManager>();
  154. InitScriptProgress = index++.ToString();
  155. gameObject.AddScript<RobotManager>();
  156. InitScriptProgress = index++.ToString();
  157. gameObject.AddScript<CDMinigamePanelManager>();
  158. InitScriptProgress = index++.ToString();
  159. gameObject.AddScript<EnterMinigamePanelManager>();
  160. InitScriptProgress = index++.ToString();
  161. gameObject.AddScript<PlazaroomMemberPanel>();
  162. InitScriptProgress = index++.ToString();
  163. gameObject.AddScript<FriendPanel>();
  164. InitScriptProgress = index++.ToString();
  165. gameObject.AddScript<AddFriendPanel>();
  166. InitScriptProgress = index++.ToString();
  167. gameObject.AddScript<MessagePanel>();
  168. InitScriptProgress = index++.ToString();
  169. gameObject.AddScript<FashionShowEditPage>();
  170. InitScriptProgress = index++.ToString();
  171. gameObject.AddScript<FashionShowCommentPanel>();
  172. InitScriptProgress = index++.ToString();
  173. gameObject.AddScript<FashionShowHomePage>();
  174. InitScriptProgress = index++.ToString();
  175. StartCoroutine(WaitToInit());
  176. }
  177. public static void InitEntrance()
  178. {
  179. if (Instance.CatchException)
  180. {
  181. DebugManager.TryCatch(Init, EnableDebugLab);
  182. }
  183. else
  184. {
  185. Init();
  186. }
  187. }
  188. public static void Init()
  189. {
  190. DebugText = GameObject.Find(CanvasLabel.U_DebugLab).GetComponent<Text>();
  191. DebugText.text = "Error code : 1";
  192. TutorialManager.NewplayerTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.NewplayerTutorial);
  193. DebugText.text = "Error code : 1-1";
  194. TutorialManager.memoryMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.MemoryMinigameTutorial);
  195. DebugText.text = "Error code : 1-2";
  196. TutorialManager.visitTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.VisitTutorial);
  197. DebugText.text = "Error code : 1-3";
  198. TutorialManager.dressroomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.DressroomTutorial);
  199. DebugText.text = "Error code : 1-4";
  200. TutorialManager.findMinigameTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.FindMinigameTutorial);
  201. DebugText.text = "Error code : 1-5";
  202. TutorialManager.plazaRoomTutorial = ConfigManager.GetBoolFormConfig(PlayerConfigLabel.TutorialPlazaRoom);
  203. DebugText.text = "Error code : 1-5-1";
  204. TutorialManager.NewplayerTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.NewplayerTutorialIndex);
  205. DebugText.text = "Error code : 1-6";
  206. TutorialManager.MemoryMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.MemoryMinigameTutorialIndex);
  207. DebugText.text = "Error code : 1-7";
  208. TutorialManager.VisitTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.VisitTutorialIndex);
  209. DebugText.text = "Error code : 1-8";
  210. TutorialManager.DressroomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.DressroomIndex);
  211. DebugText.text = "Error code : 1-9";
  212. TutorialManager.FindMinigameTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.FindMinigameTutorialIndex);
  213. DebugText.text = "Error code : 1-10";
  214. TutorialManager.PlazaRoomTutorialIndex = ConfigManager.GetIntFormConfig(PlayerConfigLabel.TutorialIndexPlazaRoom);
  215. DebugText.text = "Error code : 1-10-1";
  216. Bundle.LoadAtlasSprites();
  217. DebugText.text = "Error code : 1-11";
  218. for (int i = 0; i < RegistList.Count; i++)
  219. {
  220. DebugText.text = "Error code : 1-12-" + i;
  221. //Debug.Log(i + " " + RegistList[i].GetType());
  222. RegistList[i].InstantiatePrefabs();
  223. }
  224. DebugText.text = "Error code : 2";
  225. for (int i = 0; i < RegistList.Count; i++)
  226. {
  227. DebugText.text = "Error code : 2-" + i;
  228. RegistList[i].RegistReference();
  229. }
  230. DebugText.text = "Error code : 3";
  231. for (int i = 0; i < RegistList.Count; i++)
  232. {
  233. DebugText.text = "Error code : 3-" + i;
  234. RegistList[i].FirstInit();
  235. }
  236. DebugText.text = "Error code : 4";
  237. for (int i = 0; i < RegistList.Count; i++)
  238. {
  239. DebugText.text = "Error code : 4-" + i;
  240. RegistList[i].SecondInit();
  241. }
  242. DebugText.text = "Error code : 5";
  243. for (int i = 0; i < RegistList.Count; i++)
  244. {
  245. DebugText.text = "Error code : 5-" + i;
  246. RegistList[i].ThirdInit();
  247. RegistList[i].enabled = true;
  248. }
  249. DebugText.text = "Error code : 6";
  250. Inited = true;
  251. if (HttpManager.IsAnnounceReady)
  252. {
  253. ResourceManager.SetActive(CanvasLabel.C_NotifyParent, true);
  254. ResourceManager.Get(CanvasLabel.C_Notify).TweenForCG();
  255. }
  256. DebugText.text = "Error code : 7";
  257. PlayerManager.InitDressRoom();
  258. DebugText.text = "Error code : 8";
  259. Manager.FirstTimeLoginCallback(new JsonData());
  260. //debugLab.text = "Error code : 9";
  261. //SFSManager.GardenSmartFox.Connector.Connect();
  262. DebugText.text = "Error code : 10";
  263. StringFilter.Init();
  264. DebugText.text = "Error code : 11";
  265. IAPManager.Init();
  266. DebugText.text = "Error code : 12";
  267. VisitManager.Init();
  268. DebugText.text = "Error code : 13";
  269. SocialManager.InitRankPanel();
  270. if (Instance.DebugMode)
  271. {
  272. ActivateGame();
  273. }
  274. else
  275. {
  276. ShowLoadingPanel();
  277. }
  278. }
  279. public IEnumerator WaitToInit()
  280. {
  281. while (!Logo.Complete)
  282. {
  283. yield return null;
  284. }
  285. while (!Bundle.Complete)
  286. {
  287. yield return null;
  288. }
  289. while (ConfigManager.PlayerDocumentDamageFlag)
  290. {
  291. yield return null;
  292. }
  293. InitEntrance();
  294. }
  295. private static float LoadingDelayTime = 3f;
  296. private static void ShowLoadingPanel()
  297. {
  298. ResourceManager.Get(CanvasLabel.U_Group).TweenForCG();
  299. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 0;
  300. ResourceManager.SetText(CanvasLabel.U_Lab, Language.GetStr(LanguageLabel.UI__U_Lab));
  301. Auxiliary.Instance.DelayCall(ActivateGame, LoadingDelayTime);
  302. }
  303. public static void SetWarningTitleAndText()
  304. {
  305. SystemLanguage language = Application.systemLanguage;
  306. if (Instance.AuditEdition)
  307. {
  308. language = SystemLanguage.ChineseSimplified;
  309. }
  310. ResourceManager.SetText(CanvasLabel.U_WarningTitle, Language.GetStr(LanguageLabel.UI__U_WarningTitle, language));
  311. if (language == SystemLanguage.ChineseSimplified)
  312. {
  313. ResourceManager.SetText(CanvasLabel.U_WarningText, Language.GetStr(LanguageLabel.UI__U_WarningText, language));
  314. }
  315. else if (language == SystemLanguage.ChineseTraditional)
  316. {
  317. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  318. }
  319. else
  320. {
  321. ResourceManager.SetActive(CanvasLabel.U_WarningText, false);
  322. }
  323. }
  324. private static void ActivateGame()
  325. {
  326. ResourceManager.Get(CanvasLabel.U_LoadingPanel).TweenForCG();
  327. ResourceManager.Get<CanvasGroup>(CanvasLabel.C_Main).alpha = 1;
  328. AudioManager.GardenThemeAudio.TweenForAudio();
  329. }
  330. public static void EnableDebugLab()
  331. {
  332. ResourceManager.Get<CanvasGroup>(CanvasLabel.U_Group).alpha = 0;
  333. ResourceManager.Get<Text>(CanvasLabel.U_DebugLab).enabled = true;
  334. }
  335. }