Compare commits

...

20 Commits
1.1.1 ... 1.2.0

Author SHA1 Message Date
hevinci
e340af90ed Update CHANGELOG.md 2022-07-18 12:17:21 +08:00
hevinci
7fa7cc4af1 Update package.json 2022-07-18 12:17:02 +08:00
hevinci
ca3c011f34 Update AssetBundleBuilder
增加配置保存按钮。
2022-07-18 12:05:40 +08:00
hevinci
669339d5b4 Update AssetBundleCollector
增加配置保存按钮。
2022-07-18 12:04:46 +08:00
hevinci
c6567650fe Update Update document 2022-07-18 11:25:09 +08:00
hevinci
3ae70412fa Update AssetBundleBuilder 2022-07-18 11:24:47 +08:00
hevinci
d575850f9f Update package.json 2022-07-15 19:47:33 +08:00
hevinci
d1439da54e Update AssetBundleBuilder
支持可编程构建管线
2022-07-15 19:34:59 +08:00
何冠峰
89022d3df4 Merge pull request #24 from LiuOcean/main
Update UniTask.YooAsset README
2022-07-13 17:03:39 +08:00
L
3c38fe6155 Update UniTask.YooAsset README 2022-07-13 15:29:23 +08:00
hevinci
e68ece6925 Update AssetBundleBuilder 2022-07-13 11:59:15 +08:00
hevinci
ea9b8874cc Update decryption services
解密服务接口增加解密文件信息。
2022-07-13 10:48:49 +08:00
hevinci
475efd90fc Update FAQ.md 2022-07-13 10:33:21 +08:00
hevinci
682605d5c2 Update document 2022-07-12 16:06:44 +08:00
hevinci
256844ddf5 Update AssetBundleCollector
打包资源忽略Gizmos资源文件。
2022-07-12 15:38:26 +08:00
何冠峰
96f95bbd99 Merge pull request #21 from axn777/branch_share_ignore
如果依赖的是运行时以外的,不打入 share AssetBundle包
2022-07-12 15:00:56 +08:00
何冠峰
4f7bb945e0 Merge pull request #22 from wqaetly/ForPr
fix:修复ShaderVariantCollection刷新不及时问题
2022-07-12 14:54:26 +08:00
NKG丶MadLife
0d69d779f6 fix:修复ShaderVariantCollection刷新不及时问题 2022-07-10 22:12:09 +08:00
axn777
5df26908fb 如果依赖的是运行时以外的,不打入 share AssetBundle包 2022-07-08 01:41:20 +08:00
hevinci
fb5e289de0 Update patch system
优化代码逻辑结构
2022-07-07 19:10:44 +08:00
44 changed files with 726 additions and 187 deletions

View File

