update editor code

BuildParameters增加共享资源的打包规则字段
pull/102/head
hevinci 2023-04-22 17:22:59 +08:00
parent 1b75f4b6e9
commit 9a729f921e
10 changed files with 70 additions and 10 deletions

View File

@ -275,6 +275,7 @@ namespace YooAsset.Editor
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.PackageVersion = _buildVersionField.value;
buildParameters.VerifyBuildingResult = true;
buildParameters.ShareAssetPackRule = new DefaultShareAssetPackRule();
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@ -157,7 +157,7 @@ namespace YooAsset.Editor
/// <summary>
/// 计算共享资源包的完整包名
/// </summary>
public void CalculateShareBundleName(bool uniqueBundleName, string packageName, string shadersBundleName)
public void CalculateShareBundleName(IShareAssetPackRule packRule, bool uniqueBundleName, string packageName, string shadersBundleName)
{
if (CollectorType != ECollectorType.None)
return;
@ -173,8 +173,7 @@ namespace YooAsset.Editor
{
if (_referenceBundleNames.Count > 1)
{
IPackRule packRule = PackDirectory.StaticPackRule;
PackRuleResult packRuleResult = packRule.GetPackRuleResult(new PackRuleData(AssetPath));
PackRuleResult packRuleResult = packRule.GetPackRuleResult(AssetPath);
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
}
else

View File

@ -76,9 +76,14 @@ namespace YooAsset.Editor
/// 验证构建结果
/// </summary>
public bool VerifyBuildingResult = false;
/// <summary>
/// 加密类
/// 共享资源的打包规则
/// </summary>
public IShareAssetPackRule ShareAssetPackRule = null;
/// <summary>
/// 资源的加密接口
/// </summary>
public IEncryptionServices EncryptionServices = null;

View File

@ -13,7 +13,8 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.PackageName);
var buildParameters = buildParametersContext.Parameters;
var buildMapContext = CreateBuildMap(buildParameters.BuildMode, buildParameters.ShareAssetPackRule, buildParameters.PackageName);
context.SetContextObject(buildMapContext);
BuildLogger.Log("构建内容准备完毕!");
@ -24,7 +25,7 @@ namespace YooAsset.Editor
/// <summary>
/// 资源构建上下文
/// </summary>
public BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
public BuildMapContext CreateBuildMap(EBuildMode buildMode, IShareAssetPackRule packRule, string packageName)
{
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
@ -101,7 +102,7 @@ namespace YooAsset.Editor
var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
buildAssetInfo.CalculateShareBundleName(command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
buildAssetInfo.CalculateShareBundleName(packRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
}
// 9. 移除不参与构建的资源

View File

@ -40,6 +40,10 @@ namespace YooAsset.Editor
throw new Exception("首包资源标签不能为空!");
}
// 检测共享资源打包规则
if (buildParameters.ShareAssetPackRule == null)
throw new Exception("共享资源打包规则不能为空!");
#if UNITY_WEBGL
if (buildParameters.EncryptionServices != null)
{

View File

@ -60,8 +60,6 @@ namespace YooAsset.Editor
[DisplayName("资源包名: 父类文件夹路径")]
public class PackDirectory : IPackRule
{
public static PackDirectory StaticPackRule = new PackDirectory();
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
{
string bundleName = Path.GetDirectoryName(data.AssetPath);

View File

@ -0,0 +1,16 @@
using System;
using System.IO;
using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultShareAssetPackRule : IShareAssetPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
string bundleName = Path.GetDirectoryName(assetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b8606481370397489cb3aa21e726d9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@

namespace YooAsset.Editor
{
/// <summary>
/// 共享资源的打包规则
/// </summary>
public interface IShareAssetPackRule
{
/// <summary>
/// 获取打包规则结果
/// </summary>
PackRuleResult GetPackRuleResult(string assetPath);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1ed930b0cc1db1742b0a131ca476bd82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: