Add warning when asset path is invalid.

pull/11/head
hevinci 2022-05-12 23:13:21 +08:00
parent 2da81212b4
commit 09fac3bd64
8 changed files with 94 additions and 60 deletions

View File

@ -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);
}
/// <summary>

View File

@ -126,6 +126,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SceneOperationHandle>();
}
@ -164,6 +165,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<AssetOperationHandle>();
}
@ -188,6 +190,7 @@ namespace YooAsset
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
}

View File

@ -25,6 +25,22 @@ namespace YooAsset
}
}
/// <summary>
/// 身份是否无效
/// </summary>
internal bool IsInvalid
{
get
{
return _patchAsset == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
internal string Error { private set; get; }
/// <summary>
/// 资源对象名称
/// </summary>
@ -40,23 +56,8 @@ namespace YooAsset
/// </summary>
public System.Type AssetType { private set; get; }
/// <summary>
/// 身份是否无效
/// </summary>
public bool IsInvalid
{
get
{
return _patchAsset == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
public string Error { private set; get; }
// 注意:这是一个内部类,严格限制外部创建。
private AssetInfo()
{
}

View File

@ -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;
}
}
/// <summary>
/// 加载沙盒内的补丁清单
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
/// </summary>
private void LoadSandboxPatchManifest(int updateResourceVersion)
{

View File

@ -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))
{

View File

@ -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)
{

View File

@ -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; }
}
/// <summary>
/// 异步初始化
/// </summary>
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接口

View File

@ -33,7 +33,7 @@ namespace YooAsset
/// <summary>
/// 初始化参数
/// </summary>
public abstract class CreateParameters
public abstract class InitializeParameters
{
/// <summary>
/// 资源定位地址大小写不敏感
@ -64,7 +64,7 @@ namespace YooAsset
/// <summary>
/// 编辑器下模拟运行模式的初始化参数
/// </summary>
public class EditorSimulateModeParameters : CreateParameters
public class EditorSimulateModeParameters : InitializeParameters
{
/// <summary>
/// 用于模拟运行的资源清单路径
@ -76,14 +76,14 @@ namespace YooAsset
/// <summary>
/// 离线运行模式的初始化参数
/// </summary>
public class OfflinePlayModeParameters : CreateParameters
public class OfflinePlayModeParameters : InitializeParameters
{
}
/// <summary>
/// 网络运行模式的初始化参数
/// </summary>
public class HostPlayModeParameters : CreateParameters
public class HostPlayModeParameters : InitializeParameters
{
/// <summary>
/// 当缓存池被污染的时候清理缓存池
@ -121,7 +121,7 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public static InitializationOperation InitializeAsync(CreateParameters parameters)
public static InitializationOperation InitializeAsync(InitializeParameters parameters)
{
if (parameters == null)
throw new Exception($"YooAsset create parameters is null.");
@ -357,7 +357,30 @@ 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;
}
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
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)
@ -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;