Update YooAsset

pull/4/head
hevinci 2022-03-09 23:57:04 +08:00
parent 1c7b90806c
commit a00924bb54
39 changed files with 283 additions and 369 deletions

View File

@ -20,7 +20,7 @@ namespace YooAsset
/// </summary>
public static int AssetLoadingMaxNumber { private set; get; }
public static IDecryptServices DecryptServices { private set; get; }
public static IDecryptionServices DecryptionServices { private set; get; }
public static IBundleServices BundleServices { private set; get; }
@ -28,11 +28,11 @@ namespace YooAsset
/// 初始化资源系统
/// 注意在使用AssetSystem之前需要初始化
/// </summary>
public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptServices decryptServices, IBundleServices bundleServices)
public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
{
SimulationOnEditor = simulationOnEditor;
AssetLoadingMaxNumber = assetLoadingMaxNumber;
DecryptServices = decryptServices;
DecryptionServices = decryptionServices;
BundleServices = bundleServices;
}
@ -307,7 +307,7 @@ namespace YooAsset
DebugSummy.DebugProviderInfo providerInfo = new DebugSummy.DebugProviderInfo();
providerInfo.AssetPath = provider.AssetPath;
providerInfo.RefCount = provider.RefCount;
providerInfo.States = (int)provider.States;
providerInfo.Status = (int)provider.Status;
providerInfo.BundleInfos.Clear();
summy.ProviderInfos.Add(providerInfo);

View File

@ -1,19 +0,0 @@

namespace YooAsset
{
/// <summary>
/// 解密方法
/// </summary>
public enum EDecryptMethod
{
/// <summary>
/// 获取解密的数据偏移
/// </summary>
GetDecryptOffset,
/// <summary>
/// 获取解密的字节数据
/// </summary>
GetDecryptBinary,
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 6a446add12cd4554a9bd178a7ef2db55
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,18 +0,0 @@

namespace YooAsset
{
public interface IDecryptServices
{
EDecryptMethod DecryptType { get; }
/// <summary>
/// 获取解密的数据偏移
/// </summary>
ulong GetDecryptOffset(BundleInfo bundleInfo);
/// <summary>
/// 获取解密的字节数据
/// </summary>
byte[] GetDecryptBinary(BundleInfo bundleInfo);
}
}

View File

@ -0,0 +1,11 @@

namespace YooAsset
{
public interface IDecryptionServices
{
/// <summary>
/// 获取加密文件的数据偏移量
/// </summary>
ulong GetFileOffset(BundleInfo bundleInfo);
}
}

View File

@ -7,6 +7,17 @@ namespace YooAsset
{
internal class BundleFileLoader
{
public enum EStatus
{
None = 0,
Download,
CheckDownload,
LoadFile,
CheckFile,
Success,
Fail,
}
/// <summary>
/// 资源包文件信息
/// </summary>
@ -20,7 +31,7 @@ namespace YooAsset
/// <summary>
/// 加载状态
/// </summary>
public ELoaderStates States { private set; get; }
public EStatus Status { private set; get; }
/// <summary>
/// 是否已经销毁
@ -39,7 +50,7 @@ namespace YooAsset
{
BundleFileInfo = bundleInfo;
RefCount = 0;
States = ELoaderStates.None;
Status = EStatus.None;
}
/// <summary>
@ -89,31 +100,31 @@ namespace YooAsset
if (IsDone())
return;
if (States == ELoaderStates.None)
if (Status == EStatus.None)
{
// 检测加载地址是否为空
if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
{
States = ELoaderStates.Fail;
Status = EStatus.Fail;
return;
}
if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
States = ELoaderStates.LoadFile;
Status = EStatus.LoadFile;
else
States = ELoaderStates.Download;
Status = EStatus.Download;
}
// 1. 从服务器下载
if (States == ELoaderStates.Download)
if (Status == EStatus.Download)
{
int failedTryAgain = int.MaxValue;
_fileDownloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain);
States = ELoaderStates.CheckDownload;
Status = EStatus.CheckDownload;
}
// 2. 检测服务器下载结果
if (States == ELoaderStates.CheckDownload)
if (Status == EStatus.CheckDownload)
{
if (_fileDownloader.IsDone() == false)
return;
@ -121,23 +132,23 @@ namespace YooAsset
if (_fileDownloader.HasError())
{
_fileDownloader.ReportError();
States = ELoaderStates.Fail;
Status = EStatus.Fail;
}
else
{
States = ELoaderStates.LoadFile;
Status = EStatus.LoadFile;
}
}
// 3. 加载AssetBundle
if (States == ELoaderStates.LoadFile)
if (Status == EStatus.LoadFile)
{
#if UNITY_EDITOR
// 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。
if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
{
YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
States = ELoaderStates.Fail;
Status = EStatus.Fail;
return;
}
#endif
@ -145,31 +156,15 @@ namespace YooAsset
// Load assetBundle file
if (BundleFileInfo.IsEncrypted)
{
if (AssetSystem.DecryptServices == null)
if (AssetSystem.DecryptionServices == null)
throw new Exception($"{nameof(BundleFileLoader)} need IDecryptServices : {BundleFileInfo.BundleName}");
EDecryptMethod decryptType = AssetSystem.DecryptServices.DecryptType;
if (decryptType == EDecryptMethod.GetDecryptOffset)
{
ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleFileInfo);
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset);
else
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset);
}
else if (decryptType == EDecryptMethod.GetDecryptBinary)
{
byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleFileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromMemory(binary);
else
_cacheRequest = AssetBundle.LoadFromMemoryAsync(binary);
}
else
{
throw new NotImplementedException($"{decryptType}");
}
}
else
{
if (_isWaitForAsyncComplete)
@ -177,11 +172,11 @@ namespace YooAsset
else
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath);
}
States = ELoaderStates.CheckFile;
Status = EStatus.CheckFile;
}
// 4. 检测AssetBundle加载结果
if (States == ELoaderStates.CheckFile)
if (Status == EStatus.CheckFile)
{
if (_cacheRequest != null)
{
@ -203,11 +198,11 @@ namespace YooAsset
if (CacheBundle == null)
{
YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
States = ELoaderStates.Fail;
Status = EStatus.Fail;
}
else
{
States = ELoaderStates.Success;
Status = EStatus.Success;
}
}
}
@ -240,7 +235,7 @@ namespace YooAsset
/// </summary>
public bool IsDone()
{
return States == ELoaderStates.Success || States == ELoaderStates.Fail;
return Status == EStatus.Success || Status == EStatus.Fail;
}
/// <summary>
@ -302,7 +297,7 @@ namespace YooAsset
if (_isShowWaitForAsyncError == false)
{
_isShowWaitForAsyncError = true;
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {States}");
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}");
}
break;
}

