예제 #1
0
        void OnInitializeDownload(string path, List <string> assetbundles, ResourcesManifest manifest)
        {
            this.path           = path;
            unCompleteDownloads = assetbundles;
            m_Manifest          = manifest;

            isDone    = false;
            errorCode = ErrorCode.None;
            completeDownloads.Clear();
            failedDownloads.Clear();

            if (unCompleteDownloads == null)
            {
                unCompleteDownloads = new List <string>();
            }

            totalSize     = 0;
            completedSize = 0;

            foreach (var item in unCompleteDownloads)
            {
                var ab = manifest.Find(item);
                if (ab == null)
                {
                    continue;
                }
                totalSize += ab.size;
            }
        }
예제 #2
0
        /// <summary>
        /// 加载ResourcesManifest文件
        /// </summary>
        public static ResourcesManifest LoadResourceManifestByPath(string path)
        {
            var result = new ResourcesManifest();

            result.Load(path);
            return(result);
        }
예제 #3
0
        void ExportResourcesManifestFile(AssetBundleManifest manifest)
        {
            if (manifest == null)
            {
                return;
            }
            var info = new ResourcesManifest();
            //读取所有AB
            //读取主manifest信息
            var rootDir      = PathResolver.BUILD_PATH;
            var manifestName = PathResolver.MAIN_MANIFEST_FILE_NAME;
            var desc         = new ResourcesManifestData.AssetBundleData();

            desc.assetBundleName = PathResolver.MAIN_MANIFEST_FILE_NAME;
            desc.size            = FileHelper.GetFileSize(rootDir + manifestName);
            info.data.assetbundles.Add(manifestName, desc);

            //读取其他AB信息
            foreach (var name in manifest.GetAllAssetBundles())
            {
                desc = new ResourcesManifestData.AssetBundleData();
                desc.assetBundleName = name;
                desc.size            = FileHelper.GetFileSize(rootDir + name);
                desc.isNative        = true;
                var ab = AssetBundle.LoadFromFile(rootDir + name);
                foreach (var asset in ab.GetAllAssetNames())
                {
                    desc.assets.Add(asset);
                }
                ab.Unload(false);
                info.data.assetbundles.Add(name, desc);
            }

            //读取旧的ResourcesManifest信息,同步一下其他信息
            var oldManiFest = new ResourcesManifest();

            oldManiFest.Load(PathResolver.EDITOR_RESOURCE_MANIFEST_FILE_PATH);
            if (oldManiFest.data != null && oldManiFest.data.assetbundles.Count > 0)
            {
                foreach (var assetBundle in oldManiFest.data.assetbundles.Values)
                {
                    if (string.IsNullOrEmpty(assetBundle.assetBundleName))
                    {
                        continue;
                    }
                    if (info.data.assetbundles.ContainsKey(assetBundle.assetBundleName))
                    {
                        info.data.assetbundles[assetBundle.assetBundleName].isNative = assetBundle.isNative;
                    }
                }
            }
            var buildConfig = AssetDatabase.LoadAssetAtPath <AssetBundleBuildConfig>(AssetBundleBuildPanel.savePath);

            info.data.version = buildConfig.version;
            //保存ResourcesInfo
            info.Save(PathResolver.EDITOR_RESOURCE_MANIFEST_FILE_PATH);
        }
예제 #4
0
        public bool Start(string path, List <string> assetbundles, ResourcesManifest manifest)
        {
            Abort();

            if (manifest == null)
            {
                isDone    = true;
                errorCode = ErrorCode.ParameterError;
                return(false);
            }

            OnInitializeDownload(path, assetbundles, manifest);
            OnUpdateState();
            OnDownloadAll();
            return(true);
        }