@@ -2,6 +2,7 @@
[仓库链接](https://github.com/Cysharp/UniTask)
- 请去下载对应的源码,并删除此目录最后的波浪线
- 在项目的 `asmdef` 文件中添加对 `UniTask.YooAsset` 的引用
- 在 UniTask `_InternalVisibleTo.cs` 文件中增加 `[assembly: InternalsVisibleTo("UniTask.YooAsset")]` 后即可使用
## 代码示例

View File

@@ -2,6 +2,23 @@
All notable changes to this package will be documented in this file.
## [1.2.0] - 2022-07-18
### Fixed
- 修复了ShaderVariantCollection刷新不及时问题。
### Changed
- 资源收集忽略了Gizmos资源文件。
- 解密服务接口增加解密文件信息参数。
- 资源收集窗体增加配置保存按钮。
- 资源构建窗体增加配置保存按钮。
### Added
- 资源构建模块增加了可编程构建管线(SBP)的支持,开发者可以在内置构建管线和可编程构建管线之间自由选择,零修改成本。
## [1.1.1] - 2022-07-07
### Fixed

View File

@@ -18,29 +18,65 @@ namespace YooAsset.Editor
// 清空旧数据
_buildContext.ClearAllContext();
// 检测构建参数是否为空
if (buildParameters == null)
{
throw new Exception($"{nameof(buildParameters)} is null !");
}
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
if (buildParameters.SBPParameters == null)
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
}
// 构建参数
var buildParametersContext = new BuildParametersContext(buildParameters);
_buildContext.SetContextObject(buildParametersContext);
// 执行构建流程
List<IBuildTask> pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding(), //开始执行构建
new TaskVerifyBuildResult(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
// 是否显示LOG
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
BuildRunner.EnableLog = false;
else
BuildRunner.EnableLog = true;
// 创建构建节点
List<IBuildTask> pipeline;
if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{
pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding(), //开始执行构建
new TaskVerifyBuildResult(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
}
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding_SBP(), //开始执行构建
new TaskVerifyBuildResult_SBP(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
}
else
{
throw new NotImplementedException();
}
// 执行构建流程
bool succeed = BuildRunner.Run(pipeline, _buildContext);
if (succeed)
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");

View File

@@ -10,6 +10,11 @@ namespace YooAsset.Editor
/// </summary>
public int BuildVersion = 0;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
/// <summary>
/// 构建模式
/// </summary>

View File

@@ -19,6 +19,11 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { set; get; } = false;
/// <summary>
/// 加载配置文件
/// </summary>
@@ -34,6 +39,7 @@ namespace YooAsset.Editor
{
if (Setting != null)
{
IsDirty = false;
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");

View File

@@ -22,8 +22,10 @@ namespace YooAsset.Editor
private List<Type> _encryptionServicesClassTypes;
private List<string> _encryptionServicesClassNames;
private Button _saveButton;
private TextField _buildOutputField;
private IntegerField _buildVersionField;
private EnumField _buildPipelineField;
private EnumField _buildModeField;
private TextField _buildinTagsField;
private PopupField<string> _encryptionField;
@@ -43,7 +45,14 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root);
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 构建平台
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
// 加密服务类
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
@@ -59,9 +68,22 @@ namespace YooAsset.Editor
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
_buildVersionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
});
// 构建管线
_buildPipelineField = root.Q<EnumField>("BuildPipeline");
_buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.style.width = 300;
_buildPipelineField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value;
RefreshWindow();
});
// 构建模式
_buildModeField = root.Q<EnumField>("BuildMode");
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
@@ -69,6 +91,7 @@ namespace YooAsset.Editor
_buildModeField.style.width = 300;
_buildModeField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
RefreshWindow();
});
@@ -78,6 +101,7 @@ namespace YooAsset.Editor
_buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
_buildinTagsField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
});
@@ -91,6 +115,7 @@ namespace YooAsset.Editor
_encryptionField.style.width = 300;
_encryptionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
});
encryptionContainer.Add(_encryptionField);
@@ -110,6 +135,7 @@ namespace YooAsset.Editor
_compressionField.style.width = 300;
_compressionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
});
@@ -118,6 +144,7 @@ namespace YooAsset.Editor
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
});
@@ -134,7 +161,24 @@ namespace YooAsset.Editor
}
public void OnDestroy()
{
AssetBundleBuilderSettingData.SaveFile();
if(AssetBundleBuilderSettingData.IsDirty)
AssetBundleBuilderSettingData.SaveFile();
}
public void Update()
{
if(_saveButton != null)
{
if(AssetBundleBuilderSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if(_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
}
private void RefreshWindow()
@@ -146,6 +190,10 @@ namespace YooAsset.Editor
_compressionField.SetEnabled(enableElement);
_appendExtensionToggle.SetEnabled(enableElement);
}
private void SaveBtn_clicked()
{
AssetBundleBuilderSettingData.SaveFile();
}
private void BuildButton_clicked()
{
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
@@ -165,23 +213,28 @@ namespace YooAsset.Editor
/// </summary>
private void ExecuteBuild()
{
var buildMode = (EBuildMode)_buildModeField.value;
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildMode = buildMode;
buildParameters.BuildVersion = _buildVersionField.value;
buildParameters.BuildinTags = _buildinTagsField.value;
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
buildParameters.CopyBuildinTagFiles = buildMode == EBuildMode.ForceRebuild;
buildParameters.AppendFileExtension = AssetBundleBuilderSettingData.Setting.AppendExtension;
buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
AssetBundleBuilder builder = new AssetBundleBuilder();
if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
buildParameters.SBPParameters = new BuildParameters.SBPBuildParameters();
buildParameters.SBPParameters.WriteLinkXML = true;
}
var builder = new AssetBundleBuilder();
bool succeed = builder.Run(buildParameters);
if (succeed)
{

View File

@@ -1,8 +1,11 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex;" />
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<ui:VisualElement name="BuildContainer">
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
<uie:EnumField label="Build Pipeline" name="BuildPipeline" />
<uie:EnumField label="Build Mode" name="BuildMode" />
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
<uie:EnumField label="Compression" value="Center" name="Compression" />

View File

@@ -112,7 +112,7 @@ namespace YooAsset.Editor
}
}
}
/// <summary>
/// 添加资源包的分类标签
/// 说明:传染算法统计到的分类标签

View File

@@ -9,6 +9,23 @@ namespace YooAsset.Editor
/// </summary>
public class BuildParameters
{
/// <summary>
/// SBP构建参数
/// </summary>
public class SBPBuildParameters
{
/// <summary>
/// 生成代码防裁剪配置
/// </summary>
public bool WriteLinkXML = true;
}
/// <summary>
/// 可编程构建管线的参数
/// </summary>
public SBPBuildParameters SBPParameters;
/// <summary>
/// 输出的根目录
/// </summary>
@@ -19,6 +36,11 @@ namespace YooAsset.Editor
/// </summary>
public BuildTarget BuildTarget;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline;
/// <summary>
/// 构建模式
/// </summary>
@@ -86,4 +108,6 @@ namespace YooAsset.Editor
return StringUtility.StringToStringList(BuildinTags, ';');
}
}
}

