Ejemplo n.º 1
0
        /// <summary>
        /// 刷新流目录
        /// </summary>
        private void RefreshStreammingFolder()
        {
            string streamingPath = Application.dataPath + "/StreamingAssets";

            EditorTools.ClearFolder(streamingPath);

            string outputRoot = AssetBundleBuilderHelper.GetDefaultOutputRootPath();

            AssetBundleBuilderHelper.CopyPackageToStreamingFolder(_assetBuilder.BuildTarget, outputRoot);
        }
        /// <summary>
        /// 刷新输出目录
        /// </summary>
        private void RefreshOutputMainFolder()
        {
            string outputPath = _assetBuilder.OutputPath;

            EditorTools.ClearFolder(outputPath);

            string outputRoot = AssetBundleBuilderHelper.GetDefaultOutputRootPath();

            AssetBundleBuilderHelper.CopyPackageToUnityManifestFolder(_assetBuilder.BuildTarget, outputRoot);
        }
Ejemplo n.º 3
0
        private void OnGUI()
        {
            // 初始化
            InitInternal();

            // 标题
            EditorGUILayout.LabelField("Build setup", _centerStyle);
            EditorGUILayout.Space();

            // 输出路径
            string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRootPath();
            string outputDirectory   = AssetBundleBuilder.MakeOutputDirectory(defaultOutputRoot, BuildTarget);

            EditorGUILayout.LabelField("Build Output", outputDirectory);

            BuildVersion   = EditorGUILayout.IntField("Build Version", BuildVersion, GUILayout.MaxWidth(250));
            CompressOption = (ECompressOption)EditorGUILayout.EnumPopup("Compression", CompressOption, GUILayout.MaxWidth(250));
            IsForceRebuild = GUILayout.Toggle(IsForceRebuild, "Froce Rebuild", GUILayout.MaxWidth(120));

            // 构建按钮
            EditorGUILayout.Space();
            if (GUILayout.Button("Build", GUILayout.MaxHeight(40)))
            {
                string title;
                string content;
                if (IsForceRebuild)
                {
                    title   = "警告";
                    content = "确定开始强制构建吗,这样会删除所有已有构建的文件";
                }
                else
                {
                    title   = "提示";
                    content = "确定开始增量构建吗";
                }
                if (EditorUtility.DisplayDialog(title, content, "Yes", "No"))
                {
                    // 清空控制台
                    EditorTools.ClearUnityConsole();

                    // 存储配置
                    SaveSettingsToPlayerPrefs();

                    EditorApplication.delayCall += ExecuteBuild;
                }
                else
                {
                    Debug.LogWarning("[Build] 打包已经取消");
                }
            }

            // 绘制工具栏部分
            OnDrawGUITools();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行构建
        /// </summary>
        private void ExecuteBuild()
        {
            string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRootPath();

            AssetBundleBuilder.BuildParameters buildParameters = new AssetBundleBuilder.BuildParameters();
            buildParameters.OutputRoot     = defaultOutputRoot;
            buildParameters.BuildTarget    = BuildTarget;
            buildParameters.BuildVersion   = BuildVersion;
            buildParameters.CompressOption = CompressOption;
            buildParameters.IsForceRebuild = IsForceRebuild;
            _assetBuilder.Run(buildParameters);
        }
Ejemplo n.º 5
0
        void IBuildTask.Run(BuildContext context)
        {
            // 注意:我们只有在强制重建的时候才会拷贝
            var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>();

            if (buildParameters.Parameters.IsForceRebuild)
            {
                // 清空流目录
                AssetBundleBuilderHelper.ClearStreamingAssetsFolder();

                // 拷贝内置文件
                var pipelineOutputDirectory = buildParameters.PipelineOutputDirectory;
                CopyBuildinFilesToStreaming(pipelineOutputDirectory);
            }
        }
        /// <summary>
        /// 获取资源包列表
        /// </summary>
        private List <PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters,
                                                     TaskGetBuildMap.BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext,
                                                     AssetBundleManifest unityManifest)
        {
            List <PatchBundle> result = new List <PatchBundle>();

            // 内置标记列表
            List <string> buildinTags = buildParameters.Parameters.GetBuildinTags();

            // 加载旧补丁清单
            PatchManifest oldPatchManifest = null;

            if (buildParameters.Parameters.IsForceRebuild == false)
            {
                oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
            }

            string[] allAssetBundles = unityManifest.GetAllAssetBundles();
            foreach (var bundleName in allAssetBundles)
            {
                string   path          = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
                string   hash          = HashUtility.FileMD5(path);
                string   crc           = HashUtility.FileCRC32(path);
                long     size          = FileUtility.GetFileSize(path);
                int      version       = buildParameters.Parameters.BuildVersion;
                string[] collectAssets = buildMapContext.GetCollectAssetPaths(bundleName);
                string[] depends       = unityManifest.GetDirectDependencies(bundleName);
                string[] tags          = buildMapContext.GetAssetTags(bundleName);
                bool     isEncrypted   = encryptionContext.IsEncryptFile(bundleName);
                bool     isBuildin     = IsBuildinBundle(tags, buildinTags);

                // 注意:如果文件没有变化使用旧版本号
                if (oldPatchManifest != null && oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle value))
                {
                    if (value.Hash == hash)
                    {
                        version = value.Version;
                    }
                }

                PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc, size, version, collectAssets, depends, tags);
                patchBundle.SetFlagsValue(isEncrypted, isBuildin);
                result.Add(patchBundle);
            }

            return(result);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 获取AssetBundle的完整名称
 /// </summary>
 public string GetAssetBundleFullName()
 {
     return(AssetBundleBuilderHelper.MakeAssetBundleFullName(AssetBundleLabel, AssetBundleVariant));
 }
