Update document

pull/4/head
hevinci 2022-03-03 19:13:07 +08:00
parent 8b08907ea8
commit 50e139ef44
6 changed files with 163 additions and 153 deletions

View File

@ -39,25 +39,25 @@
````C# ````C#
public class AssetEncrypter : IAssetEncrypter public class AssetEncrypter : IAssetEncrypter
{ {
/// <summary> /// <summary>
/// 检测资源包是否需要加密 /// 检测资源包是否需要加密
/// </summary> /// </summary>
bool IAssetEncrypter.Check(string filePath) bool IAssetEncrypter.Check(string filePath)
{ {
// 对配置表相关的资源包进行加密 // 对配置表相关的资源包进行加密
return filePath.Contains("Assets/Config/"); return filePath.Contains("Assets/Config/");
} }
/// <summary> /// <summary>
/// 对数据进行加密,并返回加密后的数据 /// 对数据进行加密,并返回加密后的数据
/// </summary> /// </summary>
byte[] IAssetEncrypter.Encrypt(byte[] fileData) byte[] IAssetEncrypter.Encrypt(byte[] fileData)
{ {
int offset = 32; int offset = 32;
var temper = new byte[fileData.Length + offset]; var temper = new byte[fileData.Length + offset];
Buffer.BlockCopy(fileData, 0, temper, offset, fileData.Length); Buffer.BlockCopy(fileData, 0, temper, offset, fileData.Length);
return temper; return temper;
} }
} }
```` ````
@ -82,52 +82,52 @@ public class AssetEncrypter : IAssetEncrypter
````c# ````c#
private static void BuildInternal(BuildTarget buildTarget) private static void BuildInternal(BuildTarget buildTarget)
{ {
Debug.Log($"开始构建 : {buildTarget}"); Debug.Log($"开始构建 : {buildTarget}");
// 打印命令行参数 // 打印命令行参数
int buildVersion = GetBuildVersion(); int buildVersion = GetBuildVersion();
bool isForceBuild = IsForceBuild(); bool isForceBuild = IsForceBuild();
Debug.Log($"资源版本 : {buildVersion}"); Debug.Log($"资源版本 : {buildVersion}");
Debug.Log($"强制重建 : {isForceBuild}"); Debug.Log($"强制重建 : {isForceBuild}");
// 构建参数 // 构建参数
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
AssetBundleBuilder.BuildParameters buildParameters = new AssetBundleBuilder.BuildParameters(); AssetBundleBuilder.BuildParameters buildParameters = new AssetBundleBuilder.BuildParameters();
buildParameters.IsVerifyBuildingResult = true; buildParameters.IsVerifyBuildingResult = true;
buildParameters.OutputRoot = defaultOutputRoot; buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = buildTarget; buildParameters.BuildTarget = buildTarget;
buildParameters.BuildVersion = buildVersion; buildParameters.BuildVersion = buildVersion;
buildParameters.CompressOption = ECompressOption.LZ4; buildParameters.CompressOption = ECompressOption.LZ4;
buildParameters.AppendFileExtension = false; buildParameters.AppendFileExtension = false;
buildParameters.IsForceRebuild = isForceBuild; buildParameters.IsForceRebuild = isForceBuild;
buildParameters.BuildinTags = "buildin"; buildParameters.BuildinTags = "buildin";
// 执行构建 // 执行构建
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();
builder.Run(buildParameters); builder.Run(buildParameters);
// 构建完成 // 构建完成
Debug.Log("构建完成"); Debug.Log("构建完成");
} }
// 从构建命令里获取参数 // 从构建命令里获取参数
private static int GetBuildVersion() private static int GetBuildVersion()
{ {
foreach (string arg in System.Environment.GetCommandLineArgs()) foreach (string arg in System.Environment.GetCommandLineArgs())
{ {
if (arg.StartsWith("buildVersion")) if (arg.StartsWith("buildVersion"))
return int.Parse(arg.Split("="[0])[1]); return int.Parse(arg.Split("="[0])[1]);
} }
return -1; return -1;
} }
private static bool IsForceBuild() private static bool IsForceBuild()
{ {
foreach (string arg in System.Environment.GetCommandLineArgs()) foreach (string arg in System.Environment.GetCommandLineArgs())
{ {
if (arg.StartsWith("forceBuild")) if (arg.StartsWith("forceBuild"))
return arg.Split("="[0])[1] == "true" ? true : false; return arg.Split("="[0])[1] == "true" ? true : false;
} }
return false; return false;
} }
```` ````

View File