View File

@@ -40,19 +40,19 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取构建选项
/// 获取内置构建管线的构建选项
/// </summary>
public BuildAssetBundleOptions GetPipelineBuildOptions()
{
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
// 除非设置ForceRebuildAssetBundle标记否则会进行增量打包
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
throw new Exception("Should never get here !");
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
{
opt |= BuildAssetBundleOptions.DryRunBuild;
@@ -77,6 +77,39 @@ namespace YooAsset.Editor
return opt;
}
/// <summary>
/// 获取可编程构建管线的构建参数
/// </summary>
public UnityEditor.Build.Pipeline.BundleBuildParameters GetSBPBuildParameters()
{
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
throw new Exception("Should never get here !");
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
throw new Exception($"SBP not support {nameof(EBuildMode.DryRunBuild)} build mode !");
var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget);
var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory);
if (Parameters.CompressOption == ECompressOption.Uncompressed)
buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed;
else if (Parameters.CompressOption == ECompressOption.LZMA)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA;
else if (Parameters.CompressOption == ECompressOption.LZ4)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4;
else
throw new System.NotImplementedException(Parameters.CompressOption.ToString());
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
buildParams.UseCache = false;
if (Parameters.DisableWriteTypeTree)
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
buildParams.WriteLinkXML = Parameters.SBPParameters.WriteLinkXML;
return buildParams;
}
/// <summary>
/// 获取构建的耗时(单位:秒)
/// </summary>

View File

@@ -8,6 +8,11 @@ namespace YooAsset.Editor
[Serializable]
public class ReportSummary
{
/// <summary>
/// YooAsset版本
/// </summary>
public string YooVersion;
/// <summary>
/// 引擎版本
/// </summary>
@@ -16,7 +21,7 @@ namespace YooAsset.Editor
/// <summary>
/// 构建时间
/// </summary>
public string BuildTime;
public string BuildDate;
/// <summary>
/// 构建耗时(单位:秒)
@@ -28,6 +33,11 @@ namespace YooAsset.Editor
/// </summary>
public BuildTarget BuildTarget;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline;
/// <summary>
/// 构建模式
/// </summary>

View File

@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;

View File

@@ -0,0 +1,82 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute("资源构建内容打包")]
public class TaskBuilding_SBP : IBuildTask
{
public class SBPBuildResultContext : IContextObject
{
public IBundleBuildResults Results;
}
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
// 模拟构建模式下跳过引擎构建
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return;
// 构建内容
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
// 开始构建
IBundleBuildResults buildResults;
var buildParameters = buildParametersContext.GetSBPBuildParameters();
var taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0)
{
throw new Exception($"构建过程中发生错误 : {exitCode}");
}
BuildRunner.Log("Unity引擎打包成功");
SBPBuildResultContext buildResultContext = new SBPBuildResultContext();
buildResultContext.Results = buildResults;
context.SetContextObject(buildResultContext);
// 添加Unity内置资源包信息
if (buildResults.BundleInfos.Keys.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
{
BuildBundleInfo builtInBundleInfo = new BuildBundleInfo(YooAssetSettings.UnityBuiltInShadersBundleName);
buildMapContext.BundleInfos.Add(builtInBundleInfo);
}
// 拷贝原生文件
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{
CopyRawBundle(buildMapContext, buildParametersContext);
}
}
/// <summary>
/// 拷贝原生文件
/// </summary>
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
{
foreach (var bundleInfo in buildMapContext.BundleInfos)
{
if (bundleInfo.IsRawFile)
{
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach (var buildAsset in bundleInfo.BuildinAssets)
{
if (buildAsset.IsRawAsset)
EditorTools.CopyFile(buildAsset.AssetPath, dest, true);
}
}
}
}
}
}