View File

@ -74,7 +74,7 @@ namespace YooAsset
debugInfo.BundleName = loader.BundleFileInfo.BundleName;
debugInfo.Version = loader.BundleFileInfo.Version;
debugInfo.RefCount = loader.RefCount;
debugInfo.States = (int)loader.States;
debugInfo.Status = (int)loader.Status;
output.Add(debugInfo);
}
}

View File

@ -1,17 +0,0 @@

namespace YooAsset
{
/// <summary>
/// 文件加载器状态
/// </summary>
public enum ELoaderStates
{
None = 0,
Download,
CheckDownload,
LoadFile,
CheckFile,
Success,
Fail,
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 90f00fe388279034aaee9c89c07e2ef1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fcfac83df022948478c32bf11b8e0987
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -24,15 +24,20 @@ namespace YooAsset
}
/// <summary>
/// 当前的加载状态
/// 当前状态
/// </summary>
public EAssetStates States
public EOperationStatus Status
{
get
{
if (IsValid == false)
return EAssetStates.None;
return _provider.States;
return EOperationStatus.None;
if (_provider.Status == AssetProviderBase.EStatus.Fail)
return EOperationStatus.Failed;
else if (_provider.Status == AssetProviderBase.EStatus.Success)
return EOperationStatus.Succeed;
else
return EOperationStatus.None;
}
}

View File

@ -3,6 +3,16 @@ namespace YooAsset
{
internal abstract class AssetProviderBase : IAssetProvider
{
public enum EStatus
{
None = 0,
CheckBundle,
Loading,
Checking,
Success,
Fail,
}
protected bool IsWaitForAsyncComplete { private set; get; } = false;
public string AssetPath { private set; get; }
@ -11,7 +21,7 @@ namespace YooAsset
public UnityEngine.Object AssetObject { protected set; get; }
public UnityEngine.Object[] AllAssets { protected set; get; }
public IAssetInstance AssetInstance { protected set; get; }
public EAssetStates States { protected set; get; }
public EStatus Status { protected set; get; }
public int RefCount { private set; get; }
public AssetOperationHandle Handle { private set; get; }
public System.Action<AssetOperationHandle> Callback { set; get; }
@ -20,7 +30,7 @@ namespace YooAsset
{
get
{
return States == EAssetStates.Success || States == EAssetStates.Fail;
return Status == EStatus.Success || Status == EStatus.Fail;
}
}
public bool IsValid
@ -44,7 +54,7 @@ namespace YooAsset
AssetPath = assetPath;
AssetName = System.IO.Path.GetFileName(assetPath);
AssetType = assetType;
States = EAssetStates.None;
Status = EStatus.None;
Handle = new AssetOperationHandle(this);
}

View File

@ -26,13 +26,13 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
States = EAssetStates.CheckBundle;
Status = EStatus.CheckBundle;
}
// 1. 检测资源包
if (States == EAssetStates.CheckBundle)
if (Status == EStatus.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@ -47,17 +47,17 @@ namespace YooAsset
if (OwnerBundle.CacheBundle == null)
{
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
}
else
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
}
// 2. 加载资源对象
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
if (IsWaitForAsyncComplete)
{
@ -73,11 +73,11 @@ namespace YooAsset
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType);
}
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
// 3. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
if (_cacheRequest != null)
{
@ -95,8 +95,8 @@ namespace YooAsset
}
}
States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
YooLogger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion();
}