@ -25,10 +25,10 @@
````c# ````c#
public class PackDirectory : IPackRule public class PackDirectory : IPackRule
{ {
string IPackRule.GetAssetBundleLabel(string assetPath) string IPackRule.GetAssetBundleLabel(string assetPath)
{ {
return Path.GetDirectoryName(assetPath); //"Assets/Config/test.txt" --> "Assets/Config" return Path.GetDirectoryName(assetPath); //"Assets/Config/test.txt" --> "Assets/Config"
} }
} }
```` ````
@ -46,10 +46,10 @@ public class PackDirectory : IPackRule
````c# ````c#
public class CollectScene : IFilterRule public class CollectScene : IFilterRule
{ {
public bool IsCollectAsset(string assetPath) public bool IsCollectAsset(string assetPath)
{ {
return Path.GetExtension(assetPath) == ".unity"; return Path.GetExtension(assetPath) == ".unity";
} }
} }
```` ````
@ -67,8 +67,8 @@ public class CollectScene : IFilterRule
````xml ````xml
<root> <root>
<Collector Directory="Assets/GameRes/UIAtlas/" PackRule="PackExplicit" FilterRule="CollectAll" DontWriteAssetPath="0" AssetTags=""/> <Collector Directory="Assets/GameRes/UIAtlas/" PackRule="PackExplicit" FilterRule="CollectAll" DontWriteAssetPath="0" AssetTags=""/>
<Collector Directory="Assets/GameRes/UIPanel/" PackRule="PackExplicit" FilterRule="CollectAll" DontWriteAssetPath="0" AssetTags=""/> <Collector Directory="Assets/GameRes/UIPanel/" PackRule="PackExplicit" FilterRule="CollectAll" DontWriteAssetPath="0" AssetTags=""/>
</root> </root>
```` ````

View File

@ -17,8 +17,8 @@ YooAssets.InitializeAsync(CreateParameters parameters);
private IEnumerator InitializeYooAsset() private IEnumerator InitializeYooAsset()
{ {
var createParameters = new YooAssets.EditorPlayModeParameters(); var createParameters = new YooAssets.EditorPlayModeParameters();
createParameters.LocationRoot = "Assets/GameRes"; createParameters.LocationRoot = "Assets/GameRes";
yield return YooAssets.InitializeAsync(createParameters); yield return YooAssets.InitializeAsync(createParameters);
} }
```` ````
@ -32,8 +32,8 @@ private IEnumerator InitializeYooAsset()
private IEnumerator InitializeYooAsset() private IEnumerator InitializeYooAsset()
{ {
var createParameters = new YooAssets.OfflinePlayModeParameters(); var createParameters = new YooAssets.OfflinePlayModeParameters();
createParameters.LocationRoot = "Assets/GameRes"; createParameters.LocationRoot = "Assets/GameRes";
yield return YooAssets.InitializeAsync(createParameters); yield return YooAssets.InitializeAsync(createParameters);
} }
```` ````

View File

@ -26,38 +26,38 @@ YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
// 委托加载方式 // 委托加载方式
void Start() void Start()
{ {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
handle.Completed += Handle_Completed; handle.Completed += Handle_Completed;
} }
void Handle_Completed(AssetOperationHandle handle) void Handle_Completed(AssetOperationHandle handle)
{ {
AudioClip audioClip = handle.AssetObject as AudioClip; AudioClip audioClip = handle.AssetObject as AudioClip;
} }
```` ````
````C# ````C#
// 协程加载方式 // 协程加载方式
void Start() void Start()
{ {
this.StartCoroutine(AsyncLoad()); this.StartCoroutine(AsyncLoad());
} }
IEnumerator AsyncLoad() IEnumerator AsyncLoad()
{ {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
yield return handle; yield return handle;
AudioClip audioClip = handle.AssetObject as AudioClip; AudioClip audioClip = handle.AssetObject as AudioClip;
} }
```` ````
````C# ````C#
// Task加载方式 // Task加载方式
async void Start() async void Start()
{ {
await AsyncLoad(); await AsyncLoad();
} }
async Task AsyncLoad() async Task AsyncLoad()
{ {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
await handle.Task; await handle.Task;
AudioClip audioClip = handle.AssetObject as AudioClip; AudioClip audioClip = handle.AssetObject as AudioClip;
} }
```` ````
@ -66,11 +66,11 @@ async Task AsyncLoad()
````C# ````C#
void Start() void Start()
{ {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
... ...
handle.Release(); handle.Release();
} }
```` ````
@ -94,7 +94,7 @@ GameObject go = UnityEngine.Object.Instantiate(handle.AssetObject as GameObject)
var handle = YooAssets.LoadSubAssetsSync<Sprite>(location); var handle = YooAssets.LoadSubAssetsSync<Sprite>(location);
foreach (var asset in handle.AllAssets) foreach (var asset in handle.AllAssets)
{ {
Debug.Log($"Sprite name is {asset.name}"); Debug.Log($"Sprite name is {asset.name}");
} }
```` ````
@ -103,18 +103,18 @@ foreach (var asset in handle.AllAssets)
````c# ````c#
void Start() void Start()
{ {
// 场景加载参数 // 场景加载参数
SceneInstanceParam param = new SceneInstanceParam(); SceneInstanceParam param = new SceneInstanceParam();
param.LoadMode = UnityEngine.SceneManagement.LoadSceneMode.Single; param.LoadMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
param.ActivateOnLoad = true; param.ActivateOnLoad = true;
AssetOperationHandle handle = YooAssets.LoadSceneAsync("Scene/Login", param); AssetOperationHandle handle = YooAssets.LoadSceneAsync("Scene/Login", param);
handle.Completed += Handle_Completed; handle.Completed += Handle_Completed;
} }
void Handle_Completed(AssetOperationHandle handle) void Handle_Completed(AssetOperationHandle handle)
{ {
SceneInstance instance = handle.AssetInstance as SceneInstance; SceneInstance instance = handle.AssetInstance as SceneInstance;
Debug.Log(instance.Scene.name); Debug.Log(instance.Scene.name);
} }
```` ````

