Update YooAssets

This commit is contained in:
hevinci
2022-03-07 21:20:58 +08:00
parent 050c962587
commit 33ad0713fe
20 changed files with 139 additions and 119 deletions
@@ -227,8 +227,8 @@ namespace YooAsset
internal static BundleFileLoader CreateOwnerBundleLoader(string assetPath)
{
string bundleName = BundleServices.GetAssetBundleName(assetPath);
AssetBundleInfo bundleInfo = BundleServices.GetAssetBundleInfo(bundleName);
string bundleName = BundleServices.GetBundleName(assetPath);
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
return CreateBundleFileLoaderInternal(bundleInfo);
}
internal static List<BundleFileLoader> CreateDependBundleLoaders(string assetPath)
@@ -239,7 +239,7 @@ namespace YooAsset
{
foreach (var dependBundleName in depends)
{
AssetBundleInfo dependBundleInfo = BundleServices.GetAssetBundleInfo(dependBundleName);
BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName);
BundleFileLoader dependLoader = CreateBundleFileLoaderInternal(dependBundleInfo);
result.Add(dependLoader);
}
@@ -254,7 +254,7 @@ namespace YooAsset
}
}
private static BundleFileLoader CreateBundleFileLoaderInternal(AssetBundleInfo bundleInfo)
private static BundleFileLoader CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
{
// 如果加载器已经存在
BundleFileLoader loader = TryGetBundleFileLoader(bundleInfo.BundleName);
@@ -272,7 +272,7 @@ namespace YooAsset
for (int i = 0; i < _loaders.Count; i++)
{
BundleFileLoader temp = _loaders[i];
if (temp.BundleInfo.BundleName.Equals(bundleName))
if (temp.BundleFileInfo.BundleName.Equals(bundleName))
{
loader = temp;
break;
@@ -304,7 +304,7 @@ namespace YooAsset
foreach (var provider in _providers)
{
DebugSummy.ProviderInfo providerInfo = new DebugSummy.ProviderInfo();
DebugSummy.DebugProviderInfo providerInfo = new DebugSummy.DebugProviderInfo();
providerInfo.AssetPath = provider.AssetPath;
providerInfo.RefCount = provider.RefCount;
providerInfo.States = provider.States;
@@ -1,7 +1,7 @@

namespace YooAsset
{
public class AssetBundleInfo
public class BundleInfo
{
private readonly PatchBundle _patchBundle;
@@ -110,10 +110,10 @@ namespace YooAsset
}
private AssetBundleInfo()
private BundleInfo()
{
}
internal AssetBundleInfo(PatchBundle patchBundle, string localPath, string mainURL, string fallbackURL)
internal BundleInfo(PatchBundle patchBundle, string localPath, string mainURL, string fallbackURL)
{
_patchBundle = patchBundle;
BundleName = patchBundle.BundleName;
@@ -121,7 +121,7 @@ namespace YooAsset
RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL;
}
internal AssetBundleInfo(PatchBundle patchBundle, string localPath)
internal BundleInfo(PatchBundle patchBundle, string localPath)
{
_patchBundle = patchBundle;
BundleName = patchBundle.BundleName;
@@ -129,7 +129,7 @@ namespace YooAsset
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
}
internal AssetBundleInfo(string bundleName, string localPath)
internal BundleInfo(string bundleName, string localPath)
{
_patchBundle = null;
BundleName = bundleName;
@@ -6,12 +6,12 @@ namespace YooAsset
/// <summary>
/// 获取AssetBundle的信息
/// </summary>
AssetBundleInfo GetAssetBundleInfo(string bundleName);
BundleInfo GetBundleInfo(string bundleName);
/// <summary>
/// 获取资源所属的资源包名称
/// </summary>
string GetAssetBundleName(string assetPath);
string GetBundleName(string assetPath);
/// <summary>
/// 获取资源依赖的所有AssetBundle列表
@@ -8,11 +8,11 @@ namespace YooAsset
/// <summary>
/// 获取解密的数据偏移
/// </summary>
ulong GetDecryptOffset(AssetBundleInfo bundleInfo);
ulong GetDecryptOffset(BundleInfo bundleInfo);
/// <summary>
/// 获取解密的字节数据
/// </summary>
byte[] GetDecryptBinary(AssetBundleInfo bundleInfo);
byte[] GetDecryptBinary(BundleInfo bundleInfo);
}
}
@@ -8,9 +8,9 @@ namespace YooAsset
internal class BundleFileLoader
{
/// <summary>
/// 资源文件信息
/// 资源包文件信息
/// </summary>
public AssetBundleInfo BundleInfo { private set; get; }
public BundleInfo BundleFileInfo { private set; get; }
/// <summary>
/// 引用计数
@@ -35,9 +35,9 @@ namespace YooAsset
internal AssetBundle CacheBundle { private set; get; }
public BundleFileLoader(AssetBundleInfo bundleInfo)
public BundleFileLoader(BundleInfo bundleInfo)
{
BundleInfo = bundleInfo;
BundleFileInfo = bundleInfo;
RefCount = 0;
States = ELoaderStates.None;
}
@@ -92,13 +92,13 @@ namespace YooAsset
if (States == ELoaderStates.None)
{
// 检测加载地址是否为空
if (string.IsNullOrEmpty(BundleInfo.LocalPath))
if (string.IsNullOrEmpty(BundleFileInfo.LocalPath))
{
States = ELoaderStates.Fail;
return;
}
if (string.IsNullOrEmpty(BundleInfo.RemoteMainURL))
if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL))
States = ELoaderStates.LoadFile;
else
States = ELoaderStates.Download;
@@ -108,7 +108,7 @@ namespace YooAsset
if (States == ELoaderStates.Download)
{
int failedTryAgain = int.MaxValue;
_fileDownloader = DownloadSystem.BeginDownload(BundleInfo, failedTryAgain);
_fileDownloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain);
States = ELoaderStates.CheckDownload;
}
@@ -134,32 +134,32 @@ namespace YooAsset
{
#if UNITY_EDITOR
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
if (System.IO.File.Exists(BundleInfo.LocalPath) == false)
if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
{
Logger.Warning($"Not found assetBundle file : {BundleInfo.LocalPath}");
Logger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
States = ELoaderStates.Fail;
return;
}
#endif
// Load assetBundle file
if (BundleInfo.IsEncrypted)
if (BundleFileInfo.IsEncrypted)
{
if (AssetSystem.DecryptServices == null)
throw new Exception($"{nameof(BundleFileLoader)} need IDecryptServices : {BundleInfo.BundleName}");
throw new Exception($"{nameof(BundleFileLoader)} need IDecryptServices : {BundleFileInfo.BundleName}");
EDecryptMethod decryptType = AssetSystem.DecryptServices.DecryptType;
if (decryptType == EDecryptMethod.GetDecryptOffset)
{
ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleInfo);
ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleFileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(BundleInfo.LocalPath, 0, offset);
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset);
else
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath, 0, offset);
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset);
}
else if (decryptType == EDecryptMethod.GetDecryptBinary)
{
byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleInfo);
byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleFileInfo);
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromMemory(binary);
else
@@ -173,9 +173,9 @@ namespace YooAsset
else
{
if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(BundleInfo.LocalPath);
CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath);
else
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath);
_cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath);
}
States = ELoaderStates.CheckFile;
}
@@ -202,7 +202,7 @@ namespace YooAsset
// Check error
if (CacheBundle == null)
{
Logger.Error($"Failed to load assetBundle file : {BundleInfo.BundleName}");
Logger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
States = ELoaderStates.Fail;
}
else
@@ -223,9 +223,9 @@ namespace YooAsset
if (forceDestroy == false)
{
if (RefCount > 0)
throw new Exception($"Bundle file loader ref is not zero : {BundleInfo.BundleName}");
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}");
if (IsDone() == false)
throw new Exception($"Bundle file loader is not done : {BundleInfo.BundleName}");
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}");
}
if (CacheBundle != null)
@@ -302,7 +302,7 @@ namespace YooAsset
if (_isShowWaitForAsyncError == false)
{
_isShowWaitForAsyncError = true;
Logger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleInfo.BundleName} States : {States}");
Logger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {States}");
}
break;
}
@@ -66,13 +66,13 @@ namespace YooAsset
/// <summary>
/// 获取资源包的调试信息列表
/// </summary>
internal void GetBundleDebugInfos(List<DebugSummy.BundleInfo> output)
internal void GetBundleDebugInfos(List<DebugSummy.DebugBundleInfo> output)
{
foreach (var loader in _dependBundles)
{
var debugInfo = new DebugSummy.BundleInfo();
debugInfo.BundleName = loader.BundleInfo.BundleName;
debugInfo.Version = loader.BundleInfo.Version;
var debugInfo = new DebugSummy.DebugBundleInfo();
debugInfo.BundleName = loader.BundleFileInfo.BundleName;
debugInfo.Version = loader.BundleFileInfo.Version;
debugInfo.RefCount = loader.RefCount;
debugInfo.States = loader.States;
output.Add(debugInfo);
@@ -97,7 +97,7 @@ namespace YooAsset
States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleInfo.BundleName}");
Logger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion();
}
}
@@ -36,11 +36,11 @@ namespace YooAsset
/// <summary>
/// 获取资源包的调试信息列表
/// </summary>
internal void GetBundleDebugInfos(List<DebugSummy.BundleInfo> output)
internal void GetBundleDebugInfos(List<DebugSummy.DebugBundleInfo> output)
{
var ownerInfo = new DebugSummy.BundleInfo();
ownerInfo.BundleName = OwnerBundle.BundleInfo.BundleName;
ownerInfo.Version = OwnerBundle.BundleInfo.Version;
var ownerInfo = new DebugSummy.DebugBundleInfo();
ownerInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
ownerInfo.Version = OwnerBundle.BundleFileInfo.Version;
ownerInfo.RefCount = OwnerBundle.RefCount;
ownerInfo.States = OwnerBundle.States;
output.Add(ownerInfo);
@@ -97,7 +97,7 @@ namespace YooAsset
States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleInfo.BundleName}");
Logger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion();
}
}