mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新YooAsset 2.3.3 -> 2.3.7 优化YooAsset.RuntimeExtension以及YooAsset.EditorExtension目录结构
更新YooAsset 2.3.3 -> 2.3.7 优化YooAsset.RuntimeExtension以及YooAsset.EditorExtension目录结构
This commit is contained in:
@@ -3,6 +3,16 @@ namespace YooAsset
|
||||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
internal enum ELoadMethod
|
||||
{
|
||||
None = 0,
|
||||
LoadAsset,
|
||||
LoadSubAssets,
|
||||
LoadAllAssets,
|
||||
LoadScene,
|
||||
LoadRawFile,
|
||||
}
|
||||
|
||||
private readonly PackageAsset _packageAsset;
|
||||
private string _providerGUID;
|
||||
|
||||
@@ -21,6 +31,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载方法
|
||||
/// </summary>
|
||||
internal ELoadMethod LoadMethod;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
|
@@ -38,9 +38,9 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
|
||||
{
|
||||
DownloadParam downloadParam = new DownloadParam(failedTryAgain, timeout);
|
||||
downloadParam.ImportFilePath = _importFilePath;
|
||||
return _fileSystem.DownloadFileAsync(Bundle, downloadParam);
|
||||
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain, timeout);
|
||||
options.ImportFilePath = _importFilePath;
|
||||
return _fileSystem.DownloadFileAsync(Bundle, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -0,0 +1,21 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public enum EFileNameStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 哈希值名称
|
||||
/// </summary>
|
||||
HashName = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称(不推荐)
|
||||
/// </summary>
|
||||
BundleName = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称 + 哈希值名称
|
||||
/// </summary>
|
||||
BundleName_HashName = 2,
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e81f00e510f07947873055518f5d1c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -31,8 +31,8 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam);
|
||||
|
||||
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
||||
|
||||
// 下载相关
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
||||
|
@@ -0,0 +1,21 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class ManifestDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件极限大小(100MB)
|
||||
/// </summary>
|
||||
public const int FileMaxSize = 104857600;
|
||||
|
||||
/// <summary>
|
||||
/// 文件头标记
|
||||
/// </summary>
|
||||
public const uint FileSign = 0x594F4F;
|
||||
|
||||
/// <summary>
|
||||
/// 文件格式版本
|
||||
/// </summary>
|
||||
public const string FileVersion = "2.3.1";
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3282b72521a19144292a482e50ba0429
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -8,7 +8,30 @@ namespace YooAsset
|
||||
{
|
||||
internal static class ManifestTools
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 验证清单文件的二进制数据
|
||||
/// </summary>
|
||||
public static bool VerifyManifestData(byte[] fileData, string hashValue)
|
||||
{
|
||||
if (fileData == null || fileData.Length == 0)
|
||||
return false;
|
||||
if (string.IsNullOrEmpty(hashValue))
|
||||
return false;
|
||||
|
||||
// 注意:兼容俩种验证方式
|
||||
// 注意:计算MD5的哈希值通常为32个字符
|
||||
string fileHash;
|
||||
if (hashValue.Length == 32)
|
||||
fileHash = HashUtility.BytesMD5(fileData);
|
||||
else
|
||||
fileHash = HashUtility.BytesCRC32(fileData);
|
||||
|
||||
if (fileHash == hashValue)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化(JSON文件)
|
||||
/// </summary>
|
||||
@@ -26,10 +49,10 @@ namespace YooAsset
|
||||
using (FileStream fs = new FileStream(savePath, FileMode.Create))
|
||||
{
|
||||
// 创建缓存器
|
||||
BufferWriter buffer = new BufferWriter(YooAssetSettings.ManifestFileMaxSize);
|
||||
BufferWriter buffer = new BufferWriter(ManifestDefine.FileMaxSize);
|
||||
|
||||
// 写入文件标记
|
||||
buffer.WriteUInt32(YooAssetSettings.ManifestFileSign);
|
||||
buffer.WriteUInt32(ManifestDefine.FileSign);
|
||||
|
||||
// 写入文件版本
|
||||
buffer.WriteUTF8(manifest.FileVersion);
|
||||
@@ -97,13 +120,13 @@ namespace YooAsset
|
||||
|
||||
// 读取文件标记
|
||||
uint fileSign = buffer.ReadUInt32();
|
||||
if (fileSign != YooAssetSettings.ManifestFileSign)
|
||||
if (fileSign != ManifestDefine.FileSign)
|
||||
throw new Exception("Invalid manifest file !");
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = buffer.ReadUTF8();
|
||||
if (fileVersion != YooAssetSettings.ManifestFileVersion)
|
||||
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}");
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}");
|
||||
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
{
|
||||
@@ -160,7 +183,7 @@ namespace YooAsset
|
||||
InitManifest(manifest);
|
||||
return manifest;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#region 解析资源清单辅助方法
|
||||
public static void InitManifest(PackageManifest manifest)
|
||||
@@ -198,9 +221,16 @@ namespace YooAsset
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
}
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
{
|
||||
if (manifest.LocationToLower)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
}
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
@@ -222,8 +252,6 @@ namespace YooAsset
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
if (manifest.LocationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
@@ -286,27 +314,6 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 注意:该类拷贝自编辑器
|
||||
/// </summary>
|
||||
private enum EFileNameStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// 哈希值名称
|
||||
/// </summary>
|
||||
HashName = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称(不推荐)
|
||||
/// </summary>
|
||||
BundleName = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称 + 哈希值名称
|
||||
/// </summary>
|
||||
BundleName_HashName = 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源文件的后缀名
|
||||
/// </summary>
|
||||
|
@@ -15,17 +15,15 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _clearMode;
|
||||
private readonly object _clearParam;
|
||||
private readonly ClearCacheFilesOptions _options;
|
||||
private List<IFileSystem> _cloneList;
|
||||
private FSClearCacheFilesOperation _clearCacheFilesOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearCacheFilesOperation(PlayModeImpl impl, string clearMode, object clearParam)
|
||||
internal ClearCacheFilesOperation(PlayModeImpl impl, ClearCacheFilesOptions options)
|
||||
{
|
||||
_impl = impl;
|
||||
_clearMode = clearMode;
|
||||
_clearParam = clearParam;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
@@ -74,7 +72,7 @@ namespace YooAsset
|
||||
var fileSystem = _cloneList[0];
|
||||
_cloneList.RemoveAt(0);
|
||||
|
||||
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam);
|
||||
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _options);
|
||||
_clearCacheFilesOp.StartOperation();
|
||||
AddChildOperation(_clearCacheFilesOp);
|
||||
_steps = ESteps.CheckClearResult;
|
||||
@@ -102,7 +100,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"ClearMode : {_clearMode}";
|
||||
return $"ClearMode : {_options.ClearMode}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -57,7 +57,7 @@ namespace YooAsset
|
||||
|
||||
// 读取文件标记
|
||||
uint fileSign = _buffer.ReadUInt32();
|
||||
if (fileSign != YooAssetSettings.ManifestFileSign)
|
||||
if (fileSign != ManifestDefine.FileSign)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -67,11 +67,11 @@ namespace YooAsset
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = _buffer.ReadUTF8();
|
||||
if (fileVersion != YooAssetSettings.ManifestFileVersion)
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.ManifestFileVersion}";
|
||||
Error = $"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -138,9 +138,6 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(location))
|
||||
return string.Empty;
|
||||
|
||||
if (LocationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
if (AssetPathMapping1.TryGetValue(location, out string assetPath))
|
||||
return assetPath;
|
||||
else
|
||||
@@ -174,7 +171,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源依赖列表
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageAsset packageAsset)
|
||||
@@ -188,6 +185,21 @@ namespace YooAsset
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取依赖列表
|
||||
/// 注意:传入的资源包对象一定合法有效!
|
||||
/// </summary>
|
||||
public PackageBundle[] GetAllDependencies(PackageBundle packageBundle)
|
||||
{
|
||||
List<PackageBundle> result = new List<PackageBundle>(packageBundle.DependBundleIDs.Length);
|
||||
foreach (var dependID in packageBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = GetMainPackageBundle(dependID);
|
||||
result.Add(dependBundle);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源
|
||||
/// </summary>
|
||||
@@ -292,9 +304,6 @@ namespace YooAsset
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (LocationToLower)
|
||||
location = location.ToLower();
|
||||
|
||||
if (AssetPathMapping1.TryGetValue(location, out string assetPath))
|
||||
{
|
||||
return assetPath;
|
||||
|
@@ -97,9 +97,9 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
|
||||
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new ClearCacheFilesOperation(this, clearMode, clearParam);
|
||||
var operation = new ClearCacheFilesOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,17 @@ namespace YooAsset
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
PackageBundle[] depends;
|
||||
if (assetInfo.LoadMethod == AssetInfo.ELoadMethod.LoadAllAssets)
|
||||
{
|
||||
var mainBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
depends = ActiveManifest.GetAllDependencies(mainBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
depends = ActiveManifest.GetAllDependencies(assetInfo.Asset);
|
||||
}
|
||||
|
||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||
foreach (var packageBundle in depends)
|
||||
{
|
||||
|
@@ -100,7 +100,7 @@ namespace YooAsset
|
||||
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
|
||||
_bundleQuery = playModeImpl;
|
||||
_playModeImpl = playModeImpl;
|
||||
_resourceManager.Initialize(_bundleQuery);
|
||||
_resourceManager.Initialize(parameters, _bundleQuery);
|
||||
|
||||
// 初始化资源系统
|
||||
InitializationOperation initializeOperation;
|
||||
@@ -162,6 +162,10 @@ namespace YooAsset
|
||||
throw new Exception($"Editor simulate mode only support unity editor.");
|
||||
#endif
|
||||
|
||||
// 检测初始化参数
|
||||
if (parameters.BundleLoadingMaxConcurrency <= 0)
|
||||
throw new Exception($"{nameof(parameters.BundleLoadingMaxConcurrency)} value must be greater than zero.");
|
||||
|
||||
// 鉴定运行模式
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
_playMode = EPlayMode.EditorSimulateMode;
|
||||
@@ -263,8 +267,11 @@ namespace YooAsset
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode.ToString(), clearParam);
|
||||
DebugCheckInitialize(false);
|
||||
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
|
||||
options.ClearMode = clearMode.ToString();
|
||||
options.ClearParam = clearParam;
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -276,8 +283,11 @@ namespace YooAsset
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(clearMode, clearParam);
|
||||
DebugCheckInitialize(false);
|
||||
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
|
||||
options.ClearMode = clearMode;
|
||||
options.ClearParam = clearParam;
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -610,6 +620,7 @@ namespace YooAsset
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, LocalPhysicsMode physicsMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadScene;
|
||||
var loadSceneParams = new LoadSceneParameters(sceneMode, physicsMode);
|
||||
var handle = _resourceManager.LoadSceneAsync(assetInfo, loadSceneParams, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
@@ -720,6 +731,7 @@ namespace YooAsset
|
||||
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAsset;
|
||||
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
@@ -829,6 +841,7 @@ namespace YooAsset
|
||||
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadSubAssets;
|
||||
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
@@ -938,6 +951,7 @@ namespace YooAsset
|
||||
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
assetInfo.LoadMethod = AssetInfo.ELoadMethod.LoadAllAssets;
|
||||
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
|
Reference in New Issue
Block a user