View File

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

View File

@@ -1,8 +1,11 @@
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute("创建补丁清单文件")]
@@ -10,18 +13,17 @@ namespace YooAsset.Editor
{
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
CreatePatchManifestFile(buildParameters, buildMapContext, encryptionContext);
CreatePatchManifestFile(context);
}
/// <summary>
/// 创建补丁清单文件到输出目录
/// </summary>
private void CreatePatchManifestFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext,
TaskEncryption.EncryptionContext encryptionContext)
private void CreatePatchManifestFile(BuildContext context)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
int resourceVersion = buildParameters.Parameters.BuildVersion;
// 创建新补丁清单
@@ -32,6 +34,13 @@ namespace YooAsset.Editor
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
// 更新Unity内置资源包的引用关系
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
}
// 创建补丁清单文件
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
@@ -172,5 +181,45 @@ namespace YooAsset.Editor
}
throw new Exception($"Not found bundle name : {bundleName}");
}
/// <summary>
/// 更新Unity内置资源包的引用关系
/// </summary>
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults)
{
// 获取所有依赖内置资源包的资源包列表
List<string> builtInBundleReferenceList = new List<string>();
foreach (var valuePair in buildResults.BundleInfos)
{
if (valuePair.Value.Dependencies.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
builtInBundleReferenceList.Add(valuePair.Key);
}
// 检测依赖交集并更新依赖ID
int builtInBundleId = patchManifest.BundleList.Count - 1;
foreach (var patchAsset in patchManifest.AssetList)
{
List<string> dependBundles = GetPatchAssetAllDependBundles(patchManifest, patchAsset);
List<string> conflictAssetPathList = dependBundles.Intersect(builtInBundleReferenceList).ToList();
if (conflictAssetPathList.Count > 0)
{
List<int> newDependIDs = new List<int>(patchAsset.DependIDs);
newDependIDs.Add(builtInBundleId);
patchAsset.DependIDs = newDependIDs.ToArray();
}
}
}
private List<string> GetPatchAssetAllDependBundles(PatchManifest patchManifest, PatchAsset patchAsset)
{
List<string> result = new List<string>();
string mainBundle = patchManifest.BundleList[patchAsset.BundleID].BundleName;
result.Add(mainBundle);
foreach (var dependID in patchAsset.DependIDs)
{
string dependBundle = patchManifest.BundleList[dependID].BundleName;
result.Add(dependBundle);
}
return result;
}
}
}

View File

@@ -54,18 +54,38 @@ namespace YooAsset.Editor
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝UnityManifest序列化文件
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝构建日志
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json";
string destPath = $"{packageDirectory}/buildlogtep.json";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝UnityManifest文本文件
// 拷贝代码防裁剪配置
if (buildParameters.Parameters.SBPParameters.WriteLinkXML)
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml";
string destPath = $"{packageDirectory}/link.xml";
EditorTools.CopyFile(sourcePath, destPath, true);
}
}
else
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
EditorTools.CopyFile(sourcePath, destPath, true);
// 拷贝UnityManifest序列化文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝UnityManifest文本文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
EditorTools.CopyFile(sourcePath, destPath, true);
}
}
// 拷贝所有补丁文件

View File

@@ -29,14 +29,20 @@ namespace YooAsset.Editor
private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext)
{
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
BuildReport buildReport = new BuildReport();
BuildReport buildReport = new BuildReport();
// 概述信息
{
#if UNITY_2019_4_OR_NEWER
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly);
if (packageInfo != null)
buildReport.Summary.YooVersion = packageInfo.version;
#endif
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString();
buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;

View File

@@ -26,6 +26,17 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
throw new Exception("输出目录不能为空");
// 检测当前是否正在构建资源包
if (BuildPipeline.isBuildingPlayer)
throw new Exception("当前正在构建资源包,请结束后再试");
// 检测是否有未保存场景
if (EditorTools.HasDirtyScenes())
throw new Exception("检测到未保存的场景文件");
// 保存改动的资源
AssetDatabase.SaveAssets();
// 增量更新时候的必要检测
var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode == EBuildMode.IncrementalBuild)

View File

