mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新demo
更新demo
This commit is contained in:
@@ -1,130 +1,214 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建参数
|
||||
/// </summary>
|
||||
public class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// SBP构建参数
|
||||
/// </summary>
|
||||
public class SBPBuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成代码防裁剪配置
|
||||
/// </summary>
|
||||
public bool WriteLinkXML = true;
|
||||
/// <summary>
|
||||
/// 构建参数
|
||||
/// </summary>
|
||||
public abstract class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建输出的根目录
|
||||
/// </summary>
|
||||
public string BuildOutputRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存服务器地址
|
||||
/// </summary>
|
||||
public string CacheServerHost;
|
||||
/// <summary>
|
||||
/// 内置文件的根目录
|
||||
/// </summary>
|
||||
public string BuildinFileRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存服务器端口
|
||||
/// </summary>
|
||||
public int CacheServerPort;
|
||||
/// <summary>
|
||||
/// 构建管线
|
||||
/// </summary>
|
||||
public string BuildPipeline;
|
||||
|
||||
/// <summary>
|
||||
/// 修复图集资源冗余问题
|
||||
/// </summary>
|
||||
public bool FixSpriteAtlasRedundancy = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 构建的平台
|
||||
/// </summary>
|
||||
public BuildTarget BuildTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 可编程构建管线的参数
|
||||
/// </summary>
|
||||
public SBPBuildParameters SBPParameters;
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的根目录
|
||||
/// </summary>
|
||||
public string StreamingAssetsRoot;
|
||||
/// <summary>
|
||||
/// 是否启用共享资源打包
|
||||
/// </summary>
|
||||
public bool EnableSharePackRule = false;
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出的根目录
|
||||
/// </summary>
|
||||
public string BuildOutputRoot;
|
||||
/// <summary>
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
public bool VerifyBuildingResult = false;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的平台
|
||||
/// </summary>
|
||||
public BuildTarget BuildTarget;
|
||||
/// <summary>
|
||||
/// 资源包名称样式
|
||||
/// </summary>
|
||||
public EFileNameStyle FileNameStyle;
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线
|
||||
/// </summary>
|
||||
public EBuildPipeline BuildPipeline;
|
||||
/// <summary>
|
||||
/// 内置文件的拷贝选项
|
||||
/// </summary>
|
||||
public EBuildinFileCopyOption BuildinFileCopyOption;
|
||||
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode;
|
||||
/// <summary>
|
||||
/// 内置文件的拷贝参数
|
||||
/// </summary>
|
||||
public string BuildinFileCopyParams;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
/// <summary>
|
||||
/// 资源包加密服务类
|
||||
/// </summary>
|
||||
public IEncryptionServices EncryptionServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示普通日志
|
||||
/// </summary>
|
||||
public bool EnableLog = true;
|
||||
|
||||
/// <summary>
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
public bool VerifyBuildingResult = false;
|
||||
|
||||
/// <summary>
|
||||
/// 共享资源的打包规则
|
||||
/// </summary>
|
||||
public ISharedPackRule SharedPackRule = null;
|
||||
private string _pipelineOutputDirectory = string.Empty;
|
||||
private string _packageOutputDirectory = string.Empty;
|
||||
private string _packageRootDirectory = string.Empty;
|
||||
private string _buildinRootDirectory = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 资源的加密接口
|
||||
/// </summary>
|
||||
public IEncryptionServices EncryptionServices = null;
|
||||
/// <summary>
|
||||
/// 检测构建参数是否合法
|
||||
/// </summary>
|
||||
public virtual void CheckBuildParameters()
|
||||
{
|
||||
// 检测当前是否正在构建资源包
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.ThePipelineIsBuiding, "The pipeline is buiding, please try again after finish !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 补丁文件名称的样式
|
||||
/// </summary>
|
||||
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
|
||||
// 检测是否有未保存场景
|
||||
if (BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (EditorTools.HasDirtyScenes())
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源选项
|
||||
/// </summary>
|
||||
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
// 检测构建参数合法性
|
||||
if (BuildTarget == BuildTarget.NoTarget)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageName))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(BuildOutputRoot))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(BuildinFileRoot))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源的标签
|
||||
/// </summary>
|
||||
public string CopyBuildinFileTags = string.Empty;
|
||||
// 强制构建删除包裹目录
|
||||
if (BuildMode == EBuildMode.ForceRebuild)
|
||||
{
|
||||
string packageRootDirectory = GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩选项
|
||||
/// </summary>
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
// 检测包裹输出目录是否存在
|
||||
if (BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
string packageOutputDirectory = GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||
/// </summary>
|
||||
public bool DisableWriteTypeTree = false;
|
||||
// 如果输出目录不存在
|
||||
string pipelineOutputDirectory = GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 忽略类型树变化
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建管线的输出目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string GetPipelineOutputDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
||||
{
|
||||
_pipelineOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{YooAssetSettings.OutputFolderName}";
|
||||
}
|
||||
return _pipelineOutputDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本次构建的补丁输出目录
|
||||
/// </summary>
|
||||
public virtual string GetPackageOutputDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
||||
{
|
||||
_packageOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{PackageVersion}";
|
||||
}
|
||||
return _packageOutputDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本次构建的补丁根目录
|
||||
/// </summary>
|
||||
public virtual string GetPackageRootDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageRootDirectory))
|
||||
{
|
||||
_packageRootDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}";
|
||||
}
|
||||
return _packageRootDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置资源的根目录
|
||||
/// </summary>
|
||||
public virtual string GetBuildinRootDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_buildinRootDirectory))
|
||||
{
|
||||
_buildinRootDirectory = $"{BuildinFileRoot}/{PackageName}";
|
||||
}
|
||||
return _buildinRootDirectory;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user