Addressable loads the scene asynchronously and gets the loading progress

Project scenario:

At the beginning, I used the PercentComplete function to get the loading progress, and found that it was calculated from 0.85 each time. It was not allowed. The official document explained: "PercentComplete will reflect the progress of the overall operation, and will not accurately represent only the download percentage or load into memory. % of the download.", "To get the exact download percentage, use GetDownloadStatus()."

GetDownloadStatus().Percent: Returns the percentage of calculation complete as a floating point value between 0 and 1.


solution:

Use GetDownloadStatus().Percent to get the download progress

    void Start()
    {
    
    
        StartCoroutine(LoadScene());
    }

    IEnumerator LoadScene()
    {
    
    
        // 异步加载场景(如果场景资源没有下载,会自动下载),
        var handle = Addressables.LoadSceneAsync("SceneName");
        if (handle.Status == AsyncOperationStatus.Failed)
        {
    
    
            Debug.LogError("场景加载异常: " + handle.OperationException.ToString());
            yield break;
        }
        while (!handle.IsDone)
        {
    
    
            // 下载进度(0~1)
            var percentage = handle.GetDownloadStatus().Percent;
            Debug.Log("进度: " + percentage);
            yield return null;
        }

        Debug.Log("场景加载完毕");
    }

Guess you like

Origin blog.csdn.net/zjjjjjjj_/article/details/127905676