@@ -37,53 +37,21 @@ namespace YooAsset.Editor
string[] buildedBundles = unityManifest.GetAllAssetBundles();
// 1. 过滤掉原生Bundle
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length);
foreach(var bundleInfo in buildMapContext.BundleInfos)
{
if (bundleInfo.IsRawFile == false)
expectBundles.Add(bundleInfo);
}
string[] expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
// 2. 验证数量
if (buildedBundles.Length != expectBundles.Count)
// 2. 验证Bundle
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
if (intersectBundleList.Count > 0)
{
Debug.LogWarning($"构建过程中可能存在无效的资源导致和预期构建的Bundle数量不一致");
}
// 3. 正向验证Bundle
foreach (var bundleName in buildedBundles)
{
if (buildMapContext.IsContainsBundle(bundleName) == false)
foreach (var intersectBundle in intersectBundleList)
{
throw new Exception($"Should never get here !");
Debug.LogWarning($"差异资源包: {intersectBundle}");
}
throw new System.Exception("存在差异资源包!请查看警告信息!");
}
// 4. 反向验证Bundle
// 3. 验证Asset
bool isPass = true;
foreach (var expectBundle in expectBundles)
{
bool isMatch = false;
foreach (var buildedBundle in buildedBundles)
{
if (buildedBundle == expectBundle.BundleName)
{
isMatch = true;
break;
}
}
if (isMatch == false)
{
isPass = false;
Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}");
}
}
if(isPass == false)
{
throw new Exception("构建结果验证没有通过,请参考警告日志!");
}
// 5. 验证Asset
var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{
@@ -137,7 +105,6 @@ namespace YooAsset.Editor
}
}
// 卸载所有加载的Bundle
BuildRunner.Log("构建结果验证成功!");
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute("验证构建结果")]
public class TaskVerifyBuildResult_SBP : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
// 模拟构建模式下跳过验证
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
return;
// 验证构建结果
if (buildParametersContext.Parameters.VerifyBuildingResult)
{
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
VerifyingBuildingResult(context, buildResultContext.Results);
}
}
/// <summary>
/// 验证构建结果
/// </summary>
private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
// 1. 移除特定Bundle
List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
buildedBundles.Remove(YooAssetSettings.UnityBuiltInShadersBundleName);
// 2. 过滤掉原生Bundle
List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
// 3. 验证Bundle
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
if (intersectBundleList.Count > 0)
{
foreach (var intersectBundle in intersectBundleList)
{
Debug.LogWarning($"差异资源包: {intersectBundle}");
}
throw new System.Exception("存在差异资源包!请查看警告信息!");
}
BuildRunner.Log("构建结果验证成功!");
}
}
}

View File

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

View File

@@ -0,0 +1,19 @@

namespace YooAsset.Editor
{
/// <summary>
/// 构建管线类型
/// </summary>
public enum EBuildPipeline
{
/// <summary>
/// 传统内置构建管线
/// </summary>
BuiltinBuildPipeline,
/// <summary>
/// 可编程构建管线
/// </summary>
ScriptableBuildPipeline,
}
}

View File

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

View File

@@ -180,7 +180,15 @@ namespace YooAsset.Editor
private bool IsValidateAsset(string assetPath)
{
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
return false;
}
if (assetPath.Contains("/Gizmos/"))
{
UnityEngine.Debug.LogWarning($"Cannot pack gizmos asset : {assetPath}");
return false;
}
if (AssetDatabase.IsValidFolder(assetPath))
return false;

View File

@@ -18,6 +18,7 @@ namespace YooAsset.Editor
window.minSize = new Vector2(800, 600);
}
private Button _saveButton;
private List<string> _collectorTypeList;
private List<string> _activeRuleList;
private List<string> _addressRuleList;
@@ -69,6 +70,10 @@ namespace YooAsset.Editor
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_clicked;
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 公共设置相关
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
@@ -193,6 +198,22 @@ namespace YooAsset.Editor
if (AssetBundleCollectorSettingData.IsDirty)
AssetBundleCollectorSettingData.SaveFile();
}
public void Update()
{
if (_saveButton != null)
{
if (AssetBundleCollectorSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
}
private void RefreshWindow()
{
@@ -221,6 +242,10 @@ namespace YooAsset.Editor
RefreshWindow();
}
}
private void SaveBtn_clicked()
{
AssetBundleCollectorSettingData.SaveFile();
}
// 分组列表相关
private void FillGroupViewData()

View File

@@ -1,5 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar>

View File

@@ -58,10 +58,13 @@ namespace YooAsset.Editor
_buildReport = buildReport;
_items.Clear();
_items.Add(new ItemWrapper("YooAsset版本", buildReport.Summary.YooVersion));
_items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion));
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildTime));
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildDate));
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
_items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}"));
_items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}"));
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}"));
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));

