GameApplction.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #if !UNITY_EDITOR
  59. AssetBundleLoadManager.Instance.AddBundleTask("fb010shader", delegate(BundleLoadBasic basic, object o)
  60. {
  61. if (basic.currBundle != null)
  62. {
  63. basic.currBundle.LoadAllAssets<Shader>();
  64. Shader.WarmupAllShadersWait();
  65. }
  66. }, null);
  67. #endif
  68. gameStartUIPanel.ShowMassge("loadConfig");
  69. gameStartUIPanel.SetSlider(0.25f);
  70. await ConfigComponent.Instance.Preload();
  71. await AnimationCurveManager.Instance.Init();
  72. UGUIPackLoad uguiPackLoad = new UGUIPackLoad();
  73. UGUIPackManager.Instance.SetIUGUIPackLoad(uguiPackLoad);
  74. await uguiPackLoad.InitPack();
  75. gameStartUIPanel.ShowMassge("loadLanguage");
  76. gameStartUIPanel.SetSlider(0.45f);
  77. await LanguageManager.Instance.InitManager();
  78. _root.AddComponent<StaticUpdater>();
  79. _root.AddComponent<UIManager, Transform>(null);
  80. gameStartUIPanel.ShowMassge("loadUI");
  81. gameStartUIPanel.SetSlider(0.55f);
  82. await AudioManager.Instance.InitMainAudio();
  83. await UIManager.Instance.InitUI();
  84. CustomTweenManager.Init();
  85. PlayerManager.Instance.Init();
  86. // PlayerManager.Instance.InitTestHero();
  87. //主UI加载
  88. MainSceneController.Instance.Init();
  89. await CombatDrive.Instance.Init();
  90. StartCombatInfo startCombatInfo = new StartCombatInfo();
  91. startCombatInfo.CombatType = CombatType.LevelBattle;
  92. #if UNITY_EDITOR
  93. TestCombatHeroConfig testCombatHeroConfig = GameObject.FindObjectOfType<TestCombatHeroConfig>();
  94. if (testCombatHeroConfig != null)
  95. {
  96. startCombatInfo.CombatType = CombatType.TestCombat;
  97. }
  98. #endif
  99. startCombatInfo.levelBattleId = AccountFileInfo.Instance.playerData.levelBattle;
  100. CombatDrive.Instance.AddCombatController(new CombatController());
  101. gameStartUIPanel.ShowMassge("loadCombat");
  102. gameStartUIPanel.SetSlider(0.95f);
  103. await CombatDrive.Instance.StartCombat(startCombatInfo);
  104. gameStartUIPanel.ShowMassge("loadFinish");
  105. gameStartUIPanel.SetSlider(1f);
  106. }
  107. }