GameApplction.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Core.AssetLoadTool.Asset;
  2. using Core.Language;
  3. using Fort23.Core;
  4. using Fort23.Mono;
  5. using Fort23.Mono.UpdateAsset;
  6. using Fort23.UTool;
  7. using GameLogic.Combat;
  8. using GameLogic.Combat.CombatTool;
  9. using GameLogic.Combat.CombatType;
  10. using GameLogic.CombatScenesTool;
  11. using GameUI;
  12. #if UNITY_EDITOR
  13. using UnityEditor;
  14. #endif
  15. using UnityEngine;
  16. using UnityEngine.UI;
  17. using Utility.CTween;
  18. using Utility.UITool;
  19. public class GameApplction : IGameStart
  20. {
  21. public ShaderVariantCollection ShaderVariantCollection;
  22. public BundleLoadType BundleLoadType;
  23. public string h5Url;
  24. private Entity _root;
  25. private Entity _scene;
  26. // public bool isTest;
  27. public int levelBattleId = 1;
  28. private GameStartUIPanel gameStartUIPanel;
  29. public async void StartGame(LoadType LoadType, string h5Url, GameStartUIPanel gameStartUIPanel,
  30. System.Action LoadFinish)
  31. {
  32. GameUpdateAsset.Instance.Init(h5Url);
  33. this.gameStartUIPanel = gameStartUIPanel;
  34. gameStartUIPanel.ShowMassge("开始加载资源");
  35. gameStartUIPanel.SetSlider(0);
  36. this.h5Url = h5Url;
  37. BundleLoadType = (BundleLoadType)LoadType;
  38. GameObject gameObject = new GameObject("app");
  39. gameObject.AddComponent<GameApplctionMono>();
  40. await InitGameApplication();
  41. LoadFinish?.Invoke();
  42. UIManager.Instance.Canvas.gameObject.SetActive(true);
  43. Debug.Log("初始化完成");
  44. }
  45. private async CTask InitGameApplication()
  46. {
  47. _scene = new Scene();
  48. _root = new Entity();
  49. _root.Parent = _scene;
  50. _root.AddComponent<TimerComponent>();
  51. _root.AddComponent<CoroutineLockComponent>();
  52. gameStartUIPanel.ShowMassge("loadBundle");
  53. gameStartUIPanel.SetSlider(0.15f);
  54. AssetBundleLoadManager.Instance.BundleLoadType = BundleLoadType;
  55. AssetBundleLoadManager.Instance.h5Url = h5Url;
  56. await AssetBundleLoadManager.Instance.InitAssetsManager(null);
  57. gameStartUIPanel.ShowMassge("loadConfig");
  58. gameStartUIPanel.SetSlider(0.25f);
  59. await ConfigComponent.Instance.Preload();
  60. await AnimationCurveManager.Instance.Init();
  61. UGUIPackLoad uguiPackLoad = new UGUIPackLoad();
  62. UGUIPackManager.Instance.SetIUGUIPackLoad(uguiPackLoad);
  63. await uguiPackLoad.InitPack();
  64. gameStartUIPanel.ShowMassge("loadLanguage");
  65. gameStartUIPanel.SetSlider(0.45f);
  66. await LanguageManager.Instance.InitManager();
  67. _root.AddComponent<StaticUpdater>();
  68. _root.AddComponent<UIManager, Transform>(null);
  69. gameStartUIPanel.ShowMassge("loadUI");
  70. gameStartUIPanel.SetSlider(0.55f);
  71. await UIManager.Instance.InitUI();
  72. CustomTweenManager.Init();
  73. PlayerManager.Instance.Init();
  74. // PlayerManager.Instance.InitTestHero();
  75. //主UI加载
  76. MainSceneController.Instance.Init();
  77. await CombatDrive.Instance.Init();
  78. StartCombatInfo startCombatInfo = new StartCombatInfo();
  79. startCombatInfo.CombatType = CombatType.LevelBattle;
  80. #if UNITY_EDITOR
  81. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  82. if (testCombatHeroConfig != null)
  83. {
  84. startCombatInfo.CombatType = CombatType.TestCombat;
  85. }
  86. #endif
  87. startCombatInfo.levelBattleId = AccountFileInfo.Instance.playerData.levelBattle;
  88. CombatDrive.Instance.AddCombatController(new CombatController());
  89. gameStartUIPanel.ShowMassge("loadCombat");
  90. gameStartUIPanel.SetSlider(0.95f);
  91. await CombatDrive.Instance.StartCombat(startCombatInfo);
  92. gameStartUIPanel.ShowMassge("loadFinish");
  93. gameStartUIPanel.SetSlider(1f);
  94. }
  95. }