Ejemplo n.º 8
0
 public BundleInfo(string bundleLabel, string bundleVariant)
 {
     AssetBundleLabel    = bundleLabel;
     AssetBundleVariant  = bundleVariant;
     AssetBundleFullName = AssetBundleBuilderHelper.MakeAssetBundleFullName(bundleLabel, bundleVariant);
 }
 public BuildParametersContext(BuildParameters parameters)
 {
     Parameters = parameters;
     PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
 }
Ejemplo n.º 10
0
        void IBuildTask.Run(BuildContext context)
        {
            var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>();

            // 检测构建平台是否合法
            if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget)
            {
                throw new Exception("请选择目标平台");
            }

            // 检测构建版本是否合法
            if (buildParameters.Parameters.BuildVersion <= 0)
            {
                throw new Exception("请先设置版本号");
            }

            // 检测输出目录是否为空
            if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
            {
                throw new Exception("输出目录不能为空");
            }

            // 检测资源收集配置文件
            if (AssetBundleCollectorSettingData.GetCollecterCount() == 0)
            {
                throw new Exception("配置的资源收集路径为空");
            }

            // 增量更新时候的必要检测
            if (buildParameters.Parameters.IsForceRebuild == false)
            {
                // 检测历史版本是否存在
                if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false)
                {
                    throw new Exception("没有发现任何历史版本,请尝试强制重建");
                }

                // 检测构建版本是否合法
                int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot);
                if (buildParameters.Parameters.BuildVersion <= maxPackageVersion)
                {
                    throw new Exception("构建版本不能小于历史版本");
                }

                // 检测补丁包是否已经存在
                string packageDirectory = buildParameters.GetPackageDirectory();
                if (Directory.Exists(packageDirectory))
                {
                    throw new Exception($"补丁包已经存在:{packageDirectory}");
                }

                // 检测内置资源标记是否一致
                PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
                if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
                {
                    throw new Exception($"增量更新时内置资源标记必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
                }
            }

            // 如果是强制重建
            if (buildParameters.Parameters.IsForceRebuild)
            {
                // 删除平台总目录
                string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}";
                if (EditorTools.DeleteDirectory(platformDirectory))
                {
                    BuildLogger.Log($"删除平台总目录:{platformDirectory}");
                }
            }

            // 如果输出目录不存在
            if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory))
            {
                BuildLogger.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 创建Readme文件到输出目录
        /// </summary>
        private void CreateReadmeFile(AssetBundleBuilder.BuildParametersContext buildParameters, AssetBundleManifest unityManifest)
        {
            string[] allAssetBundles = unityManifest.GetAllAssetBundles();

            // 删除旧文件
            string filePath = $"{buildParameters.PipelineOutputDirectory}/{PatchDefine.ReadmeFileName}";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            BuildLogger.Log($"创建说明文件:{filePath}");

            StringBuilder content = new StringBuilder();

            AppendData(content, $"构建平台:{buildParameters.Parameters.BuildTarget}");
            AppendData(content, $"构建版本:{buildParameters.Parameters.BuildVersion}");
            AppendData(content, $"构建时间:{DateTime.Now}");

            AppendData(content, "");
            AppendData(content, $"--着色器--");
            AppendData(content, $"IsCollectAllShaders:{AssetBundleCollectorSettingData.Setting.IsCollectAllShaders}");
            AppendData(content, $"ShadersBundleName:{AssetBundleCollectorSettingData.Setting.ShadersBundleName}");

            AppendData(content, "");
            AppendData(content, $"--配置信息--");
            for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++)
            {
                AssetBundleCollectorSetting.Collector wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i];
                AppendData(content, wrapper.ToString());
            }

            AppendData(content, "");
            AppendData(content, $"--构建参数--");
            AppendData(content, $"CompressOption:{buildParameters.Parameters.CompressOption}");
            AppendData(content, $"IsForceRebuild:{buildParameters.Parameters.IsForceRebuild}");
            AppendData(content, $"BuildinTags:{buildParameters.Parameters.BuildinTags}");
            AppendData(content, $"IsAppendHash:{buildParameters.Parameters.IsAppendHash}");
            AppendData(content, $"IsDisableWriteTypeTree:{buildParameters.Parameters.IsDisableWriteTypeTree}");
            AppendData(content, $"IsIgnoreTypeTreeChanges:{buildParameters.Parameters.IsIgnoreTypeTreeChanges}");

            AppendData(content, "");
            AppendData(content, $"--构建列表--");
            for (int i = 0; i < allAssetBundles.Length; i++)
            {
                AppendData(content, allAssetBundles[i]);
            }

            PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);

            {
                AppendData(content, "");
                AppendData(content, $"--内置列表--");
                foreach (var patchBundle in patchManifest.BundleList)
                {
                    if (patchBundle.IsBuildin)
                    {
                        AppendData(content, patchBundle.BundleName);
                    }
                }

                AppendData(content, "");
                AppendData(content, $"--更新列表--");
                foreach (var patchBundle in patchManifest.BundleList)
                {
                    if (patchBundle.Version == buildParameters.Parameters.BuildVersion)
                    {
                        AppendData(content, patchBundle.BundleName);
                    }
                }

                AppendData(content, "");
                AppendData(content, $"--加密列表--");
                foreach (var patchBundle in patchManifest.BundleList)
                {
                    if (patchBundle.IsEncrypted)
                    {
                        AppendData(content, patchBundle.BundleName);
                    }
                }
            }

            // 创建新文件
            File.WriteAllText(filePath, content.ToString(), Encoding.UTF8);
        }