Update document

pull/51/head
hevinci 2022-10-28 10:46:35 +08:00
parent ba4efebbce
commit 171f40551e
10 changed files with 47 additions and 49 deletions

View File

@ -112,7 +112,11 @@ public class GameEncryption : IEncryptionServices
### 补丁清单
补丁清单是一个Json格式的文本文件里面包含了所有资源包的信息例如名称大小CRC等。
补丁清单是一个Json格式的文本文件。
AssetList组记录的是主资源对象列表。
BundleList组记录的是资源包列表。
![image](./Image/AssetBuilder-img2.png)
@ -134,8 +138,8 @@ private static void BuildInternal(BuildTarget buildTarget)
buildParameters.BuildTarget = buildTarget;
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
buildParameters.BuildMode = EBuildMode.ForceRebuild;
buildParameters.BuildPackage = "DefaultPackage";
buildParameters.HumanReadableVersion = "v1.0";
buildParameters.PackageName = "DefaultPackage";
buildParameters.PackageVersion = "1.0.0";
buildParameters.VerifyBuildingResult = true;
buildParameters.EncryptionServices = new GameEncryption();
buildParameters.CompressOption = ECompressOption.LZ4;
@ -146,10 +150,12 @@ private static void BuildInternal(BuildTarget buildTarget)
AssetBundleBuilder builder = new AssetBundleBuilder();
var buildResult = builder.Run(buildParameters);
if (buildResult.Success)
Debug.Log($"构建成功!");
{
Debug.Log($"构建成功 : {buildResult.OutputPackageDirectory}");
}
}
// 从构建命令里获取参数
// 从构建命令里获取参数示例
private static string GetBuildPackageName()
{
foreach (string arg in System.Environment.GetCommandLineArgs())
@ -157,7 +163,7 @@ private static string GetBuildPackageName()
if (arg.StartsWith("buildPackage"))
return arg.Split("="[0])[1];
}
return -1;
return string.Empty;
}
````
@ -173,8 +179,8 @@ private static string GetBuildPackageName()
- **首包资源**
在构建应用程序的时候例如安卓的APK我们希望将某些资源打进首包里可以在构建成功后自己编写逻辑代码拷贝相关资源文件到StreamingAssets/YooAssets/目录里。首包资源如果发生变化,也可以通过热更新来更新资源。
在构建应用程序的时候我们希望将某些资源打进首包里首包资源拷贝至StreamingAssets/BuildinFiles/目录下。首包资源如果发生变化,也可以通过热更新来更新资源。
- **补丁包**
无论是通过增量构建还是强制构建,在构建完成后都会生成一个以补丁清单文件哈希值命名的文件夹我们把这个文件夹统称为补丁包。补丁包里包含了游戏运行需要的所有资源我们可以无脑的将补丁包内容覆盖到CDN目录下也可以通过编写差异分析工具来筛选出和线上最新版本之间的差异文件然后将差异文件上传到CDN目录里。
无论是通过增量构建还是强制构建,在构建完成后都会生成一个以包裹版本PackageVersion命名的文件夹我们把这个文件夹统称为补丁包。补丁包里包含了游戏运行需要的所有资源我们可以无脑的将补丁包内容覆盖到CDN目录下也可以通过编写差异分析工具来筛选出和线上最新版本之间的差异文件然后将差异文件上传到CDN目录里。

View File