예제 #5
0
        void CompareAsset(
            ref List <string> downFiles,
            ref List <string> deleteFiles,
            AssetBundleManifest oldManifest,
            AssetBundleManifest newManifest,
            ResourcesManifest oldResManifest,
            ResourcesManifest newResManifest)
        {
            if (downFiles != null)
            {
                downFiles.Clear();
            }
            if (deleteFiles != null)
            {
                deleteFiles.Clear();
            }
            if (oldManifest == null)
            {
                Error(ErrorCode.LoadMainManifestFailed, "Local Manifest no Find");
                return;
            }
            if (newManifest == null)
            {
                Error(ErrorCode.LoadNewMainManifestFailed, "Load New MainManifest no Find");
                return;
            }
            if (newResManifest == null)
            {
                Error(ErrorCode.loadNewResourcesManiFestFailed, "Load New ResourceManifest no Find");
                return;
            }
            //标记位
            var old_ver_bit        = 1 << 0; //存在旧资源
            var new_ver_bit        = 1 << 1; //存在新资源
            var old_ver_native_bit = 1 << 2; //存在旧的本地资源
            var new_ver_native_bit = 1 << 3; //存在新的本地资源

            var tempDic = new Dictionary <string, int>();
            //标记旧资源
            var allAssetBundle = oldManifest.GetAllAssetBundles();

            foreach (var name in allAssetBundle)
            {
                SetDictionaryBit(ref tempDic, name, old_ver_bit);
            }
            //标记新资源
            var allNewAssetBundle = newManifest.GetAllAssetBundles();

            foreach (var name in allNewAssetBundle)
            {
                SetDictionaryBit(ref tempDic, name, new_ver_bit);
            }
            //标记旧本地资源
            if (oldResManifest.data != null && oldResManifest.data.assetbundles != null)
            {
                var itor = oldResManifest.data.assetbundles.GetEnumerator();
                while (itor.MoveNext())
                {
                    if (itor.Current.Value.isNative)
                    {
                        var name = itor.Current.Value.assetBundleName;
                        SetDictionaryBit(ref tempDic, name, old_ver_native_bit);
                    }
                }
            }
            //标记新的本地资源
            if (newResManifest.data != null && newResManifest.data.assetbundles != null)
            {
                var itor = newResManifest.data.assetbundles.GetEnumerator();
                while (itor.MoveNext())
                {
                    if (itor.Current.Value.isNative)
                    {
                        var name = itor.Current.Value.assetBundleName;
                        SetDictionaryBit(ref tempDic, name, new_ver_native_bit);
                    }
                }
            }

            //优先级:both>add>delete
            //both: 第0位和第1位标记的
            //delete : 第0位标记
            //add:第2位未标记,第3位标记的
            int both      = old_ver_bit | new_ver_bit;//2个版本都存在的资源
            var addFiles  = new List <string>();
            var bothFiles = new List <string>();

            using (var itor = tempDic.GetEnumerator())
            {
                while (itor.MoveNext())
                {
                    var name = itor.Current.Key;
                    var mask = itor.Current.Value;
                    if ((mask & new_ver_native_bit) == new_ver_native_bit &&
                        (mask & old_ver_native_bit) == 0)
                    {
                        addFiles.Add(name);
                    }
                    else if ((mask & both) == both)
                    {
                        bothFiles.Add(name);
                    }
                    else if ((mask & old_ver_bit) == old_ver_bit)
                    {
                        deleteFiles.Add(name);
                    }
                }
                itor.Dispose();
            }

            //加载下载缓存数据
            var download = new DownloadCache();

            download.Load(PathResolver.DOWNLOADCACHE_FILE_PATH);
            if (download.IsEmpty())
            {
                download = null;
            }

            //记录需要下载的文件
            {
                //加入新增文件
                downFiles.AddRange(addFiles);
                //判断同时存在文件的哈希
                foreach (var name in bothFiles)
                {
                    var fullName = PathResolver.GetFileFullName(name);
                    if (File.Exists(fullName))
                    {
                        //判断哈希是否相同
                        var oldHash = oldManifest.GetAssetBundleHash(name).ToString();
                        var newHash = newManifest.GetAssetBundleHash(name).ToString();
                        if (oldHash.CompareTo(newHash) == 0)
                        {
                            continue;
                        }
                        downFiles.Add(name);
                    }
                }

                //过滤已下载的文件
                if (null != download)
                {
                    var itor = download.data.assetBundles.GetEnumerator();
                    while (itor.MoveNext())
                    {
                        var elem     = itor.Current.Value;
                        var name     = elem.assetbundleName;
                        var fullName = PathResolver.GetFileFullName(name);
                        if (File.Exists(fullName))
                        {
                            var cacheHash = elem.hash;
                            var newHash   = newManifest.GetAssetBundleHash(name).ToString();
                            if (!string.IsNullOrEmpty(cacheHash) && cacheHash.CompareTo(newHash) == 0)
                            {
                                downFiles.Remove(name);
                            }
                        }
                    }
                }
            }
        }