Пример #1
0
        public virtual BundleManifest CopyAssetBundleAndManifest(DirectoryInfo src, DirectoryInfo dest, List <IBundleModifier> bundleModifierChain = null, IBundleFilter bundleFilter = null)
        {
            if (!src.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Not found the directory '{0}'.", src.FullName));
            }

            try
            {
                string         json     = File.ReadAllText(System.IO.Path.Combine(src.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"));
                BundleManifest manifest = BundleManifest.Parse(json);
                manifest = this.CopyAssetBundle(manifest, src, dest, bundleModifierChain, bundleFilter);
                if (manifest != null)
                {
                    File.WriteAllText(System.IO.Path.Combine(dest.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"), manifest.ToJson());
                }
                return(manifest);
            }
            catch (System.Exception e)
            {
                throw new System.Exception(string.Format("Copy AssetBundles failure from {0} to {1}.", src.FullName, dest.FullName), e);
            }
        }
Пример #2
0
        public virtual void Build(string outputPath, BuildTarget buildTarget, BuildAssetBundleOptions options, string version, List <IBundleModifier> bundleModifierChain = null)
        {
            if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
            {
                if (!EditorUserBuildSettings.SwitchActiveBuildTarget(BuildPipeline.GetBuildTargetGroup(buildTarget), buildTarget))
                {
                    throw new System.Exception("Switch BuildTarget failure.");
                }
            }

            if (string.IsNullOrEmpty(outputPath))
            {
                throw new System.ArgumentNullException("outputPath");
            }

            if (string.IsNullOrEmpty(version))
            {
                throw new System.ArgumentNullException("version");
            }


            string platformOutput = this.GetPlatformOutput(outputPath, buildTarget);
            string genOutput      = this.GetGenOutput(outputPath, buildTarget);
            string versionOutput  = this.GetVersionOutput(outputPath, buildTarget, version);

            if (((options & BuildAssetBundleOptions.ForceRebuildAssetBundle) > 0) && Directory.Exists(genOutput))
            {
                Directory.Delete(genOutput, true);
            }

            if (Directory.Exists(versionOutput))
            {
                Directory.Delete(versionOutput, true);
            }

            if (!Directory.Exists(genOutput))
            {
                Directory.CreateDirectory(genOutput);
            }

            if (!Directory.Exists(versionOutput))
            {
                Directory.CreateDirectory(versionOutput);
            }

            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(genOutput, options, buildTarget);

            if (manifest == null)
            {
                throw new System.Exception("Build failure.");
            }

#if UNITY_5_6_OR_NEWER
            if ((options & BuildAssetBundleOptions.DryRunBuild) > 0)
            {
                return;
            }
#endif

            try
            {
                AssetDatabase.StartAssetEditing();

                BundleManifest    lastVersionBundleManifest = this.GetPreviousBundleManifest(outputPath, buildTarget, version);
                List <BundleInfo> lastBundles = new List <BundleInfo>();
                if (lastVersionBundleManifest != null)
                {
                    lastBundles.AddRange(lastVersionBundleManifest.GetAll());
                }

                BundleManifest bundleManifest = this.CreateBundleManifest(genOutput, manifest, version);

                bundleManifest = this.CopyAssetBundle(bundleManifest, new DirectoryInfo(genOutput), new DirectoryInfo(versionOutput), bundleModifierChain);
                File.WriteAllText(string.Format("{0}/{1}", versionOutput, BundleSetting.ManifestFilename), bundleManifest.ToJson());

                File.WriteAllText(string.Format("{0}/{1}_{2}.csv", platformOutput, ManifestPrefix, version), this.ToCSV(lastBundles.ToArray(), bundleManifest.GetAll()));
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
            }
        }