diff --git a/Assets/YooAsset/Runtime/AssetReference.cs b/Assets/YooAsset/Runtime/AssetReference.cs
deleted file mode 100644
index 2ed11d0..0000000
--- a/Assets/YooAsset/Runtime/AssetReference.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using UnityEngine;
-
-namespace YooAsset
-{
- public class AssetReference
- {
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/AssetReference.cs.meta b/Assets/YooAsset/Runtime/AssetReference.cs.meta
deleted file mode 100644
index 062d368..0000000
--- a/Assets/YooAsset/Runtime/AssetReference.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 1534f1a1b207ad542bf1fc73da8b4316
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs
index a6e157e..a430f02 100644
--- a/Assets/YooAsset/Runtime/InitializeParameters.cs
+++ b/Assets/YooAsset/Runtime/InitializeParameters.cs
@@ -27,12 +27,6 @@ namespace YooAsset
///
public abstract class InitializeParameters
{
- ///
- /// 资源定位地址大小写不敏感
- /// 注意:默认值为False
- ///
- public bool LocationToLower = false;
-
///
/// 文件解密服务接口
///
diff --git a/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs b/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs
index 40a4a0c..30e1674 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs
@@ -36,6 +36,8 @@ namespace YooAsset
// 写入文件头信息
buffer.WriteBool(manifest.EnableAddressable);
+ buffer.WriteBool(manifest.LocationToLower);
+ buffer.WriteBool(manifest.IncludeAssetGUID);
buffer.WriteInt32(manifest.OutputNameStyle);
buffer.WriteUTF8(manifest.PackageName);
buffer.WriteUTF8(manifest.PackageVersion);
@@ -47,6 +49,7 @@ namespace YooAsset
var packageAsset = manifest.AssetList[i];
buffer.WriteUTF8(packageAsset.Address);
buffer.WriteUTF8(packageAsset.AssetPath);
+ buffer.WriteUTF8(packageAsset.AssetGUID);
buffer.WriteUTF8Array(packageAsset.AssetTags);
buffer.WriteInt32(packageAsset.BundleID);
buffer.WriteInt32Array(packageAsset.DependIDs);
@@ -104,10 +107,16 @@ namespace YooAsset
// 读取文件头信息
manifest.FileVersion = fileVersion;
manifest.EnableAddressable = buffer.ReadBool();
+ manifest.LocationToLower = buffer.ReadBool();
+ manifest.IncludeAssetGUID = buffer.ReadBool();
manifest.OutputNameStyle = buffer.ReadInt32();
manifest.PackageName = buffer.ReadUTF8();
manifest.PackageVersion = buffer.ReadUTF8();
+ // 检测配置
+ if (manifest.EnableAddressable && manifest.LocationToLower)
+ throw new Exception("Addressable not support location to lower !");
+
// 读取资源列表
int packageAssetCount = buffer.ReadInt32();
manifest.AssetList = new List(packageAssetCount);
@@ -116,6 +125,7 @@ namespace YooAsset
var packageAsset = new PackageAsset();
packageAsset.Address = buffer.ReadUTF8();
packageAsset.AssetPath = buffer.ReadUTF8();
+ packageAsset.AssetGUID = buffer.ReadUTF8();
packageAsset.AssetTags = buffer.ReadUTF8Array();
packageAsset.BundleID = buffer.ReadInt32();
packageAsset.DependIDs = buffer.ReadInt32Array();
@@ -140,7 +150,7 @@ namespace YooAsset
}
}
- // BundleDic
+ // 填充BundleDic
manifest.BundleDic = new Dictionary(manifest.BundleList.Count);
foreach (var packageBundle in manifest.BundleList)
{
@@ -148,7 +158,7 @@ namespace YooAsset
manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
}
- // AssetDic
+ // 填充AssetDic
manifest.AssetDic = new Dictionary(manifest.AssetList.Count);
foreach (var packageAsset in manifest.AssetList)
{
diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DeserializeManifestOperation.cs
index 973246c..b1e4907 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DeserializeManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/DeserializeManifestOperation.cs
@@ -16,7 +16,7 @@ namespace YooAsset
DeserializeBundleList,
Done,
}
-
+
private readonly BufferReader _buffer;
private int _packageAssetCount;
private int _packageBundleCount;
@@ -77,10 +77,16 @@ namespace YooAsset
Manifest = new PackageManifest();
Manifest.FileVersion = fileVersion;
Manifest.EnableAddressable = _buffer.ReadBool();
+ Manifest.LocationToLower = _buffer.ReadBool();
+ Manifest.IncludeAssetGUID = _buffer.ReadBool();
Manifest.OutputNameStyle = _buffer.ReadInt32();
Manifest.PackageName = _buffer.ReadUTF8();
Manifest.PackageVersion = _buffer.ReadUTF8();
+ // 检测配置
+ if (Manifest.EnableAddressable && Manifest.LocationToLower)
+ throw new System.Exception("Addressable not support location to lower !");
+
_steps = ESteps.PrepareAssetList;
}
@@ -89,6 +95,17 @@ namespace YooAsset
_packageAssetCount = _buffer.ReadInt32();
Manifest.AssetList = new List(_packageAssetCount);
Manifest.AssetDic = new Dictionary(_packageAssetCount);
+
+ if (Manifest.EnableAddressable)
+ Manifest.AssetPathMapping1 = new Dictionary(_packageAssetCount);
+ else
+ Manifest.AssetPathMapping1 = new Dictionary(_packageAssetCount * 2);
+
+ if (Manifest.IncludeAssetGUID)
+ Manifest.AssetPathMapping2 = new Dictionary(_packageAssetCount);
+ else
+ Manifest.AssetPathMapping2 = new Dictionary();
+
_progressTotalValue = _packageAssetCount;
_steps = ESteps.DeserializeAssetList;
}
@@ -99,6 +116,7 @@ namespace YooAsset
var packageAsset = new PackageAsset();
packageAsset.Address = _buffer.ReadUTF8();
packageAsset.AssetPath = _buffer.ReadUTF8();
+ packageAsset.AssetGUID = _buffer.ReadUTF8();
packageAsset.AssetTags = _buffer.ReadUTF8Array();
packageAsset.BundleID = _buffer.ReadInt32();
packageAsset.DependIDs = _buffer.ReadInt32Array();
@@ -111,6 +129,47 @@ namespace YooAsset
else
Manifest.AssetDic.Add(assetPath, packageAsset);
+ // 填充AssetPathMapping1
+ if (Manifest.EnableAddressable)
+ {
+ string location = packageAsset.Address;
+ if (Manifest.AssetPathMapping1.ContainsKey(location))
+ throw new System.Exception($"Address have existed : {location}");
+ else
+ Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
+ }
+ else
+ {
+ string location = packageAsset.AssetPath;
+ if (Manifest.LocationToLower)
+ location = location.ToLower();
+
+ // 添加原生路径的映射
+ if (Manifest.AssetPathMapping1.ContainsKey(location))
+ throw new System.Exception($"AssetPath have existed : {location}");
+ else
+ Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
+
+ // 添加无后缀名路径的映射
+ if (Path.HasExtension(location))
+ {
+ string locationWithoutExtension = PathUtility.RemoveExtension(location);
+ if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
+ YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}");
+ else
+ Manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
+ }
+ }
+
+ // 填充AssetPathMapping2
+ if (Manifest.IncludeAssetGUID)
+ {
+ if (Manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
+ throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
+ else
+ Manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
+ }
+
_packageAssetCount--;
Progress = 1f - _packageAssetCount / _progressTotalValue;
if (OperationSystem.IsBusy)
diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageAsset.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageAsset.cs
index 3ba70fb..d486cc3 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/PackageAsset.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/PackageAsset.cs
@@ -16,6 +16,11 @@ namespace YooAsset
///
public string AssetPath;
+ ///
+ /// 资源GUID
+ ///
+ public string AssetGUID;
+
///
/// 资源的分类标签
///
diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs
index 8b55afd..881b935 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs
@@ -22,6 +22,16 @@ namespace YooAsset
///
public bool EnableAddressable;
+ ///
+ /// 资源定位地址大小写不敏感
+ ///
+ public bool LocationToLower;
+
+ ///
+ /// 包含资源GUID数据
+ ///
+ public bool IncludeAssetGUID;
+
///
/// 文件名称样式
///
@@ -61,93 +71,17 @@ namespace YooAsset
public Dictionary AssetDic;
///
- /// 资源路径映射集合
+ /// 资源路径映射集合(提供Location获取AssetPath)
///
[NonSerialized]
- public Dictionary AssetPathMapping;
-
- // 资源路径映射相关
- private bool _isInitAssetPathMapping = false;
- private bool _locationToLower = false;
-
+ public Dictionary AssetPathMapping1;
///
- /// 初始化资源路径映射
+ /// 资源路径映射集合(提供AssetGUID获取AssetPath)
///
- public void InitAssetPathMapping(bool locationToLower)
- {
- if (_isInitAssetPathMapping)
- return;
- _isInitAssetPathMapping = true;
+ [NonSerialized]
+ public Dictionary AssetPathMapping2;
- if (EnableAddressable)
- {
- if (locationToLower)
- YooLogger.Error("Addressable not support location to lower !");
-
- AssetPathMapping = new Dictionary(AssetList.Count);
- foreach (var packageAsset in AssetList)
- {
- string location = packageAsset.Address;
- if (AssetPathMapping.ContainsKey(location))
- throw new Exception($"Address have existed : {location}");
- else
- AssetPathMapping.Add(location, packageAsset.AssetPath);
- }
- }
- else
- {
- _locationToLower = locationToLower;
- AssetPathMapping = new Dictionary(AssetList.Count * 2);
- foreach (var packageAsset in AssetList)
- {
- string location = packageAsset.AssetPath;
- if (locationToLower)
- location = location.ToLower();
-
- // 添加原生路径的映射
- if (AssetPathMapping.ContainsKey(location))
- throw new Exception($"AssetPath have existed : {location}");
- else
- AssetPathMapping.Add(location, packageAsset.AssetPath);
-
- // 添加无后缀名路径的映射
- if (Path.HasExtension(location))
- {
- string locationWithoutExtension = PathUtility.RemoveExtension(location);
- if (AssetPathMapping.ContainsKey(locationWithoutExtension))
- YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}");
- else
- AssetPathMapping.Add(locationWithoutExtension, packageAsset.AssetPath);
- }
- }
- }
- }
-
- ///
- /// 映射为资源路径
- ///
- public string MappingToAssetPath(string location)
- {
- if (string.IsNullOrEmpty(location))
- {
- YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
- return string.Empty;
- }
-
- if (_locationToLower)
- location = location.ToLower();
-
- if (AssetPathMapping.TryGetValue(location, out string assetPath))
- {
- return assetPath;
- }
- else
- {
- YooLogger.Warning($"Failed to mapping location to asset path : {location}");
- return string.Empty;
- }
- }
///
/// 尝试映射为资源路径
@@ -157,10 +91,10 @@ namespace YooAsset
if (string.IsNullOrEmpty(location))
return string.Empty;
- if (_locationToLower)
+ if (LocationToLower)
location = location.ToLower();
- if (AssetPathMapping.TryGetValue(location, out string assetPath))
+ if (AssetPathMapping1.TryGetValue(location, out string assetPath))
return assetPath;
else
return string.Empty;
@@ -283,14 +217,14 @@ namespace YooAsset
}
///
- /// 资源定位地址转换为资源信息类,失败时内部会发出错误日志。
+ /// 资源定位地址转换为资源信息。
///
/// 如果转换失败会返回一个无效的资源信息类
public AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
DebugCheckLocation(location);
- string assetPath = MappingToAssetPath(location);
+ string assetPath = ConvertLocationToAssetInfoMapping(location);
if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
{
AssetInfo assetInfo = new AssetInfo(packageAsset, assetType);
@@ -307,6 +241,76 @@ namespace YooAsset
return assetInfo;
}
}
+ private string ConvertLocationToAssetInfoMapping(string location)
+ {
+ if (string.IsNullOrEmpty(location))
+ {
+ YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
+ return string.Empty;
+ }
+
+ if (LocationToLower)
+ location = location.ToLower();
+
+ if (AssetPathMapping1.TryGetValue(location, out string assetPath))
+ {
+ return assetPath;
+ }
+ else
+ {
+ YooLogger.Warning($"Failed to mapping location to asset path : {location}");
+ return string.Empty;
+ }
+ }
+
+ ///
+ /// 资源GUID转换为资源信息。
+ ///
+ /// 如果转换失败会返回一个无效的资源信息类
+ public AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType)
+ {
+ if (IncludeAssetGUID == false)
+ {
+ YooLogger.Warning("Package manifest not include asset guid ! Please check asset bundle collector settings.");
+ AssetInfo assetInfo = new AssetInfo("AssetGUID data is empty !");
+ return assetInfo;
+ }
+
+ string assetPath = ConvertAssetGUIDToAssetInfoMapping(assetGUID);
+ if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
+ {
+ AssetInfo assetInfo = new AssetInfo(packageAsset, assetType);
+ return assetInfo;
+ }
+ else
+ {
+ string error;
+ if (string.IsNullOrEmpty(assetGUID))
+ error = $"The assetGUID is null or empty !";
+ else
+ error = $"The assetGUID is invalid : {assetGUID}";
+ AssetInfo assetInfo = new AssetInfo(error);
+ return assetInfo;
+ }
+ }
+ private string ConvertAssetGUIDToAssetInfoMapping(string assetGUID)
+ {
+ if (string.IsNullOrEmpty(assetGUID))
+ {
+ YooLogger.Error("Failed to mapping assetGUID to asset path, The assetGUID is null or empty.");
+ return string.Empty;
+ }
+
+ if (AssetPathMapping2.TryGetValue(assetGUID, out string assetPath))
+ {
+ return assetPath;
+ }
+ else
+ {
+ YooLogger.Warning($"Failed to mapping assetGUID to asset path : {assetGUID}");
+ return string.Empty;
+ }
+ }
///
/// 获取资源包内的主资源列表
diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs
index 6d5ad26..42282c0 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/EditorSimulateModeImpl.cs
@@ -7,14 +7,12 @@ namespace YooAsset
internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices
{
private PackageManifest _activeManifest;
- private bool _locationToLower;
///
/// 异步初始化
///
- public InitializationOperation InitializeAsync(bool locationToLower, string simulateManifestFilePath)
+ public InitializationOperation InitializeAsync(string simulateManifestFilePath)
{
- _locationToLower = locationToLower;
var operation = new EditorSimulateModeInitializationOperation(this, simulateManifestFilePath);
OperationSystem.StartOperation(operation);
return operation;
@@ -26,7 +24,6 @@ namespace YooAsset
set
{
_activeManifest = value;
- _activeManifest.InitAssetPathMapping(_locationToLower);
}
get
{
diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs
index d0f5d50..627859d 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs
@@ -10,7 +10,6 @@ namespace YooAsset
// 参数相关
private string _packageName;
- private bool _locationToLower;
private string _defaultHostServer;
private string _fallbackHostServer;
private IQueryServices _queryServices;
@@ -18,10 +17,9 @@ namespace YooAsset
///
/// 异步初始化
///
- public InitializationOperation InitializeAsync(string packageName, bool locationToLower, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices)
+ public InitializationOperation InitializeAsync(string packageName, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices)
{
_packageName = packageName;
- _locationToLower = locationToLower;
_defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer;
_queryServices = queryServices;
@@ -67,7 +65,6 @@ namespace YooAsset
set
{
_activeManifest = value;
- _activeManifest.InitAssetPathMapping(_locationToLower);
}
get
{
diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs
index 4b12d38..50c1a2d 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -7,14 +7,12 @@ namespace YooAsset
internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices
{
private PackageManifest _activeManifest;
- private bool _locationToLower;
///
/// 异步初始化
///
- public InitializationOperation InitializeAsync(string packageName, bool locationToLower)
+ public InitializationOperation InitializeAsync(string packageName)
{
- _locationToLower = locationToLower;
var operation = new OfflinePlayModeInitializationOperation(this, packageName);
OperationSystem.StartOperation(operation);
return operation;
@@ -26,7 +24,6 @@ namespace YooAsset
set
{
_activeManifest = value;
- _activeManifest.InitAssetPathMapping(_locationToLower);
}
get
{
diff --git a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs
index 30f2d0f..ce843e7 100644
--- a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs
+++ b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs
@@ -92,7 +92,7 @@ namespace YooAsset
parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as EditorSimulateModeParameters;
- initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulateManifestFilePath);
+ initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.SimulateManifestFilePath);
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
@@ -104,7 +104,7 @@ namespace YooAsset
parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as OfflinePlayModeParameters;
- initializeOperation = offlinePlayModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower);
+ initializeOperation = offlinePlayModeImpl.InitializeAsync(PackageName);
}
else if (_playMode == EPlayMode.HostPlayMode)
{
@@ -118,7 +118,6 @@ namespace YooAsset
var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(
PackageName,
- initializeParameters.LocationToLower,
initializeParameters.DefaultHostServer,
initializeParameters.FallbackHostServer,
initializeParameters.QueryServices
@@ -363,8 +362,17 @@ namespace YooAsset
public AssetInfo GetAssetInfo(string location)
{
DebugCheckInitialize();
- AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
- return assetInfo;
+ return ConvertLocationToAssetInfo(location, null);
+ }
+
+ ///
+ /// 获取资源信息
+ ///
+ /// 资源GUID
+ public AssetInfo GetAssetInfoByGUID(string assetGUID)
+ {
+ DebugCheckInitialize();
+ return ConvertAssetGUIDToAssetInfo(assetGUID, null);
}
///
@@ -889,13 +897,14 @@ namespace YooAsset
return _playModeServices.ActiveManifest.IsIncludeBundleFile(cacheGUID);
}
- ///
- /// 资源定位地址转换为资源信息类
- ///
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
return _playModeServices.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
}
+ private AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType)
+ {
+ return _playModeServices.ActiveManifest.ConvertAssetGUIDToAssetInfo(assetGUID, assetType);
+ }
#endregion
#region 调试方法
diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
index 4b85030..adc0564 100644
--- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
+++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs
@@ -24,7 +24,7 @@ namespace YooAsset
///
/// 清单文件格式版本
///
- public const string ManifestFileVersion = "1.4.6";
+ public const string ManifestFileVersion = "1.4.17";
///