View File

@ -42,7 +42,7 @@ namespace YooAsset
ownerInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
ownerInfo.Version = OwnerBundle.BundleFileInfo.Version;
ownerInfo.RefCount = OwnerBundle.RefCount;
ownerInfo.States = (int)OwnerBundle.States;
ownerInfo.Status = (int)OwnerBundle.Status;
output.Add(ownerInfo);
DependBundles.GetBundleDebugInfos(output);

View File

@ -29,13 +29,13 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
States = EAssetStates.CheckBundle;
Status = EStatus.CheckBundle;
}
// 1. 检测资源包
if (States == EAssetStates.CheckBundle)
if (Status == EStatus.CheckBundle)
{
if (DependBundles.IsDone() == false)
return;
@ -44,34 +44,34 @@ namespace YooAsset
if (OwnerBundle.CacheBundle == null)
{
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
}
else
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
}
// 2. 加载场景
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
_asyncOp = SceneManager.LoadSceneAsync(AssetName, _param.LoadMode);
if (_asyncOp != null)
{
_asyncOp.allowSceneActivation = true;
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
else
{
YooLogger.Warning($"Failed to load scene : {AssetName}");
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
}
}
// 3. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
if (_asyncOp.isDone)
{
@ -81,7 +81,7 @@ namespace YooAsset
if (_param.ActivateOnLoad)
instance.Activate();
States = instance.Scene.IsValid() ? EAssetStates.Success : EAssetStates.Fail;
Status = instance.Scene.IsValid() ? EStatus.Success : EStatus.Fail;
InvokeCompletion();
}
}

View File

@ -26,13 +26,13 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
States = EAssetStates.CheckBundle;
Status = EStatus.CheckBundle;
}
// 1. 检测资源包
if (States == EAssetStates.CheckBundle)
if (Status == EStatus.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@ -47,17 +47,17 @@ namespace YooAsset
if (OwnerBundle.CacheBundle == null)
{
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
}
else
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
}
// 2. 加载资源对象
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
if (IsWaitForAsyncComplete)
{
@ -73,11 +73,11 @@ namespace YooAsset
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType);
}
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
// 3. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
if (_cacheRequest != null)
{
@ -95,8 +95,8 @@ namespace YooAsset
}
}
States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Status = AllAssets == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
YooLogger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion();
}

View File

@ -27,19 +27,19 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
if (string.IsNullOrEmpty(guid))
{
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
return;
}
else
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
// 注意:模拟异步加载效果提前返回
@ -48,17 +48,17 @@ namespace YooAsset
}
// 1. 加载资源对象
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType);
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
// 2. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
YooLogger.Warning($"Failed to load asset object : {AssetPath}");
InvokeCompletion();
}

View File

