diff --git a/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs b/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs
deleted file mode 100644
index 8cfdd20..0000000
--- a/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs
+++ /dev/null
@@ -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
- {
- ///
- /// 缓存的APP内置版本
- ///
- public string CacheAppVersion = string.Empty;
-
- ///
- /// 读取缓存文件
- /// 注意:如果文件不存在则创建新的缓存文件
- ///
- public static CacheData LoadCache()
- {
- string filePath = GetCacheDataFilePath();
- if (File.Exists(filePath))
- {
- string jsonData = FileUtility.ReadFile(filePath);
- var cacheData = JsonUtility.FromJson(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;
- }
- }
-
- ///
- /// 更新缓存文件
- ///
- 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");
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs.meta
deleted file mode 100644
index c660875..0000000
--- a/Assets/YooAsset/Runtime/PatchSystem/CacheData.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 37a7daecdb1361140b44ba4724e8866e
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
index 19aef93..2753163 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs
@@ -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; }
///
- /// 内置补丁清单版本号
+ /// 内置补丁清单CRC
///
- public int StaticVersion { private set; get; }
+ public string BuildinPackageCRC { private set; get; }
+
+
+ public AppManifestLoader(string buildinPackageName)
+ {
+ _buildinPackageName = buildinPackageName;
+ }
///
/// 是否已经完成
@@ -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;
-
///
/// 错误日志
@@ -370,20 +361,11 @@ namespace YooAsset
///
public bool Result { private set; get; }
- ///
- /// 是否已经完成
- ///
- public bool IsDone()
- {
- return _steps == ESteps.Done;
- }
- ///
- /// 初始化流程
- ///
- public void Init(int staticVersion)
+ public AppManifestCopyer(string buildinPackageName, string buildinPackageCRC)
{
- _staticVersion = staticVersion;
+ _buildinPackageName = buildinPackageName;
+ _buildinPackageCRC = buildinPackageCRC;
}
///
@@ -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();
}
}
+
+ ///
+ /// 是否已经完成
+ ///
+ public bool IsDone()
+ {
+ return _steps == ESteps.Done;
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
index 7d9aa76..214416e 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
@@ -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;
- }
+ string cachedManifestCRC = GetSandboxPatchManifestFileHash(_packageName, _packageCRC);
- if (_steps == ESteps.CheckWebManifestHash)
- {
- if (_downloader1.IsDone() == false)
- return;
-
- // Check error
- if (_downloader1.HasError())
+ // 如果补丁清单文件的哈希值相同
+ if (cachedManifestCRC == _packageCRC)
{
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = _downloader1.GetError();
+ YooLogger.Log($"Patch manifest file hash is not change : {_packageCRC}");
+ LoadSandboxPatchManifest(_packageName, _packageCRC);
+ FoundNewManifest = false;
+ _steps = ESteps.InitVerifyingCache;
}
else
{
- string webManifestHash = _downloader1.GetText();
- string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
-
- // 如果补丁清单文件的哈希值相同
- if (cachedManifestHash == webManifestHash)
- {
- YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
- LoadSandboxPatchManifest(_resourceVersion);
- FoundNewManifest = false;
- _steps = ESteps.InitVerifyingCache;
- }
- else
- {
- YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
- FoundNewManifest = true;
- _steps = ESteps.LoadWebManifest;
- }
+ 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
///
/// 解析并保存远端请求的补丁清单
///
- 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
/// 加载沙盒内的补丁清单
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
///
- 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
/// 获取沙盒内补丁清单文件的哈希值
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
///
- 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
/// 加载沙盒内的补丁清单
/// 注意:在加载本地补丁清单之前,未验证过文件的哈希值
///
- 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.");
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
index 9abdb44..3d74a38 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
@@ -78,21 +78,23 @@ 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()
{
- RequestCount++;
+ RequestCount++;
_steps = ESteps.LoadWebManifest;
}
internal override void Update()
@@ -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);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
index 3100025..3d6e7c1 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs
@@ -9,9 +9,9 @@ namespace YooAsset
public abstract class UpdateStaticVersionOperation : AsyncOperationBase
{
///
- /// 资源版本号
+ /// 包裹文件的哈希值
///
- public int ResourceVersion { protected set; get; } = 0;
+ public string PackageCRC { protected set; get; } = string.Empty;
}
///
@@ -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();
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
index ea18152..adf5468 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
@@ -17,11 +17,6 @@ namespace YooAsset
///
public string FileVersion;
- ///
- /// 资源版本号
- ///
- public int ResourceVersion;
-
///
/// 启用可寻址资源定位
///
@@ -32,6 +27,11 @@ namespace YooAsset
///
public int OutputNameStyle;
+ ///
+ /// 资源包裹名称
+ ///
+ public string PackageName;
+
///
/// 内置资源的标签列表(首包资源)
///
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
index 0147a7a..0e985d4 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs
@@ -20,16 +20,6 @@ namespace YooAsset
return operation;
}
- ///
- /// 获取资源版本号
- ///
- public int GetResourceVersion()
- {
- if (_simulatePatchManifest == null)
- return 0;
- return _simulatePatchManifest.ResourceVersion;
- }
-
// 设置资源清单
internal void SetSimulatePatchManifest(PatchManifest patchManifest)
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index e668cfa..b7b5517 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -13,26 +13,19 @@ namespace YooAsset
// 参数相关
private bool _locationToLower;
- private bool _clearCacheWhenDirty;
private string _defaultHostServer;
private string _fallbackHostServer;
- public bool ClearCacheWhenDirty
- {
- get { return _clearCacheWhenDirty; }
- }
-
///
/// 异步初始化
///
- 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
///
/// 异步更新资源版本号
///
- 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
///
/// 异步更新补丁清单
///
- 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
///
/// 异步更新补丁清单(弱联网)
///
- 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
///
/// 异步更新资源包裹
///
- 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;
}
- ///
- /// 获取资源版本号
- ///
- public int GetResourceVersion()
- {
- if (LocalPatchManifest == null)
- return 0;
- return LocalPatchManifest.ResourceVersion;
- }
-
///
/// 获取未被使用的缓存文件路径集合
///
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
index b3236a4..95640d9 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -12,24 +12,14 @@ namespace YooAsset
///
/// 异步初始化
///
- 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;
}
- ///
- /// 获取资源版本号
- ///
- public int GetResourceVersion()
- {
- if (_appPatchManifest == null)
- return 0;
- return _appPatchManifest.ResourceVersion;
- }
-
// 设置资源清单
internal void SetAppPatchManifest(PatchManifest patchManifest)
{
diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
index 8a801c9..4cb3f39 100644
--- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
+++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
@@ -24,7 +24,7 @@ namespace YooAsset
///
/// 补丁清单文件版本
///
- public const string PatchManifestFileVersion = "1.2.2";
+ public const string PatchManifestFileVersion = "1.3.0";
///
/// 构建输出文件夹名称
@@ -39,7 +39,7 @@ namespace YooAsset
///
/// 静态版本文件
///
- public const string VersionFileName = "StaticVersion.bytes";
+ public const string VersionFileName = "StaticVersion";
///
/// Unity着色器资源包名称
diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs
index d4bcdfb..da5403a 100644
--- a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs
+++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs
@@ -35,25 +35,33 @@ namespace YooAsset
///
/// 获取构建报告文件名
///
- 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";
}
///
/// 获取补丁清单文件完整名称
///
- 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";
}
///
- /// 获取补丁清单哈希文件完整名称
+ /// 获取补丁清单文件临时名称
///
- public static string GetPatchManifestHashFileName(int resourceVersion)
+ public static string GetPatchManifestTempFileName(string packageName)
{
- return $"{Setting.PatchManifestFileName}_{resourceVersion}.hash";
+ return $"{Setting.PatchManifestFileName}_{packageName}.temp";
+ }
+
+ ///
+ /// 获取静态版本文件名称
+ ///
+ public static string GetStaticVersionFileName(string packageName)
+ {
+ return $"{YooAssetSettings.VersionFileName}_{packageName}.bytes";
}
///
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index b82438f..88eb8b5 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -40,6 +40,11 @@ namespace YooAsset
///
public bool LocationToLower = false;
+ ///
+ /// 内置的资源包裹名称
+ ///
+ public string BuildinPackageName = string.Empty;
+
///
/// 资源定位服务接口
///
@@ -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
///
/// 向网络端请求静态资源版本
///
+ /// 更新的资源包裹名称
/// 超时时间(默认值:60秒)
- 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
///
/// 向网络端请求并更新补丁清单
///
- /// 更新的资源版本
+ /// 更新的资源包裹名称
+ /// 更新的资源包裹版本
/// 超时时间(默认值:60秒)
- 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
/// 弱联网情况下加载补丁清单
/// 注意:当指定版本内容验证失败后会返回失败。
///
- /// 指定的资源版本
- public static UpdateManifestOperation WeaklyUpdateManifestAsync(int resourceVersion)
+ /// 指定的资源包裹名称
+ /// 指定的资源包裹版本
+ 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);
}
- ///
- /// 获取资源版本号
- ///
- 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();
- }
- }
-
///
/// 资源回收(卸载引用计数为零的资源)
///
@@ -985,9 +972,10 @@ namespace YooAsset
///
/// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件
///
- /// 指定更新的资源版本
+ /// 指定更新的资源包裹名称
+ /// 指定更新的资源包裹版本
/// 超时时间
- 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
{