View File

@ -9,20 +9,20 @@
````c# ````c#
private IEnumerator UpdatePatchManifest() private IEnumerator UpdatePatchManifest()
{ {
int updateResourceVersion = 123; int updateResourceVersion = 123;
int timeout = 30; int timeout = 30;
UpdateManifestOperation operation = YooAssets.UpdateManifestAsync(updateResourceVersion, timeout); UpdateManifestOperation operation = YooAssets.UpdateManifestAsync(updateResourceVersion, timeout);
yield return operation; yield return operation;
if (operation.Status == EOperationStatus.Succeed) if (operation.Status == EOperationStatus.Succeed)
{ {
//更新成功 //更新成功
} }
else else
{ {
//更新失败 //更新失败
Debug.LogError(operation.Error); Debug.LogError(operation.Error);
} }
} }
```` ````
@ -40,20 +40,20 @@ private PatchDownloader _downloader;
/// </summary> /// </summary>
private void CreateDownloader() private void CreateDownloader()
{ {
string[] tags = { "buildin", "config" }; string[] tags = { "buildin", "config" };
int downloadingMaxNum = 10; int downloadingMaxNum = 10;
int failedTryAgain = 3; int failedTryAgain = 3;
_downloader = YooAssets.CreateDLCDownloader(tags, 10, 3); _downloader = YooAssets.CreateDLCDownloader(tags, 10, 3);
if (_downloader.TotalDownloadCount == 0) if (_downloader.TotalDownloadCount == 0)
{ {
//没有需要下载的资源 //没有需要下载的资源
} }
else else
{ {
//需要下载的文件总数和总大小 //需要下载的文件总数和总大小
int totalDownloadCount = _downloader.TotalDownloadCount; int totalDownloadCount = _downloader.TotalDownloadCount;
long totalDownloadBytes = _downloader.TotalDownloadBytes; long totalDownloadBytes = _downloader.TotalDownloadBytes;
} }
} }
/// <summary> /// <summary>
@ -61,8 +61,8 @@ private void CreateDownloader()
/// </summary> /// </summary>
private void UpdateDownloader() private void UpdateDownloader()
{ {
if (_downloader != null) if (_downloader != null)
_downloader.Update(); _downloader.Update();
} }
/// <summary> /// <summary>
@ -70,22 +70,22 @@ private void UpdateDownloader()
/// </summary> /// </summary>
private IEnumerator Download() private IEnumerator Download()
{ {
//注册下载回调 //注册下载回调
_downloader.OnPatchFileDownloadFailedCallback = OnPatchFileDownloadFailed; _downloader.OnPatchFileDownloadFailedCallback = OnPatchFileDownloadFailed;
_downloader.OnDownloadProgressCallback = OnDownloadProgressUpdate; _downloader.OnDownloadProgressCallback = OnDownloadProgressUpdate;
_downloader.OnDownloadOverCallback = OnDownloadOver; _downloader.OnDownloadOverCallback = OnDownloadOver;
_downloader.Download(); _downloader.Download();
yield return _downloader; yield return _downloader;
//检测下载结果 //检测下载结果
if (_downloader.DownloadStates == EDownloaderStates.Succeed) if (_downloader.DownloadStates == EDownloaderStates.Succeed)
{ {
//下载成功 //下载成功
} }
else else
{ {
//下载失败 //下载失败
} }
} }
/// <summary> /// <summary>
@ -93,7 +93,7 @@ private IEnumerator Download()
/// </summary> /// </summary>
private void OnPatchFileDownloadFailed(string fileName) private void OnPatchFileDownloadFailed(string fileName)
{ {
Debug.LogError($"File download failed : {fileName}"); Debug.LogError($"File download failed : {fileName}");
} }
/// <summary> /// <summary>