View File

@@ -7,6 +7,7 @@ using System.IO;
using System.Text;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
namespace YooAsset.Editor
{
@@ -265,6 +266,20 @@ namespace YooAsset.Editor
}
#endregion
#region SceneUtility
public static bool HasDirtyScenes()
{
var sceneCount = EditorSceneManager.sceneCount;
for (var i = 0; i < sceneCount; ++i)
{
var scene = EditorSceneManager.GetSceneAt(i);
if (scene.isDirty)
return true;
}
return false;
}
#endregion
#region
/// <summary>
/// 创建文件所在的目录

View File

@@ -34,6 +34,8 @@ namespace YooAsset.Editor
EditorGUILayout.Space();
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
{
// 先删除再保存否则ShaderVariantCollection内容将无法及时刷新
AssetDatabase.DeleteAsset(ShaderVariantCollectorSettingData.Setting.SavePath);
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath);
}

View File

@@ -2,7 +2,9 @@
"name": "YooAsset.Editor",
"rootNamespace": "",
"references": [
"YooAsset"
"YooAsset",
"Unity.ScriptableBuildPipeline",
"Unity.ScriptableBuildPipeline.Editor"
],
"includePlatforms": [
"Editor"

View File

@@ -117,7 +117,11 @@ namespace YooAsset
if (AssetSystem.DecryptionServices == null)
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
ulong offset = AssetSystem.DecryptionServices.GetFileOffset();
DecryptionFileInfo fileInfo = new DecryptionFileInfo();
fileInfo.BundleName = MainBundleInfo.BundleName;
fileInfo.BundleHash = MainBundleInfo.Hash;
fileInfo.BundleCRC = MainBundleInfo.CRC;
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(fileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
else

View File

@@ -382,7 +382,7 @@ namespace YooAsset
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (appPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
if (appPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;

View File

@@ -203,7 +203,7 @@ namespace YooAsset
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (_impl.AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
if (_impl.AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;

View File

@@ -42,13 +42,13 @@ namespace YooAsset
/// 资源包集合提供BundleName获取PatchBundle
/// </summary>
[NonSerialized]
public readonly Dictionary<string, PatchBundle> Bundles = new Dictionary<string, PatchBundle>();
public readonly Dictionary<string, PatchBundle> BundleDic = new Dictionary<string, PatchBundle>();
/// <summary>
/// 资源映射集合提供AssetPath获取PatchAsset
/// </summary>
[NonSerialized]
public readonly Dictionary<string, PatchAsset> Assets = new Dictionary<string, PatchAsset>();
public readonly Dictionary<string, PatchAsset> AssetDic = new Dictionary<string, PatchAsset>();
/// <summary>
/// 资源路径映射集合
@@ -117,7 +117,7 @@ namespace YooAsset
/// </summary>
public string MappingToAssetPath(string location)
{
if(string.IsNullOrEmpty(location))
if (string.IsNullOrEmpty(location))
{
YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
return string.Empty;
@@ -138,18 +138,18 @@ namespace YooAsset
}
/// <summary>
/// 获取资源包名称
/// 获取资源包
/// 注意:传入的资源路径一定合法有效!
/// </summary>
public string GetBundleName(string assetPath)
public PatchBundle GetMainPatchBundle(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
{
int bundleID = patchAsset.BundleID;
if (bundleID >= 0 && bundleID < BundleList.Count)
{
var patchBundle = BundleList[bundleID];
return patchBundle.BundleName;
return patchBundle;
}
else
{
@@ -166,17 +166,17 @@ namespace YooAsset
/// 获取资源依赖列表
/// 注意:传入的资源路径一定合法有效!
/// </summary>
public string[] GetAllDependencies(string assetPath)
public PatchBundle[] GetAllDependencies(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
{
List<string> result = new List<string>(patchAsset.DependIDs.Length);
List<PatchBundle> result = new List<PatchBundle>(patchAsset.DependIDs.Length);
foreach (var dependID in patchAsset.DependIDs)
{
if (dependID >= 0 && dependID < BundleList.Count)
{
var dependPatchBundle = BundleList[dependID];
result.Add(dependPatchBundle.BundleName);
result.Add(dependPatchBundle);
}
else
{
@@ -191,6 +191,22 @@ namespace YooAsset
}
}
/// <summary>
/// 尝试获取补丁资源
/// </summary>
public bool TryGetPatchAsset(string assetPath, out PatchAsset result)
{
return AssetDic.TryGetValue(assetPath, out result);
}
/// <summary>
/// 尝试获取补丁资源包
/// </summary>
public bool TryGetPatchBundle(string bundleName, out PatchBundle result)
{
return BundleDic.TryGetValue(bundleName, out result);
}
/// <summary>
/// 序列化
@@ -212,7 +228,7 @@ namespace YooAsset
foreach (var patchBundle in patchManifest.BundleList)
{
patchBundle.ParseFlagsValue();
patchManifest.Bundles.Add(patchBundle.BundleName, patchBundle);
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
}
// AssetList
@@ -220,10 +236,10 @@ namespace YooAsset
{
// 注意:我们不允许原始路径存在重名
string assetPath = patchAsset.AssetPath;
if (patchManifest.Assets.ContainsKey(assetPath))
if (patchManifest.AssetDic.ContainsKey(assetPath))
throw new Exception($"AssetPath have existed : {assetPath}");
else
patchManifest.Assets.Add(assetPath, patchAsset);
patchManifest.AssetDic.Add(assetPath, patchAsset);
}
return patchManifest;

View File

@@ -40,19 +40,13 @@ namespace YooAsset
#region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{
if(assetInfo.IsInvalid)
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
string bundleName = _simulatePatchManifest.GetBundleName(assetInfo.AssetPath);
if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
return bundleInfo;
}
else
{
throw new Exception("Should never get here !");
}
// 注意:如果补丁清单里未找到资源包会抛出异常!
var patchBundle = _simulatePatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
return bundleInfo;
}
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{
@@ -64,7 +58,7 @@ namespace YooAsset
}
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (_simulatePatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
if (_simulatePatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;

View File

@@ -56,7 +56,7 @@ namespace YooAsset
OperationSystem.StartOperaiton(operation);
return operation;
}
/// <summary>
/// 异步更新补丁清单(弱联网)
/// </summary>
@@ -108,7 +108,7 @@ namespace YooAsset
break;
}
}
if(used == false)
if (used == false)
{
YooLogger.Log($"Delete unused cache file : {fileInfo.Name}");
File.Delete(fileInfo.FullName);
@@ -136,7 +136,7 @@ namespace YooAsset
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;
@@ -168,7 +168,7 @@ namespace YooAsset
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;
@@ -215,21 +215,17 @@ namespace YooAsset
continue;
}
string mainBundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle))
{
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
}
// 注意:如果补丁清单里未找到资源包会抛出异常!
PatchBundle mainBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundleName in dependBundleNames)
// 注意:如果补丁清单里未找到资源包会抛出异常!
PatchBundle[] dependBundles = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundle in dependBundles)
{
if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle))
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
}
@@ -242,7 +238,7 @@ namespace YooAsset
// 忽略APP资源
// 注意如果是APP资源并且哈希值相同则不需要下载
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
continue;
@@ -376,53 +372,51 @@ namespace YooAsset
}
#region IBundleServices接口
private BundleInfo CreateBundleInfo(string bundleName)
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
{
if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
if (patchBundle == null)
throw new Exception("Should never get here !");
// 查询沙盒资源
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
{
// 查询沙盒资源
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
return bundleInfo;
}
// 查询APP资源
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
{
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
// 查询APP资源
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle))
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
{
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
}
// 从服务端下载
return ConvertToDownloadInfo(patchBundle);
}
else
{
throw new Exception("Should never get here !");
}
// 从服务端下载
return ConvertToDownloadInfo(patchBundle);
}
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
string bundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
return CreateBundleInfo(bundleName);
// 注意:如果补丁清单里未找到资源包会抛出异常!
var patchBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
return CreateBundleInfo(patchBundle);
}
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果补丁清单里未找到资源包会抛出异常!
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var bundleName in depends)
foreach (var patchBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
result.Add(bundleInfo);
}
return result.ToArray();
@@ -433,7 +427,7 @@ namespace YooAsset
}
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (LocalPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
if (LocalPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;

View File

@@ -38,36 +38,34 @@ namespace YooAsset
}
#region IBundleServices接口
private BundleInfo CreateBundleInfo(string bundleName)
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
{
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
else
{
if (patchBundle == null)
throw new Exception("Should never get here !");
}
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath);
return CreateBundleInfo(bundleName);
// 注意:如果补丁清单里未找到资源包会抛出异常!
var patchBundle = _appPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
return CreateBundleInfo(patchBundle);
}
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
// 注意:如果补丁清单里未找到资源包会抛出异常!
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var bundleName in depends)
foreach (var patchBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
result.Add(bundleInfo);
}
return result.ToArray();
@@ -78,7 +76,7 @@ namespace YooAsset
}
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
if (_appPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;

View File

@@ -1,11 +1,18 @@

namespace YooAsset
{
public struct DecryptionFileInfo
{
public string BundleName;
public string BundleHash;
public string BundleCRC;
}
public interface IDecryptionServices
{
/// <summary>
/// 获取加密文件的数据偏移量
/// </summary>
ulong GetFileOffset();
ulong GetFileOffset(DecryptionFileInfo fileInfo);
}
}

View File

@@ -25,6 +25,7 @@ namespace YooAsset
/// </summary>
public string UnityManifestFileName = "UnityManifest";
/// <summary>
/// 构建输出的报告文件
/// </summary>
@@ -34,5 +35,10 @@ namespace YooAsset
/// 静态版本文件
/// </summary>
public const string VersionFileName = "StaticVersion.bytes";
/// <summary>
/// Unity内置着色器资源包名称
/// </summary>
public const string UnityBuiltInShadersBundleName = "UnityBuiltInShaders.bundle";
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "1.1.1",
"version": "1.2.0",
"unity": "2019.4",
"description": "unity3d resources management system",
"author": {
@@ -13,5 +13,10 @@
"url": "https://github.com/tuyoogame/YooAsset.git"
},
"relatedPackages": {},
"dependencies": {}
"dependencies": {
"com.unity.scriptablebuildpipeline": "1.20.2",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0"
}
}

