/// <summary>
        /// 资源转hash
        /// </summary>
        /// <param name="path"></param>
        /// <param name="uploadHttpApi"></param>
        static public void PublishAssetsToServer(string path)
        {
            foreach (var platform in BApplication.SupportPlatform)
            {
                //资源路径
                var sourcePath = IPath.Combine(path, BApplication.GetPlatformPath(platform));
                //输出路径
                var outputPath = IPath.Combine(IPath.ReplaceBackSlash(path), UPLOAD_FOLDER_SUFFIX, BApplication.GetPlatformPath(platform));
                if (Directory.Exists(sourcePath))
                {
                    //对比Assets.info 是否一致
                    var sourceAssetsInfoPath = IPath.Combine(sourcePath, BResources.ASSETS_INFO_PATH);
                    var outputAssetsInfoPath = IPath.Combine(outputPath, BResources.ASSETS_INFO_PATH);
                    if (File.Exists(sourceAssetsInfoPath) && File.Exists(outputAssetsInfoPath))
                    {
                        var sourceHash = FileHelper.GetMurmurHash3(sourceAssetsInfoPath);
                        var outputHash = FileHelper.GetMurmurHash3(outputAssetsInfoPath);
                        if (sourceHash == outputHash)
                        {
                            Debug.Log("【PublishPipeline】资源无改动,无需重新生成服务器文件.  -" + BApplication.GetPlatformPath(platform));
                            continue;
                        }
                    }

                    //获取资源版本号
                    var basePckInfo = BasePackageAssetsHelper.GetPacakgeBuildInfo(path, platform);
                    var versionNum  = basePckInfo.Version;
                    //发布资源处理前,处理前回调
                    BDFrameworkPipelineHelper.OnBeginPublishAssets(platform, sourcePath, versionNum);
                    //处理资源
                    var outdir = GenServerHashAssets(path, platform, versionNum);
                    //发布资源处理后,通知回调
                    BDFrameworkPipelineHelper.OnEndPublishAssets(platform, outdir, versionNum);
                    Debug.Log("发布资源处理完成! 请继承PublishPipeline生命周期,完成后续自动化部署到自己的文件服务器!");
                }
            }
        }
        /// <summary>
        /// 一键导出
        /// </summary>
        public void OnGUI_OneKeyExprot()
        {
            GUILayout.BeginVertical(GUILayout.Width(this.maxSize.x / 2), GUILayout.Height(350));
            {
                GUILayout.Label("资源发布:", EditorGUIHelper.GetFontStyle(Color.red, 15));

                EditorGUILayout.HelpBox("版本号采用三段式:0.0.1,前两位可以自定义,最后一位默认自增!\n默认导出地址:Devops/PublishAssets", MessageType.Info);
                GUILayout.Space(5);
                //
                foreach (var sp in BApplication.SupportPlatform)
                {
                    GUILayout.BeginHorizontal();
                    {
                        var isHas = selectPlatforms.Contains(sp);
                        //选择
                        var isSelcet = GUILayout.Toggle(isHas, $"生成{BApplication.GetPlatformPath(sp)}资产", GUILayout.Width(150));
                        //
                        if (isHas != isSelcet)
                        {
                            if (isSelcet)
                            {
                                selectPlatforms.Add(sp);
                            }
                            else
                            {
                                selectPlatforms.Remove(sp);
                            }
                        }

                        var    basePackageBuildInfo = BasePackageAssetsHelper.GetPacakgeBuildInfo(EXPORT_PATH, sp);
                        string setVersionNum        = "";
                        var    ret = platformVersionMap.TryGetValue(sp, out setVersionNum);
                        if (!ret)
                        {
                            platformVersionMap[sp] = basePackageBuildInfo.Version;
                        }
                        //根据即将设置信息开始解析
                        var vs          = platformVersionMap[sp].Split('.');
                        int bigNum      = 0;
                        int smallNum    = 0;
                        int additiveNum = 0;
                        bigNum      = int.Parse(vs[0]);
                        smallNum    = int.Parse(vs[1]);
                        additiveNum = int.Parse(vs[2]);
                        //version.info信息 渲染
                        GUILayout.Label("Ver:", GUILayout.Width(30));
                        bigNum = EditorGUILayout.IntField(bigNum, GUILayout.Width(20));
                        GUILayout.Label(".", GUILayout.Width(5));
                        smallNum = EditorGUILayout.IntField(smallNum, GUILayout.Width(20));
                        GUILayout.Label(".", GUILayout.Width(5));
                        GUILayout.Label(additiveNum.ToString(), GUILayout.Width(40));
                        //保存 设置信息
                        setVersionNum = string.Format("{0}.{1}.{2}", bigNum, smallNum, additiveNum);
                        //渲染预览信息
                        GUILayout.Space(10);
                        var newVersion = VersionNumHelper.AddVersionNum(basePackageBuildInfo.Version, setVersionNum);
                        GUILayout.Label($"预览: {basePackageBuildInfo.Version}  =>  {newVersion}");
                        platformVersionMap[sp] = setVersionNum;
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(2);
                }


                //
                GUILayout.Space(5);
                if (GUILayout.Button("一键导出所选平台资产(脚本、美术、表格)", GUILayout.Width(350), GUILayout.Height(30)))
                {
                    if (isBuilding)
                    {
                        return;
                    }

                    isBuilding = true;


                    //开始 生成资源
                    foreach (var sp in selectPlatforms)
                    {
                        BuildAssetsTools.BuildAllAssets(sp, EXPORT_PATH, platformVersionMap[sp]);
                        platformVersionMap.Remove(sp);
                    }

                    isBuilding = false;
                }

                //
                if (GUILayout.Button("热更资源转hash(生成服务器配置)", GUILayout.Width(350), GUILayout.Height(30)))
                {
                    //自动转hash
                    PublishPipelineTools.PublishAssetsToServer(EXPORT_PATH);
                }

                GUILayout.Space(20);
                GUILayout.Label("调试功能:", EditorGUIHelper.LabelH4);
                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("拷贝资源到Streaming", GUILayout.Width(175), GUILayout.Height(30)))
                    {
                        //路径
                        var source = IPath.Combine(EXPORT_PATH, BApplication.GetRuntimePlatformPath());
                        var target = IPath.Combine(Application.streamingAssetsPath, BApplication.GetRuntimePlatformPath());
                        if (Directory.Exists(target))
                        {
                            Directory.Delete(target, true);
                        }

                        //拷贝
                        FileHelper.CopyFolderTo(source, target);
                        AssetDatabase.Refresh();
                    }

                    if (GUILayout.Button("删除Streaming资源", GUILayout.Width(175), GUILayout.Height(30)))
                    {
                        var target = IPath.Combine(Application.streamingAssetsPath, BApplication.GetRuntimePlatformPath());
                        Directory.Delete(target, true);
                    }
                }
            }
            GUILayout.EndHorizontal();


            GUILayout.EndVertical();
        }
