Support addressable location

支持可寻址资源定位
This commit is contained in:
hevinci
2022-04-28 17:23:31 +08:00
parent 775c724840
commit 2cb006f3d9
40 changed files with 799 additions and 235 deletions
@@ -202,6 +202,7 @@ namespace YooAsset.Editor
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildVersion = _buildVersionField.value;
buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable;
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
@@ -11,6 +11,11 @@ namespace YooAsset.Editor
/// </summary>
public string BundleName { private set; get; }
/// <summary>
/// 可寻址地址
/// </summary>
public string Address { private set; get; }
/// <summary>
/// 资源路径
/// </summary>
@@ -53,8 +58,9 @@ namespace YooAsset.Editor
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
public BuildAssetInfo(string assetPath, bool isRawAsset, bool notWriteToAssetList)
public BuildAssetInfo(string address, string assetPath, bool isRawAsset, bool notWriteToAssetList)
{
Address = address;
AssetPath = assetPath;
IsRawAsset = isRawAsset;
NotWriteToAssetList = notWriteToAssetList;
@@ -26,7 +26,7 @@ namespace YooAsset.Editor
{
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
{
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
buildAssetInfo.SetBundleName(collectAssetInfo.BundleName);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
@@ -100,7 +100,7 @@ namespace YooAsset.Editor
var buildAssetInfo = pair.Value;
if (buildAssetInfo.BundleNameIsValid() == false)
{
string shaderBundleName = AssetBundleCollector.CollectShaderBundleName(buildAssetInfo.AssetPath);
string shaderBundleName = AssetBundleGrouperSettingHelper.CollectShaderBundleName(buildAssetInfo.AssetPath);
if (string.IsNullOrEmpty(shaderBundleName) == false)
{
buildAssetInfo.SetBundleName(shaderBundleName);
@@ -108,7 +108,7 @@ namespace YooAsset.Editor
else
{
string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath));
bundleName = AssetBundleCollector.CorrectBundleName(bundleName, false);
bundleName = AssetBundleGrouperSettingHelper.CorrectBundleName(bundleName, false);
buildAssetInfo.SetBundleName(bundleName);
}
}
@@ -29,6 +29,11 @@ namespace YooAsset.Editor
/// </summary>
public int BuildVersion;
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable = false;
/// <summary>
/// 启用自动分包机制
/// 说明:自动分包机制可以实现资源零冗余
@@ -33,6 +33,11 @@ namespace YooAsset.Editor
/// </summary>
public int BuildVersion;
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 启用自动分包机制
/// </summary>
@@ -28,10 +28,11 @@ namespace YooAsset.Editor
// 创建新补丁清单
PatchManifest patchManifest = new PatchManifest();
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
// 创建补丁清单文件
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
@@ -126,7 +127,8 @@ namespace YooAsset.Editor
/// <summary>
/// 获取资源列表
/// </summary>
private List<PatchAsset> GetAllPatchAsset(BuildMapContext buildMapContext, PatchManifest patchManifest)
private List<PatchAsset> GetAllPatchAsset(AssetBundleBuilder.BuildParametersContext buildParameters,
BuildMapContext buildMapContext, PatchManifest patchManifest)
{
List<PatchAsset> result = new List<PatchAsset>(1000);
foreach (var bundleInfo in buildMapContext.BundleInfos)
@@ -135,6 +137,10 @@ namespace YooAsset.Editor
foreach (var assetInfo in assetInfos)
{
PatchAsset patchAsset = new PatchAsset();
if (buildParameters.Parameters.EnableAddressable)
patchAsset.Address = assetInfo.Address;
else
patchAsset.Address = string.Empty;
patchAsset.AssetPath = assetInfo.AssetPath;
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
@@ -29,6 +29,7 @@ namespace YooAsset.Editor
buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders;
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
if (isRawFile)
{
if (bundleInfo.BuildinAssets.Count != 1)
throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
throw new Exception($"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
continue;
}