Example #1
0
    /// <summary>
    /// ��ʽ��Url
    /// </summary>
    /// <param name="urlstr"></param>
    /// <returns></returns>
    string formatUrl(string urlstr, bool onlyServer)
    {
        Uri url;

        if (!isAbsoluteUrl(urlstr) || !Path.IsPathRooted(urlstr))
        {
            //urlstr = urlstr.Substring(urlstr.LastIndexOf("/") + 1, urlstr.Length - urlstr.LastIndexOf("/") - 1);
            urlstr = Path.GetFileName(urlstr);
            string[] bundleNmaeAndExtension = urlstr.Split('.');
            string   bundleName             = bundleNmaeAndExtension[0];
            if (bundleNmaeAndExtension.Length < 2)
            {
                urlstr = urlstr + "." + bmConfiger.bundleSuffix;
            }
            if (buildStatesDict.ContainsKey(bundleName))
            {
                BundleBuildState bundleState = buildStatesDict[bundleName];
                BundleData       bd          = bundleDict[bundleName];
#if UNITY_STANDALONE_WIN
                if (!onlyServer && LoadBundleManager.getInstace().isExistsForConfiger(bundleState.bundleName, bundleState.version, bundleState.crc))
                {
                    string rootpath = downloadLoadRootUrl + "/" + bd.bundleRelativePath;
                    url = new Uri(new Uri(rootpath + '/'), urlstr);
                    if (!File.Exists(url.AbsoluteUri))
                    {
                        rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                        url      = new Uri(new Uri(rootpath + '/'), urlstr);
                    }
                }
                else
                {
                    string rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                    url = new Uri(new Uri(rootpath + '/'), urlstr);
                }
#else
                string rootpath = downloadRootUrl + "/" + bd.bundleRelativePath;
                url = new Uri(new Uri(rootpath + '/'), urlstr);
#endif
            }
            else
            {
                url = new Uri(new Uri(downloadRootUrl + "/"), urlstr);
            }
        }
        else
        {
            url = new Uri(urlstr);
        }

        return(url.AbsoluteUri);
    }
 void Awake()
 {
     instance = this;
     DontDestroyOnLoad(this.gameObject);
     context = Context.GetApplicationContext();
 }
Example #3
0
    void Update()
    {
        if (!ConfigLoaded)
        {
            return;
        }

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

        foreach (WWWRequest request in processingRequest.Values)
        {
            //�����������ļ��ص���Ϣ
            if (progressManager != null && progressManager.setCurrentDownloadFileEvent != null)
            {
                progressManager.setCurrentDownloadFileEvent(request.url);
            }
            if (progressManager != null && progressManager.setCurrentDownloadProgressEvent != null)
            {
                float progress = ProgressOfBundle(Path.GetFileName(request.url));
                progressManager.setCurrentDownloadProgressEvent(progress);
            }

            if (request.www.error != null)
            {
                if (request.triedTimes - 1 < bmConfiger.downloadRetryTime)
                {
                    // Retry download
                    request.CreatWWW();
                }
                else
                {
                    newFaileds.Add(request.url);
                    Debug.LogError("Download " + request.url + " failed for " + request.triedTimes + " times.\nError: " + request.www.error);
                }
            }
            else if (request.www.isDone)
            {
                newFinisheds.Add(request.url);
            }
        }

        List <BundleBuildState> saveBundleStates = new List <BundleBuildState>();
        List <BundleData>       saveBundleData   = new List <BundleData>();

        // �����سɹ��İ����б��processingRequest��ɾ�������뵽succeedRequest��
        foreach (string finishedUrl in newFinisheds)
        {
            succeedRequest.Add(finishedUrl, processingRequest[finishedUrl]);
            //var bundle = processingRequest[finishedUrl].www.assetBundle;
            processingRequest.Remove(finishedUrl);

#if UNITY_STANDALONE_WIN
            //�����سɹ������ݱ��浽����
            string bundleName = separateUrl(finishedUrl);
            if (bundleDict.ContainsKey(bundleName))
            {
                saveBundleData.Add(bundleDict[bundleName]);
                saveBundleStates.Add(buildStatesDict[bundleName]);
                string filePath = downloadLoadRootUrl + "/" + bundleDict[bundleName].bundleRelativePath + "/"
                                  + bundleName + "." + bmConfiger.bundleSuffix;
                FileUtils.saveFileFromStream(succeedRequest[finishedUrl].www.bytes, filePath);
            }
#endif
        }
#if UNITY_STANDALONE_WIN
        LoadBundleManager.getInstace().changeBundleData(saveBundleData, LoadBundleManager.BundleOperate.Add);
        LoadBundleManager.getInstace().changeBundleStates(saveBundleStates, LoadBundleManager.BundleOperate.Add);
#endif

        // ������ʧ�ܵİ����б��processingRequest��ɾ�������뵽faileRequest��
        foreach (string finishedUrl in newFaileds)
        {
            if (!failedRequest.ContainsKey(finishedUrl))
            {
                failedRequest.Add(finishedUrl, processingRequest[finishedUrl]);
            }
            processingRequest.Remove(finishedUrl);
        }

        // ��ʼ�����°�
        int waitingIndex = 0;
        while (processingRequest.Count < bmConfiger.downloadThreadsCount &&
               waitingIndex < waitingRequests.Count)
        {
            WWWRequest curRequest = waitingRequests[waitingIndex++];

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