示例#1
0
        public void Export()
        {
            List <AssetBundleBuild> list = new List <AssetBundleBuild>();
            //标记所有 asset bundle name
            var all = AssetBundleUtil.GetAll();

            for (int i = 0; i < all.Count; i++)
            {
                AssetTarget target = all[i];
                if (target.needSelfExport)
                {
                    AssetBundleBuild build = new AssetBundleBuild();
                    build.assetBundleName = target.bundleName;
                    build.assetNames      = new string[] { target.assetPath };
                    list.Add(build);
                }
            }
            string bundleSavePath = AssetBundleUtil.GetBundleDir();

            //开始打包
            BuildPipeline.BuildAssetBundles(bundleSavePath, list.ToArray(), BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget);
            AssetBundle         ab       = AssetBundle.LoadFromFile(bundleSavePath + "/AssetBundles");
            AssetBundleManifest manifest = ab.LoadAsset("AssetBundleManifest") as AssetBundleManifest;

            //hash
            for (int i = 0; i < all.Count; i++)
            {
                AssetTarget target = all[i];
                if (target.needSelfExport)
                {
                    Hash128 hash = manifest.GetAssetBundleHash(target.bundleName);
                    if (target.bundleCrc != hash.ToString())
                    {
                        if (AssetBundleBuildPanel.ABUpdateOpen)
                        {
                            string savePath     = Path.Combine(Path.GetTempPath(), target.bundleName);
                            string downloadPath = Path.Combine(Path.Combine(AssetBundleBuildPanel.TargetFolder, "AssetBundles"), target.bundleName);
                            File.Copy(savePath, downloadPath, true);
                            XMetaResPackage pack = new XMetaResPackage();
                            pack.buildinpath = target.bundleShortName;
                            pack.download    = string.Format("AssetBundles/{0}", target.bundleName);
                            pack.Size        = (uint)(new FileInfo(downloadPath)).Length;
                            if (pack.Size != (new FileInfo(downloadPath)).Length)
                            {
                                EditorUtility.DisplayDialog("Bundle ", target.bundleShortName + " is lager than UINTMAX!!!", "OK");
                            }
                            AssetBundleBuildPanel.assetBundleUpdate.Add(pack);
                            File.Copy(savePath, bundleSavePath, true);
                        }
                    }
                    target.bundleCrc = hash.ToString();
                }
            }
            SaveDepAll(all);
            ab.Unload(true);
            RemoveUnused(all);

            AssetDatabase.RemoveUnusedAssetBundleNames();
            AssetDatabase.Refresh();
        }
示例#2
0
        /// <summary>
        /// 删除未使用的AB,可能是上次打包出来的,而这一次没生成的
        /// </summary>
        /// <param name="all"></param>
        protected void RemoveUnused(List <AssetTarget> all)
        {
            HashSet <string> usedSet = new HashSet <string>();

            for (int i = 0; i < all.Count; i++)
            {
                AssetTarget target = all[i];
                if (target.needSelfExport)
                {
                    usedSet.Add(target.bundleName);
                }
            }

            DirectoryInfo di = new DirectoryInfo(AssetBundleUtil.GetBundleDir());

            FileInfo[] abFiles = di.GetFiles("*.ab");
            for (int i = 0; i < abFiles.Length; i++)
            {
                FileInfo fi = abFiles[i];
                if (usedSet.Add(fi.Name))
                {
                    XDebug.Log("Remove unused AB : ", fi.Name);
                    fi.Delete();
                    File.Delete(fi.FullName + ".manifest");
                }
            }
        }
示例#3
0
 public AssetTarget(Object o, FileInfo f, string ap)
 {
     asset           = o;
     file            = f;
     assetPath       = ap;
     bundleShortName = file.Name.ToLower();
     bundleName      = XCommon.singleton.XHash(AssetBundleUtil.ConvertToABName(assetPath)) + ".ab";
     bundleSavePath  = Path.Combine(AssetBundleUtil.GetBundleDir(), bundleName);
     _isFileChanged  = true;
     _metaHash       = "0";
 }
示例#4
0
 void InitDirs()
 {
     new DirectoryInfo(AssetBundleUtil.GetBundleDir()).Create();
     new FileInfo(AssetBundleUtil.GetCacheFile()).Directory.Create();
 }