Ejemplo n.º 1
0
        public override void Export()
        {
            try
            {
                base.Export();

                //Build Export Tree
                var all = AssetBundleUtils.GetAll();
                List <List <AssetTarget> > tree = new List <List <AssetTarget> >();
                foreach (AssetTarget target in all)
                {
                    target.AnalyzeIfDepTreeChanged();
                    BuildExportTree(target, tree, 0);
                }

                //Export
                this.Export(tree, 0);
                this.SaveDepAll(all);
                this.RemoveUnused(all);
                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Ejemplo n.º 2
0
        public virtual void Analyze()
        {
            var all = AssetBundleUtils.GetAll();

            foreach (AssetTarget target in all)
            {
                target.Analyze();
            }
            all = AssetBundleUtils.GetAll();
            foreach (AssetTarget target in all)
            {
                target.Merge();
            }
            all = AssetBundleUtils.GetAll();
            foreach (AssetTarget target in all)
            {
                target.BeforeExport();
            }
        }
Ejemplo n.º 3
0
        public override void Export()
        {
            #region 源代码
            base.Export();

            var platform = PathResolver.GetPlatformName();
            var filePath = Path.Combine(Path.Combine(Environment.CurrentDirectory, PathResolver.BundleSaveDirName), platform).Replace("\\", "/") + "/";
            if (Directory.Exists(filePath))
            {
                Directory.Delete(filePath, true);
            }
            Directory.CreateDirectory(filePath);

            List <AssetBundleBuild> list = new List <AssetBundleBuild>();
            //标记所有 asset bundle name
            var all = AssetBundleUtils.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);
                }
            }

            //开始打包
            BuildPipeline.BuildAssetBundles(
                PathResolver.BundleSavePath,
                list.ToArray(),
                BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle,
                EditorUserBuildSettings.activeBuildTarget);

#if UNITY_5_1 || UNITY_5_2
            AssetBundle ab = AssetBundle.CreateFromFile(PathResolver.BundleSavePath + PathResolver.GetPlatformForAssetBundles(Application.platform));
#else
            var ab = AssetBundle.LoadFromFile(PathResolver.BundleSavePath + "/" + PathResolver.GetPlatformName());
#endif
            var 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);
                    target.bundleCrc = hash.ToString();
                }
            }

            this.SaveDepAll(all);
            this.SaveSpriteAll(all);
            this.SaveAssetAll(all);
            this.ExportResourcesManifestFile(manifest);
            ab.Unload(true);
            this.RemoveUnused(all);


            AssetDatabase.RemoveUnusedAssetBundleNames();
            AssetDatabase.Refresh();

            Debug.Log("[Assets]Build Finish!");
            #endregion
        }