tuyoogame / YooAsset

unity3d resources management system
https://www.yooasset.com/
Apache License 2.0
2.37k stars 466 forks source link

Unity版本2022.3.35、YooAsset版本号2.2.0-preview/2.2.1-perview,发布webgl平台时候,在unity运行下载包正常,浏览器会卡住逻辑 #324

Open damahan opened 1 month ago

damahan commented 1 month ago

如题,在发布到本机搭建的python运行http服务器上时候发生的问题,在unity运行一切逻辑正常,但是打包发布到webgl之后,在浏览器打开,可以看到下载资源包的逻辑,downloader.TotalDownloadBytes;已经下载完毕 677564/677564,但是下载文件数始终为0?本人的下载部分逻辑如下:

IEnumerator<float> Downloader()
{
    int downloadingMaxNum = 10;
    int failedTryAgain = 3;
    var downloader = package.CreateResourceDownloader(downloadingMaxNum, failedTryAgain);
    Debug.Log($"----------------start.Downloader-------------");
    result_txt.text = "start.Downloader";
    yield return Timing.WaitUntilTrue(()=>(downloader != null));

    if (downloader.TotalDownloadCount == 0)
    {
        Debug.Log("Not found any download files !");

    }
    else
    {
        // 发现新更新文件后,挂起流程系统
        // 注意:开发者需要在下载前检测磁盘空间不足
        int totalDownloadCount = downloader.TotalDownloadCount;
        long totalDownloadBytes = downloader.TotalDownloadBytes;
        Debug.Log($"download.start    ----->totalDownloadCount:{totalDownloadCount}   --------->totalDownloadBytes:{totalDownloadBytes}");

        downloader.OnDownloadErrorCallback = DownLoadError;
        downloader.OnDownloadProgressCallback = OnDownLoadProcess;
        downloader.BeginDownload();
        yield return Timing.WaitUntilTrue(()=>(downloader.IsDone));
        // 超时检查
        float startTime = Time.time;
        bool isTimeout = false;

        while (!downloader.IsDone)
        {
            if (Time.time - startTime > YooAssetTimeOutSec)
            {
                isTimeout = true;
                break;
            }

            Debug.Log($"yooasset.downloader.status:{downloader.Status}     down.process:{downloader.Progress}");
            Debug.Log($"Downloading... {downloader.CurrentDownloadCount}/{downloader.TotalDownloadCount} files, {downloader.CurrentDownloadBytes}/{downloader.TotalDownloadBytes} bytes.");
            yield return Timing.WaitForSeconds(1); ; // 等待下一帧
        }

        // 检测下载结果
        if (isTimeout)
        {
            // 处理超时逻辑
            Debug.Log("下载超时");
            // 你可以在这里取消下载或采取其他措施
            downloader.CancelDownload(); // 假设有取消下载的方法
        }
        else if (downloader.Status == EOperationStatus.Succeed)
        {
            // 下载成功
            Debug.Log("资源下载完毕");
        }
        else
        {
            shouldRestartWorkflow = true;
            // 下载失败
            Debug.Log("资源下载失败了???");
        }

    }
}

private void DownLoadError(string name,string error)
{
    Debug.Log("下载失败了?!?!");
}

private void OnDownLoadProcess(int totalCount,int currentCount,long totalBytes,long currentBytes)
{
    result_txt.text = $"Progress: {currentBytes}/{totalBytes} (Count: {currentCount}/{totalCount})";
    Debug.Log($"download.callback-->Progress: {currentBytes}/{totalBytes} (Count: {currentCount}/{totalCount})");
}

浏览器打印如截图:

image
gmhevinci commented 1 month ago

需要确认一下,WebPlayMode模式下,你用的哪个文件系统类 因为默认自带的文件系统里 DefaultWebFileSystem.cs 未实现下载功能。

        public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
        {
            throw new System.NotImplementedException();
        }
Ganlei4052 commented 2 weeks ago

需要确认一下,WebPlayMode模式下,你用的哪个文件系统类 因为默认自带的文件系统里 DefaultWebFileSystem.cs 未实现下载功能。

        public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param)
        {
            throw new System.NotImplementedException();
        }

这个应该用哪个呢?需要自己实现吗?

gmhevinci commented 2 weeks ago

YOO2,2x版本 微信小游戏平台 应该使用WechatFileSystem