@ -28,13 +28,13 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
// 1. 加载资源对象
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
loadSceneParameters.loadSceneMode = _param.LoadMode;
@ -42,18 +42,18 @@ namespace YooAsset
if (_asyncOp != null)
{
_asyncOp.allowSceneActivation = true;
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
else
{
YooLogger.Warning($"Failed to load scene : {AssetName}");
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
}
}
// 2. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
if (_asyncOp.isDone)
{
@ -63,7 +63,7 @@ namespace YooAsset
if(_param.ActivateOnLoad)
instance.Activate();
States = instance.Scene.IsValid() ? EAssetStates.Success : EAssetStates.Fail;
Status = instance.Scene.IsValid() ? EStatus.Success : EStatus.Fail;
InvokeCompletion();
}
}

View File

@ -27,19 +27,19 @@ namespace YooAsset
if (IsDone)
return;
if (States == EAssetStates.None)
if (Status == EStatus.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
if (string.IsNullOrEmpty(guid))
{
States = EAssetStates.Fail;
Status = EStatus.Fail;
InvokeCompletion();
return;
}
else
{
States = EAssetStates.Loading;
Status = EStatus.Loading;
}
// 注意:模拟异步加载效果提前返回
@ -48,7 +48,7 @@ namespace YooAsset
}
// 1. 加载资源对象
if (States == EAssetStates.Loading)
if (Status == EStatus.Loading)
{
var findAssets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(AssetPath);
List<UnityEngine.Object> result = new List<Object>(findAssets.Length);
@ -58,14 +58,14 @@ namespace YooAsset
result.Add(findObj);
}
AllAssets = result.ToArray();
States = EAssetStates.Checking;
Status = EStatus.Checking;
}
// 2. 检测加载结果
if (States == EAssetStates.Checking)
if (Status == EStatus.Checking)
{
States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Status = AllAssets == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
YooLogger.Warning($"Failed to load all asset object : {AssetPath}");
InvokeCompletion();
}

View File

@ -1,16 +0,0 @@

