cocos creator 2.2.0 热更新字节数获取的问题(查出问题,请官方确认)

使用了官方的热更新方案一样获取不正确,求大佬看下呀@panda

我之前在帖子提过这个bug,用的 2.2.0 beta3,楼主你用的哪个版本,不知道他们解决了没有,你要不在这个帖子下面再去提bug,我之前新建帖子也没人回。
https://forum.cocos.com/t/cocos-creator-v2-2-0-10-16-rc-5/82831/130

这个帖子我有回复过,现在帖子太长被关闭了只能重新开贴.我现在用的是正式版本,依旧有问题.获取字节数有问题只能用文件数量来做进度,这体验就比较差了.
热更新方案感觉官方过于封装了,其实可以简单暴露一些基础接口,实现过程给开发者去实现,这样可以避免底层出问题了无从下手.

我也碰到了,不清楚是所有人都有問題,还是只是个别。
改了下AssetsManagerEx::onProgress 这个方法能用了,

:joy:请问能分享下修改方案吗?

void AssetsManagerEx::onProgress(double total, double downloaded, const std::string& /url/, const std::string &customId)
{
if (customId == VERSION_ID || customId == MANIFEST_ID)
{
_totalDownloaded += downloaded;
float currentPercent = 100 * _totalDownloaded / _totalSize;
_percent = currentPercent;
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, customId);
return;
}
else
{
// Calcul total downloaded
bool found = false;
// _totalDownloaded = 0;
for (auto it = _downloadedSize.begin(); it != _downloadedSize.end(); ++it)
{
if (it->first == customId)
{
it->second = downloaded;
found = true;
_totalDownloaded += it->second;
}

    }
    // Collect information if not registed
    if (!found)
    {
        // Set download state to DOWNLOADING, this will run only once in the download process
        _tempManifest->setAssetDownloadState(customId, Manifest::DownloadState::DOWNLOADING);
        // Register the download size information
        _downloadedSize.emplace(customId, downloaded);
        // Check download unit size existance, if not exist collect size in total size
        if (_downloadUnits[customId].size == 0)
        {
            _totalSize += total;
            _sizeCollected++;
            // All collected, enable total size
            if (_sizeCollected == _totalToDownload)
            {
                _totalEnabled = true;
            }
        }
    }

    if (_totalEnabled && _updateState == State::UPDATING)
    {
        float currentPercent = 100 * _totalDownloaded / _totalSize;
        // Notify at integer level change
        if ((int)currentPercent != (int)_percent) {
            _percent = currentPercent;
            // Notify progression event
            dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_PROGRESSION, customId);
        }
    }
}

}

修改AssetsManagerEx.cpp是个误区,需要修改Cocos2dxDownloader.java

1赞

今晚在ios测试该更新问题又不存在bug,所以把目光转向安卓的加载层去,发现2.2.0版本安卓的加载器Cocos2dxDownloader.java做了大量的修改,从中发现该类221行和259行均有调用downloader.onProgress的方法,
但参数传输的顺序有错,downloader.onProgress(id, current, len, total); 其中current和len的位置应该调换,其中len对应onProgress方法的downloadBytes(触发当前onProgrees单次的加载字节), current为从该任务开始加载到当前所有字节,所以应该对应downloadNow. 希望官方看下,我目标自己修改了后重新打包就解决了热更新字节数获取不正确的问题了.@jare

4赞

兄弟,我按你的改了cpp,安卓可以正常获取了,但ios有问题,你那边可以吗?

明白了,cpp不需要改,只要按你的,把Cocos2dxDownloader.java 那两行改正就行,,厉害:+1:

对的,C++层的AssetsManagerEx.cpp不需要做修改,这个类跟之前的版本是一致的,没做修改.
新版本主要是对Cocos2dxDownloader.java做了调整.

mark

mark

mark

大佬改问题,而我只能选择规避:joy:

顶一下 @jare

感谢你的支持和帮助!游戏因你更美好。

马克下了

想知道有没有办法在更新前获取更新大小?

我调换了位置为什么还是不能获取呢