예제 #1
0
        // 运营活动资源
        public DownloadInfo(string directoryName, string fileNameWithMd5, ActivityResType resType, Action <DownloadInfo> _callback)
        {
            string fileNameWithNoSuffix = fileNameWithMd5.Substring(0, fileNameWithMd5.Length - 3);//移除".ab"

            string[] subPaths = fileNameWithNoSuffix.Split('_');

            //------------------ 拼接fileName
            for (int i = 0; i < subPaths.Length - 2; i++)
            {
                if (i > 0)
                {
                    fileName += "/";
                }
                fileName += subPaths[i];
            }
            fileName += ".ab";

            //------------------ 提取md5
            fileMd5 = subPaths[subPaths.Length - 1];

            onComplete = _callback;
            if (resType == ActivityResType.Activity)
            {
                url = string.Format("{0}/activities/{1}/{2}", FilePathTools.AssetBundleDownloadPath, directoryName, fileNameWithMd5);
            }
            else if (resType == ActivityResType.Bundle)
            {
                url = string.Format("{0}/bundles/{1}/{2}", FilePathTools.AssetBundleDownloadPath, directoryName, fileNameWithMd5);
            }
            else
            {
                DebugUtil.LogError("DownloadInfo Error:" + resType);
            }
            savePath = string.Format("{0}/{1}", FilePathTools.persistentDataPath_Platform, fileName);
            tempPath = string.Format("{0}/{1}.temp", FilePathTools.persistentDataPath_Platform, fileName);
        }
        // 下载运营活动/礼包的资源
        public DownloadInfo DownloadInSeconds(string directoryName, string fileNameWithMd5, ActivityResType resType, Action <DownloadInfo> onComplete)
        {
            fileNameWithMd5 = FilePathTools.NormalizePath(fileNameWithMd5);
            DownloadInfo info = new DownloadInfo(directoryName, fileNameWithMd5, resType, onComplete);

            pendingDownloads.Enqueue(info);
            return(info);
        }