namespace YooAsset
{
/// <summary>
/// 资源加载状态
/// </summary>
public enum EAssetStates
{
None = 0,
CheckBundle,
Loading,
Checking,
Success,
Fail,
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: aa6c0fe63326c604bb699be16747c1e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -39,7 +39,7 @@ namespace YooAsset
/// <summary>
/// 当前的加载状态
/// </summary>
EAssetStates States { get; }
AssetProviderBase.EStatus Status { get; }
/// <summary>
/// 引用计数

View File

@ -6,6 +6,9 @@ namespace YooAsset
{
public abstract class AsyncOperationBase : IEnumerator
{
// 用户请求的回调
private Action<AsyncOperationBase> _callback;
/// <summary>
/// 状态
/// </summary>
@ -27,11 +30,6 @@ namespace YooAsset
}
}
/// <summary>
/// 用户请求的回调
/// </summary>
private Action<AsyncOperationBase> _callback;
/// <summary>
/// 完成事件
/// </summary>

View File

@ -86,7 +86,7 @@ namespace YooAsset
{
if (_cachedHashList.ContainsKey(hash))
{
string filePath = PatchHelper.MakeSandboxCacheFilePath(hash);
string filePath = SandboxHelper.MakeSandboxCacheFilePath(hash);
if (File.Exists(filePath))
{
return true;
@ -124,7 +124,7 @@ namespace YooAsset
}
public static bool CheckContentIntegrity(PatchBundle patchBundle)
{
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
return CheckContentIntegrity(filePath, patchBundle.SizeBytes, patchBundle.CRC);
}
public static bool CheckContentIntegrity(string filePath, long size, string crc)

View File

@ -59,8 +59,8 @@ namespace YooAsset
if (_steps == ESteps.LoadAppManifest)
{
string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
_downloadURL = AssetPathHelper.ConvertToWWWPath(filePath);
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebRequester();
_downloader.SendRequest(_downloadURL);
_steps = ESteps.CheckAppManifest;
@ -134,11 +134,11 @@ namespace YooAsset
if (_impl.ClearCacheWhenDirty)
{
YooLogger.Warning("Clear cache files.");
PatchHelper.DeleteSandboxCacheFolder();
SandboxHelper.DeleteSandboxCacheFolder();
}
// 删除清单文件
PatchHelper.DeleteSandboxPatchManifestFile();
SandboxHelper.DeleteSandboxPatchManifestFile();
// 更新缓存文件
PatchCache.UpdateCache();
}
@ -149,8 +149,8 @@ namespace YooAsset
{
// 加载APP内的补丁清单
YooLogger.Log($"Load application patch manifest.");
string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
_downloadURL = AssetPathHelper.ConvertToWWWPath(filePath);
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebRequester();
_downloader.SendRequest(_downloadURL);
_steps = ESteps.CheckAppManifest;
@ -181,10 +181,10 @@ namespace YooAsset
if (_steps == ESteps.LoadSandboxManifest)
{
// 加载沙盒内的补丁清单
if (PatchHelper.CheckSandboxPatchManifestFileExist())
if (SandboxHelper.CheckSandboxPatchManifestFileExist())
{
YooLogger.Log($"Load sandbox patch manifest.");
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
string jsonData = File.ReadAllText(filePath);
_impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData);
}

View File

@ -122,7 +122,7 @@ namespace YooAsset
_downloaderHash.Dispose();
// 如果补丁清单文件的哈希值相同
string currentFileHash = PatchHelper.GetSandboxPatchManifestFileHash();
string currentFileHash = SandboxHelper.GetSandboxPatchManifestFileHash();
if (currentFileHash == webManifestHash)
{
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
@ -206,7 +206,7 @@ namespace YooAsset
// 注意:这里会覆盖掉沙盒内的补丁清单文件
YooLogger.Log("Save remote patch manifest file.");
string savePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
string savePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
}
@ -246,7 +246,7 @@ namespace YooAsset
}
// 查看文件是否存在
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
if (File.Exists(filePath) == false)
continue;
@ -285,7 +285,7 @@ namespace YooAsset
}
private bool RunThread(PatchBundle patchBundle)
{
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
ThreadInfo info = new ThreadInfo(filePath, patchBundle);
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyFile), info);
}

View File

@ -19,10 +19,10 @@ namespace YooAsset
/// </summary>
public static PatchCache LoadCache()
{
if (PatchHelper.CheckSandboxCacheFileExist())
if (SandboxHelper.CheckSandboxCacheFileExist())
{
YooLogger.Log("Load patch cache from disk.");
string filePath = PatchHelper.GetSandboxCacheFilePath();
string filePath = SandboxHelper.GetSandboxCacheFilePath();
string jsonData = FileUtility.ReadFile(filePath);
return JsonUtility.FromJson<PatchCache>(jsonData);
}
@ -31,7 +31,7 @@ namespace YooAsset
YooLogger.Log($"Create patch cache to disk : {Application.version}");
PatchCache cache = new PatchCache();
cache.CacheAppVersion = Application.version;
string filePath = PatchHelper.GetSandboxCacheFilePath();
string filePath = SandboxHelper.GetSandboxCacheFilePath();
string jsonData = JsonUtility.ToJson(cache);
FileUtility.CreateFile(filePath, jsonData);
return cache;
@ -46,7 +46,7 @@ namespace YooAsset
YooLogger.Log($"Update patch cache to disk : {Application.version}");
PatchCache cache = new PatchCache();
cache.CacheAppVersion = Application.version;
string filePath = PatchHelper.GetSandboxCacheFilePath();
string filePath = SandboxHelper.GetSandboxCacheFilePath();
string jsonData = JsonUtility.ToJson(cache);
FileUtility.CreateFile(filePath, jsonData);
}

View File

@ -1,100 +0,0 @@
using System.IO;
using System.Text;
namespace YooAsset
{
internal static class PatchHelper
{
private const string StrCacheFileName = "Cache.bytes";
private const string StrCacheFolderName = "CacheFiles";
/// <summary>
/// 清空沙盒目录
/// </summary>
public static void ClearSandbox()
{
string directoryPath = AssetPathHelper.MakePersistentLoadPath(string.Empty);
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 删除沙盒内补丁清单文件
/// </summary>
public static void DeleteSandboxPatchManifestFile()
{
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
if (File.Exists(filePath))
File.Delete(filePath);
}
/// <summary>
/// 删除沙盒内的缓存文件
/// </summary>
public static void DeleteSandboxCacheFile()
{
string filePath = GetSandboxCacheFilePath();
if (File.Exists(filePath))
File.Delete(filePath);
}
/// <summary>
/// 删除沙盒内的缓存文件夹
/// </summary>
public static void DeleteSandboxCacheFolder()
{
string directoryPath = AssetPathHelper.MakePersistentLoadPath(StrCacheFolderName);
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 获取沙盒内缓存文件的路径
/// </summary>
public static string GetSandboxCacheFilePath()
{
return AssetPathHelper.MakePersistentLoadPath(StrCacheFileName);
}
/// <summary>
/// 检测沙盒内缓存文件是否存在
/// </summary>
public static bool CheckSandboxCacheFileExist()
{
string filePath = GetSandboxCacheFilePath();
return File.Exists(filePath);
}
/// <summary>
/// 检测沙盒内补丁清单文件是否存在
/// </summary>
public static bool CheckSandboxPatchManifestFileExist()
{
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
return File.Exists(filePath);
}
/// <summary>
/// 获取沙盒内补丁清单文件的哈希值
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
/// </summary>
/// <returns></returns>
public static string GetSandboxPatchManifestFileHash()
{
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
if (File.Exists(filePath))
return HashUtility.FileMD5(filePath);
else
return string.Empty;
}
/// <summary>
/// 获取缓存文件的存储路径
/// </summary>
public static string MakeSandboxCacheFilePath(string fileName)
{
return AssetPathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}");
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 887179b2bb92ca04988d1091b3b8f8e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -170,7 +170,7 @@ namespace YooAsset
foreach (var patchBundle in AppPatchManifest.BundleList)
{
// 如果已经在沙盒内
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
if (System.IO.File.Exists(filePath))
continue;
@ -216,7 +216,7 @@ namespace YooAsset
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{
// 注意:资源版本号只用于确定下载路径
string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash);
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL);
@ -236,8 +236,8 @@ namespace YooAsset
// 解压相关
private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string streamingLoadPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash);
string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath);
return bundleInfo;
}
@ -265,7 +265,7 @@ namespace YooAsset
{
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
{
string appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
string appLoadPath = PathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, appLoadPath);
return bundleInfo;
}
@ -274,7 +274,7 @@ namespace YooAsset
// 查询沙盒资源
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
{
string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string sandboxLoadPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxLoadPath);
return bundleInfo;
}

View File

@ -36,7 +36,7 @@ namespace YooAsset
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{
string localPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash);
string localPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
BundleInfo bundleInfo = new BundleInfo(patchBundle, localPath);
return bundleInfo;
}