View File

@@ -12,6 +12,14 @@
构建版本号,也是资源版本号,版本号必须大于零。
- **Build Pipeline**
构建管线
(1) BuiltinBuildPipeline: 传统的内置构建管线。
(2) ScriptableBuildPipeline: 可编程构建管线。
- **Build Mode**
构建模式

View File

@@ -69,7 +69,13 @@
- MainAssetCollector 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
- StaticAssetCollector 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
- DependAssetCollector 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
- DependAssetCollector 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)(当依赖资源没有被任何主资源引用的时候,则会在打包的时候自动剔除)
StaticAssetCollector收集器和DependAssetCollector收集器适合对资源进行定制化打包策略。
示例1一个游戏的粒子特效的纹理会非常多通常特效制作师会把这些纹理放到一个文件夹内管理。如果我们把这些纹理打进一个AssetBundle文件内当下次更新的时候如果新增或改动了一个纹理那么就要上传整个纹理的AssetBundle文件。我们可以把特效纹理通过DependAssetCollector收集器进行收集并自定义打包规则通过文件名称的首字母进行小粒度打包这样一个AssetBundle文件会被拆分为26个AssetBundle文件。
示例2当我们需要严格控制某个文件夹内的依赖资源打进同一个AssetBundle文件内那么StaticAssetCollector收集器是最佳选择该收集器收集的资源无论是否被其它资源引用或被多个资源引用这些资源都会按照设定的打包规则打包且这些资源不会被处理为share资源包。
- **AddressRule**