示例#3
0
        /// <summary>
        /// 构建所有资源
        /// </summary>
        /// <param name="platform">平台</param>
        /// <param name="outputPath">输出目录</param>
        /// <param name="setNewVersionNum">新版本号</param>
        static public void BuildAllAssets(RuntimePlatform platform, string outputPath, string setNewVersionNum = null)
        {
            var newVersionNum = "";
            //触发事件
            var lastPackageBuildInfo = BasePackageAssetsHelper.GetPacakgeBuildInfo(outputPath, platform);
            var lastVersionNum       = lastPackageBuildInfo.Version;

            //没有指定版本号,则需要触发版本号的实现逻辑
            if (string.IsNullOrEmpty(setNewVersionNum))
            {
                BDFrameworkPipelineHelper.OnBeginBuildAllAssets(platform, outputPath, lastVersionNum, out newVersionNum);
            }

            //项目没有实现提供新的版本号,则内部提供一个版本号
            if (string.IsNullOrEmpty(newVersionNum) || lastVersionNum == newVersionNum)
            {
                //没指定版本号
                if (string.IsNullOrEmpty(setNewVersionNum))
                {
                    newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, add: 1);
                }
                //指定版本号
                else
                {
                    newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, setNewVersionNum);
                }
            }


            //开始构建资源
            var _outputPath = Path.Combine(outputPath, BApplication.GetPlatformPath(platform));

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

            //1.编译脚本
            try
            {
                EditorWindow_ScriptBuildDll.RoslynBuild(outputPath, platform, ScriptBuildTools.BuildMode.Release);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //2.打包表格
            try
            {
                Excel2SQLiteTools.AllExcel2SQLite(outputPath, platform);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //3.打包资源
            try
            {
                //var config = BDEditorApplication.BDFrameWorkFrameEditorSetting.BuildAssetBundle;
                AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            //4.生成母包资源信息
            BasePackageAssetsHelper.GenBasePackageAssetBuildInfo(outputPath, platform, version: newVersionNum);

            //5.生成本地Assets.info配置
            //这个必须最后生成!!!!
            //这个必须最后生成!!!!
            //这个必须最后生成!!!!
            var allServerAssetItemList = PublishPipelineTools.GetAssetItemList(outputPath, platform);
            var csv            = CsvSerializer.SerializeToString(allServerAssetItemList);
            var assetsInfoPath = BResources.GetAssetsInfoPath(outputPath, platform);

            FileHelper.WriteAllText(assetsInfoPath, csv);
            //
            Debug.Log($"<color=yellow>{ BApplication.GetPlatformPath(platform)} - 旧版本:{lastPackageBuildInfo.Version} 新版本号:{newVersionNum} </color> ");
            //完成回调通知
            BDFrameworkPipelineHelper.OnEndBuildAllAssets(platform, outputPath, newVersionNum);
        }