View File

@ -29,7 +29,7 @@ namespace YooAsset
/// <summary>
/// 加载状态
/// </summary>
public int States { set; get; }
public int Status { set; get; }
}
/// <summary>
@ -50,7 +50,7 @@ namespace YooAsset
/// <summary>
/// 加载状态
/// </summary>
public int States { set; get; }
public int Status { set; get; }
/// <summary>
/// 依赖的资源包列表

View File

@ -3,7 +3,7 @@
namespace YooAsset
{
[CreateAssetMenu(fileName = "YooAssetSettings", menuName = "YooAsset/Create Settings")]
public class YooAssetSettings : ScriptableObject
internal class YooAssetSettings : ScriptableObject
{
/// <summary>
/// AssetBundle文件的后缀名

View File

@ -2,7 +2,7 @@
namespace YooAsset
{
public static class ResourceSettingData
internal static class ResourceSettingData
{
private static YooAssetSettings _setting = null;
public static YooAssetSettings Setting

View File

@ -2,7 +2,10 @@
namespace YooAsset
{
internal static class AssetPathHelper
/// <summary>
/// 资源路径帮助类
/// </summary>
internal static class PathHelper
{
/// <summary>
/// 获取规范化的路径
@ -72,7 +75,7 @@ namespace YooAsset
/// <summary>
/// 合并资源路径
/// </summary>
internal static string CombineAssetPath(string root, string location)
public static string CombineAssetPath(string root, string location)
{
if (string.IsNullOrEmpty(root))
return location;
@ -83,7 +86,7 @@ namespace YooAsset
/// <summary>
/// 获取AssetDatabase的加载路径
/// </summary>
internal static string FindDatabaseAssetPath(string filePath)
public static string FindDatabaseAssetPath(string filePath)
{
#if UNITY_EDITOR
if (File.Exists(filePath))
@ -119,4 +122,102 @@ namespace YooAsset
#endif
}
}
/// <summary>
/// 沙盒帮助类
/// </summary>
internal static class SandboxHelper
{
private const string StrCacheFileName = "Cache.bytes";
private const string StrCacheFolderName = "CacheFiles";
/// <summary>
/// 清空沙盒目录
/// </summary>
public static void ClearSandbox()
{
string directoryPath = PathHelper.MakePersistentLoadPath(string.Empty);
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 删除沙盒内补丁清单文件
/// </summary>
public static void DeleteSandboxPatchManifestFile()
{
string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
if (File.Exists(filePath))
File.Delete(filePath);
}
/// <summary>
/// 删除沙盒内的缓存文件
/// </summary>
public static void DeleteSandboxCacheFile()
{
string filePath = GetSandboxCacheFilePath();
if (File.Exists(filePath))
File.Delete(filePath);
}
/// <summary>
/// 删除沙盒内的缓存文件夹
/// </summary>
public static void DeleteSandboxCacheFolder()
{
string directoryPath = PathHelper.MakePersistentLoadPath(StrCacheFolderName);
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 获取沙盒内缓存文件的路径
/// </summary>
public static string GetSandboxCacheFilePath()
{
return PathHelper.MakePersistentLoadPath(StrCacheFileName);
}
/// <summary>
/// 检测沙盒内缓存文件是否存在
/// </summary>
public static bool CheckSandboxCacheFileExist()
{
string filePath = GetSandboxCacheFilePath();
return File.Exists(filePath);
}
/// <summary>
/// 检测沙盒内补丁清单文件是否存在
/// </summary>
public static bool CheckSandboxPatchManifestFileExist()
{
string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
return File.Exists(filePath);
}
/// <summary>
/// 获取沙盒内补丁清单文件的哈希值
/// 注意:如果沙盒内补丁清单文件不存在,返回空字符串
/// </summary>
/// <returns></returns>
public static string GetSandboxPatchManifestFileHash()
{
string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
if (File.Exists(filePath))
return HashUtility.FileMD5(filePath);
else
return string.Empty;
}
/// <summary>
/// 获取缓存文件的存储路径
/// </summary>
public static string MakeSandboxCacheFilePath(string fileName)
{
return PathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}");
}
}
}

View File

@ -38,7 +38,7 @@ namespace YooAsset
/// <summary>
/// 文件解密接口
/// </summary>
public IDecryptServices DecryptServices = null;
public IDecryptionServices DecryptionServices = null;
/// <summary>
/// 资源系统自动释放零引用资源的间隔秒数
@ -145,7 +145,7 @@ namespace YooAsset
}
if (string.IsNullOrEmpty(parameters.LocationRoot) == false)
_locationRoot = AssetPathHelper.GetRegularPath(parameters.LocationRoot);
_locationRoot = PathHelper.GetRegularPath(parameters.LocationRoot);
// 运行模式
if (parameters is EditorPlayModeParameters)
@ -162,21 +162,21 @@ namespace YooAsset
{
_editorPlayModeImpl = new EditorPlayModeImpl();
_bundleServices = _editorPlayModeImpl;
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices);
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
return _editorPlayModeImpl.InitializeAsync();
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
_offlinePlayModeImpl = new OfflinePlayModeImpl();
_bundleServices = _offlinePlayModeImpl;
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices);
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
return _offlinePlayModeImpl.InitializeAsync();
}
else if (_playMode == EPlayMode.HostPlayMode)
{
_hostPlayModeImpl = new HostPlayModeImpl();
_bundleServices = _hostPlayModeImpl;
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices);
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
var hostPlayModeParameters = parameters as HostPlayModeParameters;
return _hostPlayModeImpl.InitializeAsync(
hostPlayModeParameters.ClearCacheWhenDirty,
@ -508,7 +508,7 @@ namespace YooAsset
public static void ClearSandbox()
{
YooLogger.Warning("Clear sandbox.");
PatchHelper.ClearSandbox();
SandboxHelper.ClearSandbox();
}
/// <summary>
@ -516,7 +516,7 @@ namespace YooAsset
/// </summary>
public static string GetSandboxRoot()
{
return AssetPathHelper.MakePersistentRootPath();
return PathHelper.MakePersistentRootPath();
}
#endregion
@ -554,12 +554,12 @@ namespace YooAsset
{
if (_playMode == EPlayMode.EditorPlayMode)
{
string filePath = AssetPathHelper.CombineAssetPath(_locationRoot, location);
return AssetPathHelper.FindDatabaseAssetPath(filePath);
string filePath = PathHelper.CombineAssetPath(_locationRoot, location);
return PathHelper.FindDatabaseAssetPath(filePath);
}
else
{
return AssetPathHelper.CombineAssetPath(_locationRoot, location);
return PathHelper.CombineAssetPath(_locationRoot, location);
}
}
#endregion