View File

@@ -1,13 +1,24 @@
# 常见问题解答
### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
#### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
如果在打AssetBundle的时候选定的构建目标是安卓。那么在windows操作系统下编辑器的默认渲染模式为DX11我们需要修改编辑器的渲染模式可以通过UnityHub来修改启动项目的编辑器渲染模式[参考官方文档](https://docs.unity3d.com/cn/2019.4/Manual/CommandLineArguments.html)。
### 问题YooAsset的DLL引用丢失导致编译报错了
windows平台添加命令: **-force-gles**
#### 问题YooAsset的DLL引用丢失导致编译报错了
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
2. 关闭游戏工程后删除Assets同级目录下所有的csproj文件和sln文件。
3. 删除Library/ScriptAssemblies文件夹。
4. 重新打开游戏工程,然后点击某个脚本重新编译。
#### 问题无效的资源路径请检查路径是否带有特殊符号或中文Assets/xxx/xxx/xxx
如果检查报错的文件路径内无特殊符合和中文字符也可能是文件路径过长且文件名称带空格在打包生成的manifest文件里文件路径被截断导致验证失败。
例如Assets/My Game Res/JMO Assets/Cartoon FX Remaster/CFXR Assets/Shaders/CFXR Particle Glow.shader
解决方案1缩短文件路径长度。
解决方案2移除文件名称里的空格。

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 39 KiB