diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs
index dfb004a..39bbd06 100644
--- a/Assets/YooAsset/Editor/EditorTools.cs
+++ b/Assets/YooAsset/Editor/EditorTools.cs
@@ -566,7 +566,7 @@ namespace YooAsset.Editor
public static string AbsolutePathToAssetPath(string absolutePath)
{
string content = GetRegularPath(absolutePath);
- return Substring(content, "Assets", true);
+ return Substring(content, "Assets/", true);
}
///
diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
index 1a229e6..fbc276d 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
@@ -126,6 +126,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
+ YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle();
}
@@ -164,6 +165,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
+ YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle();
}
@@ -188,6 +190,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
+ YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle();
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs
index 6738426..e6188eb 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs
@@ -25,6 +25,22 @@ namespace YooAsset
}
}
+ ///
+ /// 身份是否无效
+ ///
+ internal bool IsInvalid
+ {
+ get
+ {
+ return _patchAsset == null;
+ }
+ }
+
+ ///
+ /// 错误信息
+ ///
+ internal string Error { private set; get; }
+
///
/// 资源对象名称
///
@@ -40,23 +56,8 @@ namespace YooAsset
///
public System.Type AssetType { private set; get; }
- ///
- /// 身份是否无效
- ///
- public bool IsInvalid
- {
- get
- {
- return _patchAsset == null;
- }
- }
-
- ///
- /// 错误信息
- ///
- public string Error { private set; get; }
-
+ // 注意:这是一个内部类,严格限制外部创建。
private AssetInfo()
{
}
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
index a019e46..c384543 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs
@@ -63,8 +63,8 @@ namespace YooAsset
private readonly int _resourceVersion;
private readonly int _timeout;
private ESteps _steps = ESteps.None;
- private UnityWebDataRequester _downloaderHash;
- private UnityWebDataRequester _downloaderManifest;
+ private UnityWebDataRequester _downloader1;
+ private UnityWebDataRequester _downloader2;
private float _verifyTime;
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@@ -87,26 +87,26 @@ namespace YooAsset
{
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
- _downloaderHash = new UnityWebDataRequester();
- _downloaderHash.SendRequest(webURL, _timeout);
+ _downloader1 = new UnityWebDataRequester();
+ _downloader1.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifestHash;
}
if (_steps == ESteps.CheckWebManifestHash)
{
- if (_downloaderHash.IsDone() == false)
+ if (_downloader1.IsDone() == false)
return;
// Check error
- if (_downloaderHash.HasError())
+ if (_downloader1.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _downloaderHash.GetError();
+ Error = _downloader1.GetError();
}
else
{
- string webManifestHash = _downloaderHash.GetText();
+ string webManifestHash = _downloader1.GetText();
string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
// 如果补丁清单文件的哈希值相同
@@ -122,34 +122,34 @@ namespace YooAsset
_steps = ESteps.LoadWebManifest;
}
}
- _downloaderHash.Dispose();
+ _downloader1.Dispose();
}
if (_steps == ESteps.LoadWebManifest)
{
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
- _downloaderManifest = new UnityWebDataRequester();
- _downloaderManifest.SendRequest(webURL, _timeout);
+ _downloader2 = new UnityWebDataRequester();
+ _downloader2.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest;
}
if (_steps == ESteps.CheckWebManifest)
{
- if (_downloaderManifest.IsDone() == false)
+ if (_downloader2.IsDone() == false)
return;
// Check error
- if (_downloaderManifest.HasError())
+ if (_downloader2.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _downloaderManifest.GetError();
+ Error = _downloader2.GetError();
}
else
{
// 解析补丁清单
- if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloaderManifest.GetText()))
+ if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
{
_steps = ESteps.InitVerifyingCache;
}
@@ -157,10 +157,10 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid";
+ Error = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
}
}
- _downloaderManifest.Dispose();
+ _downloader2.Dispose();
}
if (_steps == ESteps.InitVerifyingCache)
@@ -207,18 +207,19 @@ namespace YooAsset
YooLogger.Log("Save remote patch manifest file.");
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
- PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
+ PatchManifest.Serialize(savePath, remotePatchManifest);
return true;
}
catch (Exception e)
{
- YooLogger.Warning(e.ToString());
+ YooLogger.Error(e.ToString());
return false;
}
}
///
/// 加载沙盒内的补丁清单
+ /// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
///
private void LoadSandboxPatchManifest(int updateResourceVersion)
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
index d8dda31..a3faccc 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdatePackageOperation.cs
@@ -81,7 +81,7 @@ namespace YooAsset
private readonly int _resourceVersion;
private readonly int _timeout;
private ESteps _steps = ESteps.None;
- private UnityWebDataRequester _downloaderManifest;
+ private UnityWebDataRequester _downloader;
private PatchManifest _remotePatchManifest;
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@@ -104,28 +104,28 @@ namespace YooAsset
{
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
- _downloaderManifest = new UnityWebDataRequester();
- _downloaderManifest.SendRequest(webURL, _timeout);
+ _downloader = new UnityWebDataRequester();
+ _downloader.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest;
}
if (_steps == ESteps.CheckWebManifest)
{
- Progress = _downloaderManifest.Progress();
- if (_downloaderManifest.IsDone() == false)
+ Progress = _downloader.Progress();
+ if (_downloader.IsDone() == false)
return;
// Check error
- if (_downloaderManifest.HasError())
+ if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _downloaderManifest.GetError();
+ Error = _downloader.GetError();
}
else
{
// 解析补丁清单
- if (ParseRemotePatchManifest(_downloaderManifest.GetText()))
+ if (ParseRemotePatchManifest(_downloader.GetText()))
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@@ -134,10 +134,10 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid";
+ Error = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
}
}
- _downloaderManifest.Dispose();
+ _downloader.Dispose();
}
}
@@ -209,8 +209,8 @@ namespace YooAsset
continue;
}
- // 注意:下载系统只会验证当前游戏版本的资源文件,对于其它游戏版本的差异文件不会在初始化的时候去做校验。
- // 注意:通过比对文件大小做实时的文件校验方式!
+ // 注意:通过比对文件大小做快速的文件校验!
+ // 注意:在初始化的时候会去做最终校验!
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
if (File.Exists(filePath))
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
index f7628ed..fce87cf 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
@@ -73,7 +73,7 @@ namespace YooAsset
if (EnableAddressable)
{
if (locationToLower)
- YooLogger.Warning("Addressable not support location to lower !");
+ YooLogger.Error("Addressable not support location to lower !");
foreach (var patchAsset in AssetList)
{
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index 467111a..2bf3c56 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -12,18 +12,23 @@ namespace YooAsset
internal PatchManifest LocalPatchManifest { private set; get; }
// 参数相关
- internal bool LocationToLower { private set; get; }
- internal bool ClearCacheWhenDirty { private set; get; }
+ 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)
{
- LocationToLower = locationToLower;
- ClearCacheWhenDirty = clearCacheWhenDirty;
+ _locationToLower = locationToLower;
+ _clearCacheWhenDirty = clearCacheWhenDirty;
_defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer;
@@ -293,7 +298,7 @@ namespace YooAsset
internal void SetLocalPatchManifest(PatchManifest patchManifest)
{
LocalPatchManifest = patchManifest;
- LocalPatchManifest.InitAssetPathMapping(LocationToLower);
+ LocalPatchManifest.InitAssetPathMapping(_locationToLower);
}
#region IBundleServices接口
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index ba085b9..30f5c11 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -33,7 +33,7 @@ namespace YooAsset
///
/// 初始化参数
///
- public abstract class CreateParameters
+ public abstract class InitializeParameters
{
///
/// 资源定位地址大小写不敏感
@@ -64,7 +64,7 @@ namespace YooAsset
///
/// 编辑器下模拟运行模式的初始化参数
///
- public class EditorSimulateModeParameters : CreateParameters
+ public class EditorSimulateModeParameters : InitializeParameters
{
///
/// 用于模拟运行的资源清单路径
@@ -76,14 +76,14 @@ namespace YooAsset
///
/// 离线运行模式的初始化参数
///
- public class OfflinePlayModeParameters : CreateParameters
+ public class OfflinePlayModeParameters : InitializeParameters
{
}
///
/// 网络运行模式的初始化参数
///
- public class HostPlayModeParameters : CreateParameters
+ public class HostPlayModeParameters : InitializeParameters
{
///
/// 当缓存池被污染的时候清理缓存池
@@ -121,7 +121,7 @@ namespace YooAsset
///
/// 异步初始化
///
- public static InitializationOperation InitializeAsync(CreateParameters parameters)
+ public static InitializationOperation InitializeAsync(InitializeParameters parameters)
{
if (parameters == null)
throw new Exception($"YooAsset create parameters is null.");
@@ -357,8 +357,31 @@ namespace YooAsset
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
if (assetInfo.IsInvalid)
+ {
+ YooLogger.Warning(assetInfo.Error);
return false;
-
+ }
+
+ BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
+ if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
+ return true;
+ else
+ return false;
+ }
+
+ ///
+ /// 是否需要从远端更新下载
+ ///
+ /// 资源的定位地址
+ public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
+ {
+ DebugCheckInitialize();
+ if (assetInfo.IsInvalid)
+ {
+ YooLogger.Warning(assetInfo.Error);
+ return false;
+ }
+
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
@@ -448,6 +471,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
+ YooLogger.Warning(assetInfo.Error);
RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
OperationSystem.StartOperaiton(operation);
return operation;