예제 #1
0
 public void UpdateToNew()
 {
     if (HasNewVersion)
     {
         // 读取本地ab包的清单
         localAssetBundleList = localManager.AseetBundleList;
         // 读取远程ab包的清单
         remoteAssetBundleList = remoteManager.AseetBundleList;
         IEnumerable <AssetBundleInfo> updateList;
         if (localAssetBundleList.Count == 0)
         {
             updateList = remoteAssetBundleList;
         }
         else
         {
             // 获取更新列表
             updateList = from remoteab in remoteAssetBundleList
                          from localab in localAssetBundleList
                          where localab.HasNewVersion(remoteab) || !localAssetBundleList.Contains(remoteab)
                          select remoteab;
         }
         // 开始下载
         remoteManager.DownloadAssetBundles(updateList, remoteVersion);
         // 清空本地不用的ab包
         localManager.Clear(ABUtility.GetDeleteABList(localAssetBundleList, remoteAssetBundleList));
         // 写入新的信息文件
         localManager.Version         = remoteVersion;
         localManager.AseetBundleList = remoteAssetBundleList;
     }
 }
예제 #2
0
            /// <summary>
            /// 清除不再使用的ab包
            /// </summary>
            /// <param name="deleteList"></param>
            public void Clear(IEnumerable <ABInfo> oldList, IEnumerable <ABInfo> newList)
            {
                var deleteList = ABUtility.GetDeleteABList(oldList, newList);

                foreach (var name in deleteList)
                {
                    File.Delete(Path.Combine(LocalAssetBundlePath, name));
                    File.Delete(Path.Combine(LocalAssetBundlePath, name + ".manifest"));
                }
                // 清除空目录
                ABUtility.ClearEmtry(LocalAssetBundlePath);
            }
예제 #3
0
 private void Create()
 {
     if (string.IsNullOrEmpty(Version))
     {
         throw new InvalidDataException("必须填写版本号");
     }
     if (Version == GetCurrentVersion())
     {
         Debug.LogWarning("不使用新的版本号将导致新的版本无法被察觉, 从而导致无法升级");
     }
     if (!Directory.Exists(OutputPath))
     {
         Directory.CreateDirectory(OutputPath);
         var manifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
         if (manifest)
         {
             CreateResourceListJsonFile(manifest);
             CreateVersionJsonFile();
             ABLocalManager.ClearEmtry(OutputPath);
         }
         else
         {
             Clear();
         }
     }
     else
     {
         var ab          = AssetBundle.LoadFromFile(Path.Combine(OutputPath, "AssetBundles"));
         var oldManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
         var oldABList   = ABUtility.CreateABListFromManifest(oldManifest);
         ab.Unload(true);
         var newManifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
         if (newManifest)
         {
             CreateResourceListJsonFile(newManifest);
             CreateVersionJsonFile();
             var newABList  = ABUtility.CreateABListFromManifest(newManifest);
             var deleteList = ABUtility.GetDeleteABList(oldABList, newABList);
             foreach (var name in deleteList)
             {
                 File.Delete(Path.Combine(OutputPath, name));
                 File.Delete(Path.Combine(OutputPath, name + ".manifest"));
             }
             ABLocalManager.ClearEmtry(OutputPath);
         }
         else
         {
             Clear();
         }
     }
 }