Update runtime logic
parent
e1801a5fba
commit
af37bb6e54
|
@ -1,60 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class CacheData
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存的APP内置版本
|
||||
/// </summary>
|
||||
public string CacheAppVersion = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 读取缓存文件
|
||||
/// 注意:如果文件不存在则创建新的缓存文件
|
||||
/// </summary>
|
||||
public static CacheData LoadCache()
|
||||
{
|
||||
string filePath = GetCacheDataFilePath();
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string jsonData = FileUtility.ReadFile(filePath);
|
||||
var cacheData = JsonUtility.FromJson<CacheData>(jsonData);
|
||||
YooLogger.Log($"Load cache data : {cacheData.CacheAppVersion}");
|
||||
return cacheData;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Log($"Create cache data : {Application.version}");
|
||||
CacheData cacheData = new CacheData();
|
||||
cacheData.CacheAppVersion = Application.version;
|
||||
string jsonData = JsonUtility.ToJson(cacheData);
|
||||
FileUtility.CreateFile(filePath, jsonData);
|
||||
return cacheData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新缓存文件
|
||||
/// </summary>
|
||||
public static void UpdateCache()
|
||||
{
|
||||
YooLogger.Log($"Update cache data to disk : {Application.version}");
|
||||
CacheData cacheData = new CacheData();
|
||||
cacheData.CacheAppVersion = Application.version;
|
||||
string filePath = GetCacheDataFilePath();
|
||||
string jsonData = JsonUtility.ToJson(cacheData);
|
||||
FileUtility.CreateFile(filePath, jsonData);
|
||||
}
|
||||
|
||||
private static string GetCacheDataFilePath()
|
||||
{
|
||||
return PathHelper.MakePersistentLoadPath("CacheData.bytes");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 37a7daecdb1361140b44ba4724e8866e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -89,12 +89,13 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
private readonly OfflinePlayModeImpl _impl;
|
||||
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
||||
private AppManifestLoader _appManifestLoader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, string buildinPackageName)
|
||||
{
|
||||
_impl = impl;
|
||||
_appManifestLoader = new AppManifestLoader(buildinPackageName);
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
|
@ -136,51 +137,32 @@ namespace YooAsset
|
|||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitCache,
|
||||
LoadManifest,
|
||||
CopyManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
||||
private readonly AppManifestCopyer _appManifestCopyer = new AppManifestCopyer();
|
||||
private readonly string _buildinPackageName;
|
||||
private AppManifestLoader _appManifestLoader;
|
||||
private AppManifestCopyer _appManifestCopyer;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, string buildinPackageName)
|
||||
{
|
||||
_impl = impl;
|
||||
_buildinPackageName = buildinPackageName;
|
||||
_appManifestLoader = new AppManifestLoader(buildinPackageName);
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.InitCache;
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitCache)
|
||||
{
|
||||
// 每次启动时比对APP版本号是否一致
|
||||
CacheData cacheData = CacheData.LoadCache();
|
||||
if (cacheData.CacheAppVersion != Application.version)
|
||||
{
|
||||
YooLogger.Warning($"Cache is dirty ! Cache application version is {cacheData.CacheAppVersion}, Current application version is {Application.version}");
|
||||
|
||||
// 注意:在覆盖安装的时候,会保留APP沙盒目录,可以选择清空缓存目录
|
||||
if (_impl.ClearCacheWhenDirty)
|
||||
{
|
||||
YooLogger.Warning("Clear cache files.");
|
||||
SandboxHelper.DeleteCacheFolder();
|
||||
}
|
||||
|
||||
// 更新缓存文件
|
||||
CacheData.UpdateCache();
|
||||
}
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadManifest)
|
||||
{
|
||||
_appManifestLoader.Update();
|
||||
|
@ -198,7 +180,7 @@ namespace YooAsset
|
|||
{
|
||||
_impl.SetAppPatchManifest(_appManifestLoader.Result);
|
||||
_impl.SetLocalPatchManifest(_appManifestLoader.Result);
|
||||
_appManifestCopyer.Init(_appManifestLoader.StaticVersion);
|
||||
_appManifestCopyer = new AppManifestCopyer(_buildinPackageName, _appManifestLoader.BuildinPackageCRC);
|
||||
_steps = ESteps.CopyManifest;
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +221,7 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private string _buildinPackageName;
|
||||
private ESteps _steps = ESteps.LoadStaticVersion;
|
||||
private UnityWebDataRequester _downloader1;
|
||||
private UnityWebDataRequester _downloader2;
|
||||
|
@ -254,9 +237,15 @@ namespace YooAsset
|
|||
public PatchManifest Result { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 内置补丁清单版本号
|
||||
/// 内置补丁清单CRC
|
||||
/// </summary>
|
||||
public int StaticVersion { private set; get; }
|
||||
public string BuildinPackageCRC { private set; get; }
|
||||
|
||||
|
||||
public AppManifestLoader(string buildinPackageName)
|
||||
{
|
||||
_buildinPackageName = buildinPackageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
|
@ -287,7 +276,8 @@ namespace YooAsset
|
|||
if (_steps == ESteps.LoadStaticVersion)
|
||||
{
|
||||
YooLogger.Log($"Load application static version.");
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettings.VersionFileName);
|
||||
string fileName = YooAssetSettingsData.GetStaticVersionFileName(_buildinPackageName);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
_downloader1 = new UnityWebDataRequester();
|
||||
_downloader1.SendRequest(url);
|
||||
|
@ -306,7 +296,7 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
StaticVersion = int.Parse(_downloader1.GetText());
|
||||
BuildinPackageCRC = _downloader1.GetText();
|
||||
_steps = ESteps.LoadAppManifest;
|
||||
}
|
||||
_downloader1.Dispose();
|
||||
|
@ -315,7 +305,8 @@ namespace YooAsset
|
|||
if (_steps == ESteps.LoadAppManifest)
|
||||
{
|
||||
YooLogger.Log($"Load application patch manifest.");
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(StaticVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, BuildinPackageCRC);
|
||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||
_downloader2 = new UnityWebDataRequester();
|
||||
_downloader2.SendRequest(url);
|
||||
|
@ -355,10 +346,10 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private string _buildinPackageName;
|
||||
private string _buildinPackageCRC;
|
||||
private ESteps _steps = ESteps.CopyAppManifest;
|
||||
private UnityWebFileRequester _downloader1;
|
||||
private int _staticVersion;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 错误日志
|
||||
|
@ -370,20 +361,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public bool Result { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
/// </summary>
|
||||
public bool IsDone()
|
||||
{
|
||||
return _steps == ESteps.Done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化流程
|
||||
/// </summary>
|
||||
public void Init(int staticVersion)
|
||||
public AppManifestCopyer(string buildinPackageName, string buildinPackageCRC)
|
||||
{
|
||||
_staticVersion = staticVersion;
|
||||
_buildinPackageName = buildinPackageName;
|
||||
_buildinPackageCRC = buildinPackageCRC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -396,7 +378,8 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.CopyAppManifest)
|
||||
{
|
||||
string destFilePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, _buildinPackageCRC);
|
||||
string destFilePath = PathHelper.MakePersistentLoadPath(fileName);
|
||||
if (File.Exists(destFilePath))
|
||||
{
|
||||
Result = true;
|
||||
|
@ -406,7 +389,7 @@ namespace YooAsset
|
|||
else
|
||||
{
|
||||
YooLogger.Log($"Copy application patch manifest.");
|
||||
string sourceFilePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
||||
string sourceFilePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||
string url = PathHelper.ConvertToWWWPath(sourceFilePath);
|
||||
_downloader1 = new UnityWebFileRequester();
|
||||
_downloader1.SendRequest(url, destFilePath);
|
||||
|
@ -433,5 +416,13 @@ namespace YooAsset
|
|||
_downloader1.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
/// </summary>
|
||||
public bool IsDone()
|
||||
{
|
||||
return _steps == ESteps.Done;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,8 +52,7 @@ namespace YooAsset
|
|||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadWebManifestHash,
|
||||
CheckWebManifestHash,
|
||||
CheckManifestHash,
|
||||
LoadWebManifest,
|
||||
CheckWebManifest,
|
||||
InitVerifyingCache,
|
||||
|
@ -63,18 +62,19 @@ namespace YooAsset
|
|||
|
||||
private static int RequestCount = 0;
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly int _resourceVersion;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageCRC;
|
||||
private readonly int _timeout;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebDataRequester _downloader1;
|
||||
private UnityWebDataRequester _downloader2;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private PatchCacheVerifier _patchCacheVerifier;
|
||||
private float _verifyTime;
|
||||
|
||||
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
||||
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, string packageName, string packageCRC, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_resourceVersion = resourceVersion;
|
||||
_packageName = packageName;
|
||||
_packageCRC = packageCRC;
|
||||
_timeout = timeout;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
|
@ -86,82 +86,59 @@ namespace YooAsset
|
|||
internal override void Start()
|
||||
{
|
||||
RequestCount++;
|
||||
_steps = ESteps.LoadWebManifestHash;
|
||||
_steps = ESteps.CheckManifestHash;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadWebManifestHash)
|
||||
if (_steps == ESteps.CheckManifestHash)
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
|
||||
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
||||
_downloader1 = new UnityWebDataRequester();
|
||||
_downloader1.SendRequest(webURL, _timeout);
|
||||
_steps = ESteps.CheckWebManifestHash;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckWebManifestHash)
|
||||
{
|
||||
if (_downloader1.IsDone() == false)
|
||||
return;
|
||||
|
||||
// Check error
|
||||
if (_downloader1.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader1.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
string webManifestHash = _downloader1.GetText();
|
||||
string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
|
||||
string cachedManifestCRC = GetSandboxPatchManifestFileHash(_packageName, _packageCRC);
|
||||
|
||||
// 如果补丁清单文件的哈希值相同
|
||||
if (cachedManifestHash == webManifestHash)
|
||||
if (cachedManifestCRC == _packageCRC)
|
||||
{
|
||||
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
||||
LoadSandboxPatchManifest(_resourceVersion);
|
||||
YooLogger.Log($"Patch manifest file hash is not change : {_packageCRC}");
|
||||
LoadSandboxPatchManifest(_packageName, _packageCRC);
|
||||
FoundNewManifest = false;
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
|
||||
YooLogger.Log($"Patch manifest hash is change : {cachedManifestCRC} -> {_packageCRC}");
|
||||
FoundNewManifest = true;
|
||||
_steps = ESteps.LoadWebManifest;
|
||||
}
|
||||
}
|
||||
_downloader1.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadWebManifest)
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageCRC);
|
||||
string webURL = GetPatchManifestRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||
_downloader2 = new UnityWebDataRequester();
|
||||
_downloader2.SendRequest(webURL, _timeout);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
_steps = ESteps.CheckWebManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckWebManifest)
|
||||
{
|
||||
if (_downloader2.IsDone() == false)
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
// Check error
|
||||
if (_downloader2.HasError())
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader2.GetError();
|
||||
Error = _downloader.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 解析补丁清单
|
||||
if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
|
||||
if (ParseAndSaveRemotePatchManifest(_packageName, _packageCRC, _downloader.GetText()))
|
||||
{
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
|
@ -169,10 +146,10 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
|
||||
Error = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
|
||||
}
|
||||
}
|
||||
_downloader2.Dispose();
|
||||
_downloader.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitVerifyingCache)
|
||||
|
@ -210,7 +187,7 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 解析并保存远端请求的补丁清单
|
||||
/// </summary>
|
||||
private bool ParseAndSaveRemotePatchManifest(int updateResourceVersion, string content)
|
||||
private bool ParseAndSaveRemotePatchManifest(string packageName, string packageCRC, string content)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -218,7 +195,8 @@ namespace YooAsset
|
|||
_impl.SetLocalPatchManifest(remotePatchManifest);
|
||||
|
||||
YooLogger.Log("Save remote patch manifest file.");
|
||||
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC);
|
||||
string savePath = PathHelper.MakePersistentLoadPath(fileName);
|
||||
PatchManifest.Serialize(savePath, remotePatchManifest);
|
||||
return true;
|
||||
}
|
||||
|
@ -233,10 +211,11 @@ namespace YooAsset
|
|||
/// 加载沙盒内的补丁清单
|
||||
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
|
||||
/// </summary>
|
||||
private void LoadSandboxPatchManifest(int updateResourceVersion)
|
||||
private void LoadSandboxPatchManifest(string packageName, string packageCRC)
|
||||
{
|
||||
YooLogger.Log("Load sandbox patch manifest file.");
|
||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC);
|
||||
string filePath = PathHelper.MakePersistentLoadPath(fileName);
|
||||
string jsonData = File.ReadAllText(filePath);
|
||||
var sandboxPatchManifest = PatchManifest.Deserialize(jsonData);
|
||||
_impl.SetLocalPatchManifest(sandboxPatchManifest);
|
||||
|
@ -246,11 +225,12 @@ namespace YooAsset
|
|||
/// 获取沙盒内补丁清单文件的哈希值
|
||||
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
|
||||
/// </summary>
|
||||
private string GetSandboxPatchManifestFileHash(int updateResourceVersion)
|
||||
private string GetSandboxPatchManifestFileHash(string packageName, string packageCRC)
|
||||
{
|
||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC);
|
||||
string filePath = PathHelper.MakePersistentLoadPath(fileName);
|
||||
if (File.Exists(filePath))
|
||||
return HashUtility.FileMD5(filePath);
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
@ -271,15 +251,17 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly int _resourceVersion;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageCRC;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private PatchCacheVerifier _patchCacheVerifier;
|
||||
private float _verifyTime;
|
||||
|
||||
internal HostPlayModeWeaklyUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion)
|
||||
internal HostPlayModeWeaklyUpdateManifestOperation(HostPlayModeImpl impl, string packageName, string packageCRC)
|
||||
{
|
||||
_impl = impl;
|
||||
_resourceVersion = resourceVersion;
|
||||
_packageName = packageName;
|
||||
_packageCRC = packageCRC;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
_patchCacheVerifier = new PatchCacheVerifierWithoutThread();
|
||||
|
@ -298,7 +280,7 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.LoadSandboxManifestHash)
|
||||
{
|
||||
LoadSandboxPatchManifest(_resourceVersion);
|
||||
LoadSandboxPatchManifest(_packageName, _packageCRC);
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
|
||||
|
@ -313,7 +295,7 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The resource version {_resourceVersion} content is not complete !";
|
||||
Error = $"The package resource {_packageName}_{_packageCRC} content is not complete !";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +310,7 @@ namespace YooAsset
|
|||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The resource version {_resourceVersion} content has verify failed file !";
|
||||
Error = $"The package resource {_packageName}_{_packageCRC} content has verify failed file !";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -343,9 +325,10 @@ namespace YooAsset
|
|||
/// 加载沙盒内的补丁清单
|
||||
/// 注意:在加载本地补丁清单之前,未验证过文件的哈希值
|
||||
/// </summary>
|
||||
private void LoadSandboxPatchManifest(int updateResourceVersion)
|
||||
private void LoadSandboxPatchManifest(string packageName, string packageCRC)
|
||||
{
|
||||
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC);
|
||||
string filePath = PathHelper.MakePersistentLoadPath(fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
YooLogger.Log("Load sandbox patch manifest file.");
|
||||
|
|
|
@ -78,16 +78,18 @@ namespace YooAsset
|
|||
|
||||
private static int RequestCount = 0;
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly int _resourceVersion;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageCRC;
|
||||
private readonly int _timeout;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private PatchManifest _remotePatchManifest;
|
||||
|
||||
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
||||
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, string packageName, string packageCRC, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_resourceVersion = resourceVersion;
|
||||
_packageName = packageName;
|
||||
_packageCRC = packageCRC;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void Start()
|
||||
|
@ -102,7 +104,8 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.LoadWebManifest)
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageCRC);
|
||||
string webURL = GetPatchManifestRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace YooAsset
|
|||
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源版本号
|
||||
/// 包裹文件的哈希值
|
||||
/// </summary>
|
||||
public int ResourceVersion { protected set; get; } = 0;
|
||||
public string PackageCRC { protected set; get; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -57,13 +57,15 @@ namespace YooAsset
|
|||
|
||||
private static int RequestCount = 0;
|
||||
private readonly HostPlayModeImpl _impl;
|
||||
private readonly string _packageName;
|
||||
private readonly int _timeout;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebDataRequester _downloader;
|
||||
|
||||
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, int timeout)
|
||||
internal HostPlayModeUpdateStaticVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageName = packageName;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void Start()
|
||||
|
@ -78,7 +80,8 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.LoadStaticVersion)
|
||||
{
|
||||
string webURL = GetStaticVersionRequestURL(YooAssetSettings.VersionFileName);
|
||||
string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(_packageName);
|
||||
string webURL = GetStaticVersionRequestURL(versionFileName);
|
||||
YooLogger.Log($"Beginning to request static version : {webURL}");
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
|
@ -99,17 +102,18 @@ namespace YooAsset
|
|||
}
|
||||
else
|
||||
{
|
||||
if (int.TryParse(_downloader.GetText(), out int value))
|
||||
{
|
||||
ResourceVersion = value;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
string packageCRC = _downloader.GetText();
|
||||
if(string.IsNullOrEmpty(packageCRC))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_downloader.URL} Error : static version content is invalid.";
|
||||
Error = $"URL : {_downloader.URL} Error : static version content is empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
PackageCRC = packageCRC;
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
_downloader.Dispose();
|
||||
|
|
|
@ -17,11 +17,6 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string FileVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 资源版本号
|
||||
/// </summary>
|
||||
public int ResourceVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
|
@ -32,6 +27,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public int OutputNameStyle;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的标签列表(首包资源)
|
||||
/// </summary>
|
||||
|
|
|
@ -20,16 +20,6 @@ namespace YooAsset
|
|||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源版本号
|
||||
/// </summary>
|
||||
public int GetResourceVersion()
|
||||
{
|
||||
if (_simulatePatchManifest == null)
|
||||
return 0;
|
||||
return _simulatePatchManifest.ResourceVersion;
|
||||
}
|
||||
|
||||
// 设置资源清单
|
||||
internal void SetSimulatePatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
|
|
|
@ -13,26 +13,19 @@ namespace YooAsset
|
|||
|
||||
// 参数相关
|
||||
private bool _locationToLower;
|
||||
private bool _clearCacheWhenDirty;
|
||||
private string _defaultHostServer;
|
||||
private string _fallbackHostServer;
|
||||
|
||||
public bool ClearCacheWhenDirty
|
||||
{
|
||||
get { return _clearCacheWhenDirty; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
|
||||
public InitializationOperation InitializeAsync(bool locationToLower, string buildinPackageName, string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
_locationToLower = locationToLower;
|
||||
_clearCacheWhenDirty = clearCacheWhenDirty;
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
|
||||
var operation = new HostPlayModeInitializationOperation(this);
|
||||
var operation = new HostPlayModeInitializationOperation(this, buildinPackageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
@ -40,9 +33,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步更新资源版本号
|
||||
/// </summary>
|
||||
public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout)
|
||||
public UpdateStaticVersionOperation UpdateStaticVersionAsync(string packageName, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout);
|
||||
var operation = new HostPlayModeUpdateStaticVersionOperation(this, packageName, timeout);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
@ -50,9 +43,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步更新补丁清单
|
||||
/// </summary>
|
||||
public UpdateManifestOperation UpdatePatchManifestAsync(int resourceVersion, int timeout)
|
||||
public UpdateManifestOperation UpdatePatchManifestAsync(string packageName, string packageCRC, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdateManifestOperation(this, resourceVersion, timeout);
|
||||
var operation = new HostPlayModeUpdateManifestOperation(this, packageName, packageCRC, timeout);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
@ -60,9 +53,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步更新补丁清单(弱联网)
|
||||
/// </summary>
|
||||
public UpdateManifestOperation WeaklyUpdatePatchManifestAsync(int resourceVersion)
|
||||
public UpdateManifestOperation WeaklyUpdatePatchManifestAsync(string packageName, string packageCRC)
|
||||
{
|
||||
var operation = new HostPlayModeWeaklyUpdateManifestOperation(this, resourceVersion);
|
||||
var operation = new HostPlayModeWeaklyUpdateManifestOperation(this, packageName, packageCRC);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
@ -70,23 +63,13 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步更新资源包裹
|
||||
/// </summary>
|
||||
public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout)
|
||||
public UpdatePackageOperation UpdatePackageAsync(string packageName, string packageCRC, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout);
|
||||
var operation = new HostPlayModeUpdatePackageOperation(this, packageName, packageCRC, timeout);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源版本号
|
||||
/// </summary>
|
||||
public int GetResourceVersion()
|
||||
{
|
||||
if (LocalPatchManifest == null)
|
||||
return 0;
|
||||
return LocalPatchManifest.ResourceVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未被使用的缓存文件路径集合
|
||||
/// </summary>
|
||||
|
|
|
@ -12,24 +12,14 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(bool locationToLower)
|
||||
public InitializationOperation InitializeAsync(bool locationToLower, string buildinPackageName)
|
||||
{
|
||||
_locationToLower = locationToLower;
|
||||
var operation = new OfflinePlayModeInitializationOperation(this);
|
||||
var operation = new OfflinePlayModeInitializationOperation(this, buildinPackageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源版本号
|
||||
/// </summary>
|
||||
public int GetResourceVersion()
|
||||
{
|
||||
if (_appPatchManifest == null)
|
||||
return 0;
|
||||
return _appPatchManifest.ResourceVersion;
|
||||
}
|
||||
|
||||
// 设置资源清单
|
||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 补丁清单文件版本
|
||||
/// </summary>
|
||||
public const string PatchManifestFileVersion = "1.2.2";
|
||||
public const string PatchManifestFileVersion = "1.3.0";
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出文件夹名称
|
||||
|
@ -39,7 +39,7 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 静态版本文件
|
||||
/// </summary>
|
||||
public const string VersionFileName = "StaticVersion.bytes";
|
||||
public const string VersionFileName = "StaticVersion";
|
||||
|
||||
/// <summary>
|
||||
/// Unity着色器资源包名称
|
||||
|
|
|
@ -35,25 +35,33 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 获取构建报告文件名
|
||||
/// </summary>
|
||||
public static string GetReportFileName(int resourceVersion)
|
||||
public static string GetReportFileName(string packageName, string packageCRC)
|
||||
{
|
||||
return $"{YooAssetSettings.ReportFileName}_{resourceVersion}.json";
|
||||
return $"{YooAssetSettings.ReportFileName}_{packageName}_{packageCRC}.json";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取补丁清单文件完整名称
|
||||
/// </summary>
|
||||
public static string GetPatchManifestFileName(int resourceVersion)
|
||||
public static string GetPatchManifestFileName(string packageName, string packageCRC)
|
||||
{
|
||||
return $"{Setting.PatchManifestFileName}_{resourceVersion}.bytes";
|
||||
return $"{Setting.PatchManifestFileName}_{packageName}_{packageCRC}.bytes";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取补丁清单哈希文件完整名称
|
||||
/// 获取补丁清单文件临时名称
|
||||
/// </summary>
|
||||
public static string GetPatchManifestHashFileName(int resourceVersion)
|
||||
public static string GetPatchManifestTempFileName(string packageName)
|
||||
{
|
||||
return $"{Setting.PatchManifestFileName}_{resourceVersion}.hash";
|
||||
return $"{Setting.PatchManifestFileName}_{packageName}.temp";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取静态版本文件名称
|
||||
/// </summary>
|
||||
public static string GetStaticVersionFileName(string packageName)
|
||||
{
|
||||
return $"{YooAssetSettings.VersionFileName}_{packageName}.bytes";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -40,6 +40,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public bool LocationToLower = false;
|
||||
|
||||
/// <summary>
|
||||
/// 内置的资源包裹名称
|
||||
/// </summary>
|
||||
public string BuildinPackageName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位服务接口
|
||||
/// </summary>
|
||||
|
@ -146,16 +151,19 @@ namespace YooAsset
|
|||
if (parameters == null)
|
||||
throw new Exception($"YooAsset create parameters is null.");
|
||||
|
||||
if (string.IsNullOrEmpty(parameters.BuildinPackageName))
|
||||
throw new Exception($"{nameof(parameters.BuildinPackageName)} is empty.");
|
||||
|
||||
if (parameters.LocationServices == null)
|
||||
throw new Exception($"{nameof(IBundleServices)} is null.");
|
||||
else
|
||||
_locationServices = parameters.LocationServices;
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
throw new Exception($"Editor simulate mode only support unity editor.");
|
||||
#endif
|
||||
|
||||
_locationServices = parameters.LocationServices;
|
||||
|
||||
// 创建驱动器
|
||||
if (_isInitialize == false)
|
||||
{
|
||||
|
@ -228,7 +236,7 @@ namespace YooAsset
|
|||
_offlinePlayModeImpl = new OfflinePlayModeImpl();
|
||||
_bundleServices = _offlinePlayModeImpl;
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync(parameters.LocationToLower);
|
||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync(parameters.LocationToLower, parameters.BuildinPackageName);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
|
@ -238,7 +246,7 @@ namespace YooAsset
|
|||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = _hostPlayModeImpl.InitializeAsync(
|
||||
hostPlayModeParameters.LocationToLower,
|
||||
hostPlayModeParameters.ClearCacheWhenDirty,
|
||||
hostPlayModeParameters.BuildinPackageName,
|
||||
hostPlayModeParameters.DefaultHostServer,
|
||||
hostPlayModeParameters.FallbackHostServer);
|
||||
}
|
||||
|
@ -260,8 +268,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 向网络端请求静态资源版本
|
||||
/// </summary>
|
||||
/// <param name="packageName">更新的资源包裹名称</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60)
|
||||
public static UpdateStaticVersionOperation UpdateStaticVersionAsync(string packageName, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
|
@ -278,7 +287,7 @@ namespace YooAsset
|
|||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.UpdateStaticVersionAsync(timeout);
|
||||
return _hostPlayModeImpl.UpdateStaticVersionAsync(packageName, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -289,9 +298,10 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 向网络端请求并更新补丁清单
|
||||
/// </summary>
|
||||
/// <param name="resourceVersion">更新的资源版本</param>
|
||||
/// <param name="packageName">更新的资源包裹名称</param>
|
||||
/// <param name="packageCRC">更新的资源包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public static UpdateManifestOperation UpdateManifestAsync(int resourceVersion, int timeout = 60)
|
||||
public static UpdateManifestOperation UpdateManifestAsync(string packageName, string packageCRC, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckUpdateManifest();
|
||||
|
@ -309,7 +319,7 @@ namespace YooAsset
|
|||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.UpdatePatchManifestAsync(resourceVersion, timeout);
|
||||
return _hostPlayModeImpl.UpdatePatchManifestAsync(packageName, packageCRC, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -321,8 +331,9 @@ namespace YooAsset
|
|||
/// 弱联网情况下加载补丁清单
|
||||
/// 注意:当指定版本内容验证失败后会返回失败。
|
||||
/// </summary>
|
||||
/// <param name="resourceVersion">指定的资源版本</param>
|
||||
public static UpdateManifestOperation WeaklyUpdateManifestAsync(int resourceVersion)
|
||||
/// <param name="packageName">指定的资源包裹名称</param>
|
||||
/// <param name="packageCRC">指定的资源包裹版本</param>
|
||||
public static UpdateManifestOperation WeaklyUpdateManifestAsync(string packageName, string packageCRC)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
|
@ -339,7 +350,7 @@ namespace YooAsset
|
|||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.WeaklyUpdatePatchManifestAsync(resourceVersion);
|
||||
return _hostPlayModeImpl.WeaklyUpdatePatchManifestAsync(packageName, packageCRC);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -356,30 +367,6 @@ namespace YooAsset
|
|||
OperationSystem.StartOperation(operation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源版本号
|
||||
/// </summary>
|
||||
public static int GetResourceVersion()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
return _editorSimulateModeImpl.GetResourceVersion();
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
return _offlinePlayModeImpl.GetResourceVersion();
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.GetResourceVersion();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// </summary>
|
||||
|
@ -985,9 +972,10 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件
|
||||
/// </summary>
|
||||
/// <param name="resourceVersion">指定更新的资源版本</param>
|
||||
/// <param name="packageName">指定更新的资源包裹名称</param>
|
||||
/// <param name="packageCRC">指定更新的资源包裹版本</param>
|
||||
/// <param name="timeout">超时时间</param>
|
||||
public static UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout = 60)
|
||||
public static UpdatePackageOperation UpdatePackageAsync(string packageName, string packageCRC, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
|
@ -1004,7 +992,7 @@ namespace YooAsset
|
|||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
return _hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout);
|
||||
return _hostPlayModeImpl.UpdatePackageAsync(packageName, packageCRC, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue