BuildParameters.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEditor;
  6. namespace YooAsset.Editor
  7. {
  8. /// <summary>
  9. /// 构建参数
  10. /// </summary>
  11. public abstract class BuildParameters
  12. {
  13. /// <summary>
  14. /// 构建输出的根目录
  15. /// </summary>
  16. public string BuildOutputRoot;
  17. /// <summary>
  18. /// 内置文件的根目录
  19. /// </summary>
  20. public string BuildinFileRoot;
  21. /// <summary>
  22. /// 构建管线名称
  23. /// </summary>
  24. public string BuildPipeline;
  25. /// <summary>
  26. /// 构建资源包类型
  27. /// </summary>
  28. public int BuildBundleType;
  29. /// <summary>
  30. /// 构建的平台
  31. /// </summary>
  32. public BuildTarget BuildTarget;
  33. /// <summary>
  34. /// 构建的包裹名称
  35. /// </summary>
  36. public string PackageName;
  37. /// <summary>
  38. /// 构建的包裹版本
  39. /// </summary>
  40. public string PackageVersion;
  41. /// <summary>
  42. /// 构建的包裹备注
  43. /// </summary>
  44. public string PackageNote;
  45. /// <summary>
  46. /// 清空构建缓存文件
  47. /// </summary>
  48. public bool ClearBuildCacheFiles = false;
  49. /// <summary>
  50. /// 使用资源依赖缓存数据库
  51. /// 说明:开启此项可以极大提高资源收集速度!
  52. /// </summary>
  53. public bool UseAssetDependencyDB = false;
  54. /// <summary>
  55. /// 启用共享资源打包
  56. /// </summary>
  57. public bool EnableSharePackRule = false;
  58. /// <summary>
  59. /// 对单独引用的共享资源进行独立打包
  60. /// 说明:关闭该选项单独引用的共享资源将会构建到引用它的资源包内!
  61. /// </summary>
  62. public bool SingleReferencedPackAlone = true;
  63. /// <summary>
  64. /// 验证构建结果
  65. /// </summary>
  66. public bool VerifyBuildingResult = false;
  67. /// <summary>
  68. /// 资源包名称样式
  69. /// </summary>
  70. public EFileNameStyle FileNameStyle = EFileNameStyle.HashName;
  71. /// <summary>
  72. /// 内置文件的拷贝选项
  73. /// </summary>
  74. public EBuildinFileCopyOption BuildinFileCopyOption = EBuildinFileCopyOption.None;
  75. /// <summary>
  76. /// 内置文件的拷贝参数
  77. /// </summary>
  78. public string BuildinFileCopyParams;
  79. /// <summary>
  80. /// 资源包加密服务类
  81. /// </summary>
  82. public IEncryptionServices EncryptionServices;
  83. private string _pipelineOutputDirectory = string.Empty;
  84. private string _packageOutputDirectory = string.Empty;
  85. private string _packageRootDirectory = string.Empty;
  86. private string _buildinRootDirectory = string.Empty;
  87. /// <summary>
  88. /// 检测构建参数是否合法
  89. /// </summary>
  90. public virtual void CheckBuildParameters()
  91. {
  92. // 检测当前是否正在构建资源包
  93. if (UnityEditor.BuildPipeline.isBuildingPlayer)
  94. {
  95. string message = BuildLogger.GetErrorMessage(ErrorCode.ThePipelineIsBuiding, "The pipeline is buiding, please try again after finish !");
  96. throw new Exception(message);
  97. }
  98. // 检测构建参数合法性
  99. if (BuildTarget == BuildTarget.NoTarget)
  100. {
  101. string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !");
  102. throw new Exception(message);
  103. }
  104. if (string.IsNullOrEmpty(BuildOutputRoot))
  105. {
  106. string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
  107. throw new Exception(message);
  108. }
  109. if (string.IsNullOrEmpty(BuildinFileRoot))
  110. {
  111. string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
  112. throw new Exception(message);
  113. }
  114. if (string.IsNullOrEmpty(BuildPipeline))
  115. {
  116. string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !");
  117. throw new Exception(message);
  118. }
  119. if (BuildBundleType == (int)EBuildBundleType.Unknown)
  120. {
  121. string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !");
  122. throw new Exception(message);
  123. }
  124. if (string.IsNullOrEmpty(PackageName))
  125. {
  126. string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
  127. throw new Exception(message);
  128. }
  129. if (string.IsNullOrEmpty(PackageVersion))
  130. {
  131. string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
  132. throw new Exception(message);
  133. }
  134. // 设置默认备注信息
  135. if (string.IsNullOrEmpty(PackageNote))
  136. {
  137. PackageNote = DateTime.Now.ToString();
  138. }
  139. }
  140. /// <summary>
  141. /// 获取构建管线的输出目录
  142. /// </summary>
  143. /// <returns></returns>
  144. public virtual string GetPipelineOutputDirectory()
  145. {
  146. if (string.IsNullOrEmpty(_pipelineOutputDirectory))
  147. {
  148. _pipelineOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{YooAssetSettings.OutputFolderName}";
  149. }
  150. return _pipelineOutputDirectory;
  151. }
  152. /// <summary>
  153. /// 获取本次构建的补丁输出目录
  154. /// </summary>
  155. public virtual string GetPackageOutputDirectory()
  156. {
  157. if (string.IsNullOrEmpty(_packageOutputDirectory))
  158. {
  159. _packageOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{PackageVersion}";
  160. }
  161. return _packageOutputDirectory;
  162. }
  163. /// <summary>
  164. /// 获取本次构建的补丁根目录
  165. /// </summary>
  166. public virtual string GetPackageRootDirectory()
  167. {
  168. if (string.IsNullOrEmpty(_packageRootDirectory))
  169. {
  170. _packageRootDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}";
  171. }
  172. return _packageRootDirectory;
  173. }
  174. /// <summary>
  175. /// 获取内置资源的根目录
  176. /// </summary>
  177. public virtual string GetBuildinRootDirectory()
  178. {
  179. if (string.IsNullOrEmpty(_buildinRootDirectory))
  180. {
  181. _buildinRootDirectory = $"{BuildinFileRoot}/{PackageName}";
  182. }
  183. return _buildinRootDirectory;
  184. }
  185. }
  186. }