Initializer.cs 11 KB

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