@ -62,29 +62,18 @@ private IEnumerator InitializeYooAsset()
private IEnumerator InitializeYooAsset()
{
var initParameters = new HostPlayModeParameters();
initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
initParameters.DecryptionServices = new BundleDecryptionServices();
initParameters.QueryServices = new QueryStreamingAssetsServices();
initParameters.QueryServices = new QueryStreamingAssetsFileServices();
initParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android/v1.0";
initParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android/v1.0";
yield return defaultPackage.InitializeAsync(initParameters);
}
// 文件解密服务类
private class BundleDecryptionServices : IDecryptionServices
{
public ulong GetFileOffset(DecryptionFileInfo fileInfo)
{
return 32;
}
}
// 内置文件查询服务类
private class QueryStreamingAssetsServices : IQueryServices
private class QueryStreamingAssetsFileServices : IQueryServices
{
public bool QueryStreamingAssets(string fileName)
{
// 注意使用了BetterStreamingAssets插件
// 注意使用了BetterStreamingAssets插件使用前需要初始化该插件
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
return BetterStreamingAssets.FileExists($"{buildinFolderName}/{fileName}");
}

View File

@ -10,14 +10,14 @@
private IEnumerator UpdateStaticVersion()
{
var package = YooAssets.GetAssetsPackage("DefaultPackage");
UpdateStaticVersionOperation operation = package.UpdateStaticVersionAsync();
var operation = package.UpdateStaticVersionAsync();
yield return operation;
if (operation.Status == EOperationStatus.Succeed)
{
//更新成功
string packageCRC = operation.PackageCRC;
Debug.Log($"Update resource Version : {packageCRC}");
string PackageVersion = operation.PackageVersion;
Debug.Log($"Updated package Version : {PackageVersion}");
}
else
{
@ -35,7 +35,7 @@ private IEnumerator UpdateStaticVersion()
private IEnumerator UpdatePatchManifest()
{
var package = YooAssets.GetAssetsPackage("DefaultPackage");
UpdateManifestOperation operation = package.UpdateManifestAsync(packageCRC);
var operation = package.UpdateManifestAsync(packageVersion);
yield return operation;
if (operation.Status == EOperationStatus.Succeed)
@ -76,7 +76,8 @@ IEnumerator Download()
int downloadingMaxNum = 10;
int failedTryAgain = 3;
int timeout = 60;
var downloader = YooAssets.CreatePatchDownloader(downloadingMaxNum, failedTryAgain, timeout);
var package = YooAssets.GetAssetsPackage("DefaultPackage");
var downloader = package.CreatePatchDownloader(downloadingMaxNum, failedTryAgain, timeout);
//没有需要下载的资源
if (downloader.TotalDownloadCount == 0)
@ -115,10 +116,11 @@ IEnumerator Download()
对于偏单机但是也有资源热更需求的项目。当玩家本地网络不稳定或无网络的时候,我们又不希望玩家卡在资源更新步骤而不能正常游戏。所以当玩家本地网络有问题的时候,我们可以跳过资源更新的步骤。
````c#
private IEnumerator UpdateStaticVersion()
// 尝试从服务器获取最新的资源版本号
private IEnumerator TryUpdateStaticVersion()
{
var package = YooAssets.GetAssetsPackage("DefaultPackage");
UpdateStaticVersionOperation operation = package.UpdateStaticVersionAsync(10);
var operation = package.UpdateStaticVersionAsync(30);
yield return operation;
if (operation.Status == EOperationStatus.Succeed)
{
@ -128,20 +130,22 @@ private IEnumerator UpdateStaticVersion()
// 注意:在成功下载所有资源之后,我们需要记录当前最新的资源版本号
PlayerPrefs.SetString("STATIC_VERSION", packageCRC);
}
else
{
}
private IEnumerator TryUpdateStaticVersion()
{
// 如果获取远端资源版本失败,我们走弱联网更新模式。
// 注意如果从来没有保存过版本信息则需要从内部读取StaticVersion.bytes文件的版本信息。
string packageCRC = PlayerPrefs.GetString("STATIC_VERSION", string.Empty);
if (packageCRC == string.Empty)
string packageVersion = PlayerPrefs.GetString("STATIC_VERSION", string.Empty);
if (packageVersion == string.Empty)
{
packageCRC = LoadStaticVersionFromStreamingAssets();
packageVersion = LoadStaticVersionFromStreamingAssets();
}
// 在弱联网情况下更新补丁清单
UpdateManifestOperation operation2 = package.WeaklyUpdateManifestAsync(packageCRC);
yield return operation2;
if (operation2.Status == EOperationStatus.Succeed)
var operation = package.WeaklyUpdateManifestAsync(packageVersion);
yield return operation;
if (operation.Status == EOperationStatus.Succeed)
{
StartGame();
}
@ -150,7 +154,6 @@ private IEnumerator UpdateStaticVersion()
// 指定版本的资源内容本地并不完整,需要提示玩家更新。
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
}
}
}
````

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 163 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 153 KiB