diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs
index a5ec895..79e07f9 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Text;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
@@ -61,5 +62,14 @@ namespace YooAsset.Editor
protected abstract string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext);
protected abstract string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext);
protected abstract long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext);
+
+ protected string GetFilePathTempHash(string filePath)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(filePath);
+ return HashUtility.BytesMD5(bytes);
+
+ // 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
+ //return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs
index 28464d7..1deb582 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs
@@ -55,7 +55,7 @@ namespace YooAsset.Editor
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
- return "00000000000000000000000000000000"; //32位
+ return GetFilePathTempHash(filePath);
else
return HashUtility.FileMD5(filePath);
}
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs
index 359000b..d9337b0 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs
@@ -37,7 +37,7 @@ namespace YooAsset.Editor
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
- return "00000000000000000000000000000000"; //32位
+ return GetFilePathTempHash(filePath);
else
return HashUtility.FileMD5(filePath);
}
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs
index 1faa2f8..b09ce8f 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs
@@ -55,7 +55,7 @@ namespace YooAsset.Editor
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
- return "00000000000000000000000000000000"; //32位
+ return GetFilePathTempHash(filePath);
else
return HashUtility.FileMD5(filePath);
}
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
index 74e1925..74d8826 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
@@ -176,23 +176,34 @@ namespace YooAsset
}
///
- /// 批量转换为解压BundleInfo
+ /// 批量创建解压BundleInfo
///
- public static List ConvertToUnpackInfos(ResourceAssist assist, List unpackList)
+ public static List CreateUnpackInfos(ResourceAssist assist, List unpackList)
{
List result = new List(unpackList.Count);
foreach (var packageBundle in unpackList)
{
- var bundleInfo = ConvertToUnpackInfo(assist, packageBundle);
+ var bundleInfo = CreateUnpackInfo(assist, packageBundle);
result.Add(bundleInfo);
}
return result;
}
- private static BundleInfo ConvertToUnpackInfo(ResourceAssist assist, PackageBundle packageBundle)
+ private static BundleInfo CreateUnpackInfo(ResourceAssist assist, PackageBundle packageBundle)
{
string streamingPath = PersistentHelper.ConvertToWWWPath(assist.Persistent.GetBuildinFilePath(packageBundle));
BundleInfo newBundleInfo = new BundleInfo(assist, packageBundle, ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return newBundleInfo;
}
+
+ ///
+ /// 创建导入BundleInfo
+ ///
+ public static BundleInfo CreateImportInfo(ResourceAssist assist, PackageBundle packageBundle, string filePath)
+ {
+ // 注意:我们把本地文件路径指定为远端下载地址
+ string persistentPath = PersistentHelper.ConvertToWWWPath(filePath);
+ BundleInfo bundleInfo = new BundleInfo(assist, packageBundle, BundleInfo.ELoadMode.None, persistentPath, persistentPath);
+ return bundleInfo;
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IPlayMode.cs b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IPlayMode.cs
index e1a87ff..2d0471a 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IPlayMode.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IPlayMode.cs
@@ -36,5 +36,8 @@ namespace YooAsset
// 解压相关
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout);
+
+ // 导入相关
+ ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout);
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ManifestTools.cs b/Assets/YooAsset/Runtime/ResourcePackage/ManifestTools.cs
index 7d150af..182bce3 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/ManifestTools.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/ManifestTools.cs
@@ -151,11 +151,13 @@ namespace YooAsset
}
// 填充BundleDic
- manifest.BundleDic = new Dictionary(manifest.BundleList.Count);
+ manifest.BundleDic1 = new Dictionary(manifest.BundleList.Count);
+ manifest.BundleDic2 = new Dictionary(manifest.BundleList.Count);
foreach (var packageBundle in manifest.BundleList)
{
packageBundle.ParseBundle(manifest);
- manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
+ manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
+ manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
}
// 填充AssetDic
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
index 2369440..bc3abb2 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs
@@ -267,7 +267,6 @@ namespace YooAsset
return operation;
}
}
-
public sealed class ResourceUnpackerOperation : DownloaderOperation
{
internal ResourceUnpackerOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
@@ -285,4 +284,21 @@ namespace YooAsset
return operation;
}
}
+ public sealed class ResourceImporterOperation : DownloaderOperation
+ {
+ internal ResourceImporterOperation(string packageName, List downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
+ : base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
+ {
+ }
+
+ ///
+ /// 创建空的导入器
+ ///
+ internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
+ {
+ List downloadList = new List();
+ var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
+ return operation;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/DeserializeManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/DeserializeManifestOperation.cs
index a3c2989..740996b 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/DeserializeManifestOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/Internal/DeserializeManifestOperation.cs
@@ -185,7 +185,8 @@ namespace YooAsset
{
_packageBundleCount = _buffer.ReadInt32();
Manifest.BundleList = new List(_packageBundleCount);
- Manifest.BundleDic = new Dictionary(_packageBundleCount);
+ Manifest.BundleDic1 = new Dictionary(_packageBundleCount);
+ Manifest.BundleDic2 = new Dictionary(_packageBundleCount);
_progressTotalValue = _packageBundleCount;
_steps = ESteps.DeserializeBundleList;
}
@@ -203,8 +204,9 @@ namespace YooAsset
packageBundle.Tags = _buffer.ReadUTF8Array();
packageBundle.DependIDs = _buffer.ReadInt32Array();
packageBundle.ParseBundle(Manifest);
- Manifest.BundleList.Add(packageBundle);
- Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
+ Manifest.BundleList.Add(packageBundle);
+ Manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
+ Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
// 注意:原始文件可能存在相同的CacheGUID
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs
index e2f0e2a..97f89a1 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs
@@ -67,7 +67,13 @@ namespace YooAsset
/// 资源包集合(提供BundleName获取PackageBundle)
///
[NonSerialized]
- public Dictionary BundleDic;
+ public Dictionary BundleDic1;
+
+ ///
+ /// 资源包集合(提供FileName获取PackageBundle)
+ ///
+ [NonSerialized]
+ public Dictionary BundleDic2;
///
/// 资源映射集合(提供AssetPath获取PackageAsset)
@@ -170,9 +176,17 @@ namespace YooAsset
///
/// 尝试获取包裹的资源包
///
- public bool TryGetPackageBundle(string bundleName, out PackageBundle result)
+ public bool TryGetPackageBundleByBundleName(string bundleName, out PackageBundle result)
{
- return BundleDic.TryGetValue(bundleName, out result);
+ return BundleDic1.TryGetValue(bundleName, out result);
+ }
+
+ ///
+ /// 尝试获取包裹的资源包
+ ///
+ public bool TryGetPackageBundleByFileName(string fileName, out PackageBundle result)
+ {
+ return BundleDic2.TryGetValue(fileName, out result);
}
///
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs
index 6b00d00..6741377 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs
@@ -85,6 +85,11 @@ namespace YooAsset
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout);
}
+
+ ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
+ {
+ return ResourceImporterOperation.CreateEmptyImporter(PackageName, importerMaxNumber, failedTryAgain, timeout);
+ }
#endregion
#region IBundleQuery接口
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs
index 1d0b431..4c375be 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs
@@ -265,7 +265,7 @@ namespace YooAsset
}
}
- return BundleInfo.ConvertToUnpackInfos(_assist, downloadList);
+ return BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
@@ -293,7 +293,36 @@ namespace YooAsset
}
}
- return BundleInfo.ConvertToUnpackInfos(_assist, downloadList);
+ return BundleInfo.CreateUnpackInfos(_assist, downloadList);
+ }
+
+ ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
+ {
+ List importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
+ var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
+ return operation;
+ }
+ private List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
+ {
+ List result = new List();
+ foreach (var filePath in filePaths)
+ {
+ string fileName = System.IO.Path.GetFileName(filePath);
+ if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
+ {
+ // 忽略缓存文件
+ if (IsCachedPackageBundle(packageBundle))
+ continue;
+
+ var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
+ result.Add(bundleInfo);
+ }
+ else
+ {
+ YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
+ }
+ }
+ return result;
}
#endregion
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs
index 731abb7..f182bb8 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs
@@ -109,7 +109,7 @@ namespace YooAsset
downloadList.Add(packageBundle);
}
- return BundleInfo.ConvertToUnpackInfos(_assist, downloadList);
+ return BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
@@ -134,7 +134,36 @@ namespace YooAsset
}
}
- return BundleInfo.ConvertToUnpackInfos(_assist, downloadList);
+ return BundleInfo.CreateUnpackInfos(_assist, downloadList);
+ }
+
+ ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
+ {
+ List importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
+ var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
+ return operation;
+ }
+ private List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
+ {
+ List result = new List();
+ foreach (var filePath in filePaths)
+ {
+ string fileName = System.IO.Path.GetFileName(filePath);
+ if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
+ {
+ // 忽略缓存文件
+ if (IsCachedPackageBundle(packageBundle))
+ continue;
+
+ var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
+ result.Add(bundleInfo);
+ }
+ else
+ {
+ YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
+ }
+ }
+ return result;
}
#endregion
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs
index 7e66515..4c7087d 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs
@@ -112,6 +112,11 @@ namespace YooAsset
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(PackageName, upackingMaxNumber, failedTryAgain, timeout);
}
+
+ ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
+ {
+ return ResourceImporterOperation.CreateEmptyImporter(PackageName, importerMaxNumber, failedTryAgain, timeout);
+ }
#endregion
#region IBundleQuery接口
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
index 5025561..8da7364 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
@@ -352,7 +352,6 @@ namespace YooAsset
public void UnloadUnusedAssets()
{
DebugCheckInitialize();
- _resourceMgr.Update();
_resourceMgr.UnloadUnusedAssets();
}
@@ -1028,6 +1027,21 @@ namespace YooAsset
}
#endregion
+ #region 资源导入
+ ///
+ /// 创建资源导入器
+ /// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
+ ///
+ /// 资源路径列表
+ /// 同时导入的最大文件数
+ /// 导入失败的重试次数
+ public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
+ {
+ DebugCheckInitialize();
+ return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain, int.MaxValue);
+ }
+ #endregion
+
#region 内部方法
///
/// 是否包含资源文件