Esempio n. 1
0
    public IEnumerator UpdateBundles()
    {
        if (!initializationFinished)
        {
            yield break;
        }
        initializationFinished = false;
        StopAll();

        foreach (var req in succeedRequest.Values)
        {
            var ab = req.assetBundle;
            if (ab)
            {
                ab.Unload(false);
            }
        }

        string[] disposeRequestArray = new string[succeedRequest.Count + failedRequest.Count];
        succeedRequest.Keys.CopyTo(disposeRequestArray, 0);
        failedRequest.Keys.CopyTo(disposeRequestArray, succeedRequest.Count);
        foreach (var req in disposeRequestArray)
        {
            DisposeBundle(req);
        }

        long downloadFileSize = 0;

        for (int i = 0; i < updateList.Count; ++i)
        {
            var info = updateList[i];
            UpdateFinishFielCount = i + 1;
            var www = WWW.LoadFromCacheOrDownload(info.url, info.version);
            do
            {
                yield return(null);

                UpdateFinishSize = downloadFileSize + (long)(www.progress * info.versionInfo.size);
            } while (!www.isDone);
            www.Dispose();
            downloadFileSize += info.versionInfo.size;
            UpdateFinishSize  = downloadFileSize;
            info.needDownload = false;
            BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        }
        CurrentVesion = UpdateVersion;
        PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
        initializationFinished = true;
    }
Esempio n. 2
0
    private void mergeVersion(VersionInfo versionInfo)
    {
        if (!versionInfo.isValue)
        {
            return;
        }

        var newList = new List <BundleDownloadInfo>();

        foreach (var bundleVersionInfo in versionInfo.bundles)
        {
            var bundleName = bundleVersionInfo.name;
            BundleDownloadInfo downloadInfo = null;
            if (bundleDict.ContainsKey(bundleName))
            {
                downloadInfo = bundleDict[bundleName];
            }
            else
            {
                downloadInfo         = new BundleDownloadInfo();
                downloadInfo.name    = bundleName;
                downloadInfo.version = 0;
            }

            if (downloadInfo.versionInfo == null || downloadInfo.versionInfo.crc != bundleVersionInfo.crc ||
                (!downloadInfo.localBundle && !Caching.IsVersionCached(downloadInfo.url, downloadInfo.version)))
            {
                downloadInfo.versionInfo = bundleVersionInfo;
                downloadInfo.version++;
                downloadInfo.localBundle  = versionInfo.rootUrl == localRootUrl;
                downloadInfo.url          = formatUrl(versionInfo.rootUrl, bundleVersionInfo.requestString);
                downloadInfo.needDownload = !downloadInfo.localBundle;
            }

            newList.Add(downloadInfo);
        }

        bundles    = newList;
        bmConfiger = versionInfo.bmConfiger ?? bmConfiger;

        BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        BMUtility.SaveToPersistentData(bmConfiger, CONFIGER_CACHE_NAME);
    }
Esempio n. 3
0
    void Update()
    {
        if (!ConfigLoaded)
        {
            return;
        }

        // Check if any WWW is finished or errored
        List <string> newFinisheds = new List <string>();
        List <string> newFaileds   = new List <string>();

        foreach (WWWRequest request in processingRequest.Values)
        {
            if (request.error != null)
            {
                if (request.triedTimes - 1 < bmConfiger.downloadRetryTime)
                {
                    // Retry download
                    request.CreatWWW();
                }
                else
                {
                    request.DisposeWWW();
                    newFaileds.Add(request.bundleName);
                    Debug.LogError("{BM}Download Bundle " + request.bundleName + "URL:" + request.info.url + "failed for " + request.triedTimes + " times.\nError: " + request.error);
                }
            }
            else if (request.isDone)
            {
                request.DisposeWWW();
                newFinisheds.Add(request.bundleName);
            }
        }

        // Move complete bundles out of downloading list
        foreach (string finishedUrl in newFinisheds)
        {
            var req = processingRequest[finishedUrl];
            if (req.info.needDownload)
            {
                req.info.needDownload = false;
            }
            req.assetBundle.name = req.bundleName;
            dbgDownloadBundles.Add(req.assetBundle);
            succeedRequest.Add(finishedUrl, req);
            processingRequest.Remove(finishedUrl);
        }

        // Move failed bundles out of downloading list
        foreach (string finishedUrl in newFaileds)
        {
            if (!failedRequest.ContainsKey(finishedUrl))
            {
                failedRequest.Add(finishedUrl, processingRequest[finishedUrl]);
            }
            processingRequest.Remove(finishedUrl);
        }

        // Start download new bundles
        int waitingIndex = 0;

        while (processingRequest.Count < bmConfiger.downloadThreadsCount &&
               waitingIndex < waitingRequests.Count)
        {
            WWWRequest curRequest = waitingRequests[waitingIndex++];

            bool canStartDownload = curRequest.info == null || isBundleDependenciesReady(curRequest.info.name);
            if (canStartDownload)
            {
                waitingRequests.Remove(curRequest);
                curRequest.CreatWWW();
                processingRequest.Add(curRequest.bundleName, curRequest);
            }
        }

        if (needSaveDownloadInfoCache && processingRequest.Count == 0 && waitingRequests.Count == 0)
        {
            needSaveDownloadInfoCache = false;
            BMUtility.SaveToPersistentData(bundles, DOWNLOAD_INFO_CACHE_NAME);
        }
    }    //update end