yyl
2026-03-26 1ab047b5fdd933c38ba0519ec2e83a44512ea8d7
Main/Core/GameEngine/Launch/LaunchInHot.cs
@@ -1,8 +1,9 @@
using UnityEngine;
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using Cysharp.Threading.Tasks;
public class LaunchInHot : SingletonMonobehaviour<LaunchInHot>
{
@@ -17,19 +18,38 @@
    float surplusProgress = 0f;
    float surplusTime = 0f;
    bool launchStartFinish = false;
    public Action OnApplicationOut = null;
    void Start()
    async void Start()
    {
        launchStartFinish = false;
        try
        {
            await StartAsync();
        }
        catch (Exception ex)
        {
            Debug.LogError($"[LaunchInHot] Start 初始化异常,游戏无法继续: {ex}");
            return; // launchStartFinish 保持 false,Update 会一直等待(不会进入 Main.Init)
        }
        launchStartFinish = true;
    }
    async UniTask StartAsync()
    {
        System.Net.ServicePointManager.DefaultConnectionLimit = 100;//设置http最大连接数
        Application.backgroundLoadingPriority = ThreadPriority.High;
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        await VersionConfig.GetAsync();  // 确保 VersionConfig.config 在 SDKUtils.Init() 前已加载
        SDKUtils.Instance.Init();  //原sdk接口
        if (!AssetSource.isUseAssetBundle)
        {
            InitSystemMgr();
            await InitSystemMgr();
            UIManager.Instance.OpenWindowAsync<LaunchWin>().Forget();
            
@@ -39,7 +59,12 @@
        var yooAssetInitTask = new YooAssetInitTask();
        tasks.Enqueue(yooAssetInitTask);
        // AssetBundleInitTask removed — YooAssetInitTask handles all resource system initialization
#if !UNITY_WEBGL
#if UNITY_WEBGL
        // WebGL 不使用 BuiltInAssetCopyTask(无需拷贝内置资源),
        // 但仍需在 YooAsset 初始化后调用 InitSystemMgr 初始化 UIManager 等。
        var webGLSystemInitTask = new WebGLSystemInitTask();
        tasks.Enqueue(webGLSystemInitTask);
#else
        var builtInAssetCopyTask = new BuiltInAssetCopyTask();
        tasks.Enqueue(builtInAssetCopyTask);
#endif
@@ -83,6 +108,9 @@
                //tasks.Enqueue(assetCopyTask);
                tasks.Enqueue(getVersionInfoTask);
                break;
            case RuntimePlatform.WebGLPlayer:
                tasks.Enqueue(getVersionInfoTask);
                break;
        }
        tasks.Enqueue(checkAssetValidTask);
@@ -93,19 +121,24 @@
        tasks.Enqueue(launchFadeOutTask);
        CalculateExpectTotalTime();
    }
    public void InitSystemMgr()
    public async UniTask InitSystemMgr()
    {
        SpriteAtlasHandler.Register();
        ResManager.Instance.Init();
        UIManager.Instance.Init();
        StageManager.Instance.Init();
        LoginManager.Instance.Init();
        await UIManager.Instance.Init();
        await StageManager.Instance.Init();
        await LoginManager.Instance.Init();
    }
    void Update()
    {
        if (!launchStartFinish)
        {
            return;
        }
        if (!launchComplete)
        {
            if (currentTask == null)
@@ -113,10 +146,12 @@
                if (tasks.Count > 0)
                {
                    currentTask = tasks.Dequeue();
                    Debug.LogError("start currentTask is " + currentTask.GetType().Name);
                    currentTask.Begin();
                }
                else
                {
                    Debug.LogError("launchComplete = true");
                    launchComplete = true;
                }
            }