View File

@ -2,33 +2,43 @@
YooAsset是一个基于Unity3D引擎的资源管理插件。 YooAsset是一个基于Unity3D引擎的资源管理插件。
## 特点 ## 特点
**强大灵活的打包系统** - **强大灵活的打包系统**
可以自定义打包策略,可以自定义冗余规则,自动分析依赖实现资源零冗余,基于资源对象的资源包依赖管理方案,避免了资源包之间循环依赖的问题。
**安全高效的分包方案** 可以自定义打包策略,可以自定义冗余规则,自动分析依赖实现资源零冗余,基于资源对象的资源包依赖管理方案,避免了资源包之间循环依赖的问题。
基于资源对象的标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
**灵活高效的加密方案** - **安全高效的分包方案**
提供多种加密策略可以自定义加密规则基于Unity官方的高效解密方案。
**基于引用计数方案** 基于资源对象的标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
基于引用技术的资源管理方案,可以帮助我们实现安全的资源卸载策略,更好的对内存管理,避免资源对象冗余。还有强大的分析器可帮助发现潜在的资源泄漏问题。
**多种模式自由切换** - **灵活高效的加密方案**
编辑器模拟模式,单机运行模式,联机运行模式。在编辑器模拟模式下,可以不构建资源包来模拟线上环境,在不修改任何代码的情况下,可以自由切换到其它模式。
**强大安全的加载系统** 提供多种加密策略可以自定义加密规则基于Unity官方的高效解密方案。
- **异步加载和同步加载** 异步加载接口支持协程Task委托。支持异步加载和同步加载混合使用。 - **基于引用计数方案**
- **边玩边下载** 在加载资源对象的时候,如果资源对象依赖的资源包在本地不存在,会自动从服务器下载到本地,然后再加载资源对象。
- **多线程下载** 支持断点续传,自动验证下载文件,自动修复损坏文件。可以自定义下载失败重试次数,下载超时判定时间。
- **多功能下载器** 可以按照资源标签列表创建下载器,也可以按照资源对象列表创建下载器。下载器可以设置同时下载文件数的限制,设置下载失败重试次数,多个下载器同时下载不用担心文件重复下载问题,下载器还提供了下载进度以及下载失败异常等常用接口。
**原生格式文件管理** 基于引用技术的资源管理方案,可以帮助我们实现安全的资源卸载策略,更好的对内存管理,避免资源对象冗余。还有强大的分析器可帮助发现潜在的资源泄漏问题。
无缝衔接资源打包系统,可以很方便的实现原生文件的版本管理和下载。
**灵活多变的版本管理** - **多种模式自由切换**
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
编辑器模拟模式,单机运行模式,联机运行模式。在编辑器模拟模式下,可以不构建资源包来模拟线上环境,在不修改任何代码的情况下,可以自由切换到其它模式。
- **强大安全的加载系统**
- **异步加载和同步加载** 异步加载接口支持协程Task委托。支持异步加载和同步加载混合使用。
- **边玩边下载** 在加载资源对象的时候,如果资源对象依赖的资源包在本地不存在,会自动从服务器下载到本地,然后再加载资源对象。
- **多线程下载** 支持断点续传,自动验证下载文件,自动修复损坏文件。可以自定义下载失败重试次数,下载超时判定时间。
- **多功能下载器** 可以按照资源标签列表创建下载器,也可以按照资源对象列表创建下载器。下载器可以设置同时下载文件数的限制,设置下载失败重试次数,多个下载器同时下载不用担心文件重复下载问题,下载器还提供了下载进度以及下载失败异常等常用接口。
- **原生格式文件管理**
无缝衔接资源打包系统,可以很方便的实现原生文件的版本管理和下载。
- **灵活多变的版本管理**
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
## 入门教程 ## 入门教程
1. [快速开始](https://github.com/tuyoogame/YooAsset/blob/master/Docs/QuickStart.md) 1. [快速开始](https://github.com/tuyoogame/YooAsset/blob/master/Docs/QuickStart.md)