GameApplction.cs 3.7 KB

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