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

View File

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

View File

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

View File

@ -26,38 +26,38 @@ YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
// 委托加载方式
void Start()
{
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
handle.Completed += Handle_Completed;
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
handle.Completed += Handle_Completed;
}
void Handle_Completed(AssetOperationHandle handle)
{
AudioClip audioClip = handle.AssetObject as AudioClip;
AudioClip audioClip = handle.AssetObject as AudioClip;
}
````
````C#
// 协程加载方式
void Start()
{
this.StartCoroutine(AsyncLoad());
this.StartCoroutine(AsyncLoad());
}
IEnumerator AsyncLoad()
{
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
yield return handle;
AudioClip audioClip = handle.AssetObject as AudioClip;
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
yield return handle;
AudioClip audioClip = handle.AssetObject as AudioClip;
}
````
````C#
// Task加载方式
async void Start()
{
await AsyncLoad();
await AsyncLoad();
}
async Task AsyncLoad()
{
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
await handle.Task;
AudioClip audioClip = handle.AssetObject as AudioClip;
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
await handle.Task;
AudioClip audioClip = handle.AssetObject as AudioClip;
}
````
@ -66,11 +66,11 @@ async Task AsyncLoad()
````C#
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);
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#
void Start()
{
// 场景加载参数
SceneInstanceParam param = new SceneInstanceParam();
param.LoadMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
param.ActivateOnLoad = true;
// 场景加载参数
SceneInstanceParam param = new SceneInstanceParam();
param.LoadMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
param.ActivateOnLoad = true;
AssetOperationHandle handle = YooAssets.LoadSceneAsync("Scene/Login", param);
handle.Completed += Handle_Completed;
AssetOperationHandle handle = YooAssets.LoadSceneAsync("Scene/Login", param);
handle.Completed += Handle_Completed;
}
void Handle_Completed(AssetOperationHandle handle)
{
SceneInstance instance = handle.AssetInstance as SceneInstance;
Debug.Log(instance.Scene.name);
SceneInstance instance = handle.AssetInstance as SceneInstance;
Debug.Log(instance.Scene.name);
}
````

View File

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

View File

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