diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs
new file mode 100644
index 0000000..6a0767a
--- /dev/null
+++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs
@@ -0,0 +1,27 @@
+
+namespace YooAsset
+{
+ public class AssetInfo
+ {
+ ///
+ /// 资源路径
+ ///
+ public string AssetPath { private set; get; }
+
+ ///
+ /// 资源类型
+ ///
+ public System.Type AssetType { private set; get; }
+
+ public AssetInfo(string assetPath, System.Type assetType)
+ {
+ AssetPath = assetPath;
+ AssetType = assetType;
+ }
+ public AssetInfo(string assetPath)
+ {
+ AssetPath = assetPath;
+ AssetType = null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs.meta
new file mode 100644
index 0000000..a3055bc
--- /dev/null
+++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 07db4f624e6cf80468fadd9e94691017
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
index b0cad9c..2757251 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs
@@ -82,7 +82,7 @@ namespace YooAsset
}
else
{
- throw new Exception($"Invalid depend id : {dependID} Asset path : {assetPath}");
+ throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}");
}
}
return result.ToArray();
@@ -109,7 +109,7 @@ namespace YooAsset
}
else
{
- throw new Exception($"Invalid depend id : {bundleID} Asset path : {assetPath}");
+ throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}");
}
}
else
@@ -135,7 +135,7 @@ namespace YooAsset
}
else
{
- throw new Exception($"Invalid depend id : {bundleID} Asset path : {patchAsset.AssetPath}");
+ throw new Exception($"Invalid bundle id : {bundleID} Asset path : {patchAsset.AssetPath}");
}
}
return string.Empty;
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
index 2313fc8..2d6b883 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeImpl.cs
@@ -47,6 +47,10 @@ namespace YooAsset
return bundleInfo;
}
}
+ AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
+ {
+ return PatchHelper.GetAssetsInfoByTag(AppPatchManifest, tags);
+ }
string IBundleServices.MappingToAssetPath(string location)
{
return AppPatchManifest.MappingToAssetPath(location);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
index aa4b089..811f3d8 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs
@@ -309,6 +309,10 @@ namespace YooAsset
return bundleInfo;
}
}
+ AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
+ {
+ return PatchHelper.GetAssetsInfoByTag(LocalPatchManifest, tags);
+ }
string IBundleServices.MappingToAssetPath(string location)
{
return LocalPatchManifest.MappingToAssetPath(location);
diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
index 6f6ad81..4b726aa 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs
@@ -56,6 +56,10 @@ namespace YooAsset
return bundleInfo;
}
}
+ AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
+ {
+ return PatchHelper.GetAssetsInfoByTag(AppPatchManifest, tags);
+ }
string IBundleServices.MappingToAssetPath(string location)
{
return AppPatchManifest.MappingToAssetPath(location);
diff --git a/Assets/YooAsset/Runtime/Services/IBundleServices.cs b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
index 1132b86..fd4e219 100644
--- a/Assets/YooAsset/Runtime/Services/IBundleServices.cs
+++ b/Assets/YooAsset/Runtime/Services/IBundleServices.cs
@@ -4,10 +4,15 @@ namespace YooAsset
internal interface IBundleServices
{
///
- /// 获取AssetBundle的信息
+ /// 获取资源包信息
///
BundleInfo GetBundleInfo(string bundleName);
+ ///
+ /// 获取资源信息列表
+ ///
+ AssetInfo[] GetAssetInfos(string[] tags);
+
///
/// 映射为资源路径
///
diff --git a/Assets/YooAsset/Runtime/Utility/YooHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs
index f9cfdb4..22cd528 100644
--- a/Assets/YooAsset/Runtime/Utility/YooHelper.cs
+++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs
@@ -169,5 +169,25 @@ namespace YooAsset
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
return bundleInfo;
}
+
+ ///
+ /// 获取资源信息列表
+ ///
+ public static AssetInfo[] GetAssetsInfoByTag(PatchManifest patchManifest, string[] tags)
+ {
+ List result = new List(100);
+ foreach (var patchAsset in patchManifest.AssetList)
+ {
+ string bundleName = patchManifest.GetBundleName(patchAsset.AssetPath);
+ if(patchManifest.Bundles.TryGetValue(bundleName, out PatchBundle bundle))
+ {
+ if(bundle.HasTag(tags))
+ {
+ result.Add(new AssetInfo(patchAsset.AssetPath));
+ }
+ }
+ }
+ return result.ToArray();
+ }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index 0fba011..225fd71 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -61,21 +61,21 @@ namespace YooAsset
}
///
- /// 编辑器下模拟运行(只支持在编辑器下运行)
+ /// 编辑器下模拟运行模式参数
///
public class EditorPlayModeParameters : CreateParameters
{
}
///
- /// 离线模式(本地打包运行模式)
+ /// 离线模式参数
///
public class OfflinePlayModeParameters : CreateParameters
{
}
///
- /// 网络模式(网络打包运行模式)
+ /// 网络模式参数
///
public class HostPlayModeParameters : CreateParameters
{
@@ -305,16 +305,6 @@ namespace YooAsset
}
}
- ///
- /// 获取资源包信息
- ///
- public static BundleInfo GetBundleInfo(string location)
- {
- string assetPath = _locationServices.ConvertLocationToAssetPath(location);
- string bundleName = _bundleServices.GetBundleName(assetPath);
- return _bundleServices.GetBundleInfo(bundleName);
- }
-
///
/// 资源回收(卸载引用计数为零的资源)
///
@@ -332,6 +322,38 @@ namespace YooAsset
AssetSystem.ForceUnloadAllAssets();
}
+ ///
+ /// 获取资源包信息
+ ///
+ /// 资源的定位地址
+ public static BundleInfo GetBundleInfo(string location)
+ {
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ string bundleName = _bundleServices.GetBundleName(assetPath);
+ return _bundleServices.GetBundleInfo(bundleName);
+ }
+
+ ///
+ /// 获取资源包信息
+ ///
+ /// 资源信息
+ public static BundleInfo GetBundleInfo(AssetInfo assetInfo)
+ {
+ string bundleName = _bundleServices.GetBundleName(assetInfo.AssetPath);
+ return _bundleServices.GetBundleInfo(bundleName);
+ }
+
+ ///
+ /// 获取资源信息列表
+ ///
+ /// 资源标签
+ ///
+ public static AssetInfo[] GetAssetInfos(string tag)
+ {
+ string[] tags = new string[] { tag };
+ return _bundleServices.GetAssetInfos(tags);
+ }
+
///
/// 获取调试信息
///
@@ -347,7 +369,7 @@ namespace YooAsset
///
/// 异步加载场景
///
- /// 场景对象相对路径
+ /// 场景的定位地址
/// 场景加载模式
/// 加载完毕时是否主动激活
/// 优先级
@@ -357,6 +379,20 @@ namespace YooAsset
var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority);
return handle;
}
+
+ ///
+ /// 异步加载场景
+ ///
+ /// 场景的资源信息
+ /// 场景加载模式
+ /// 加载完毕时是否主动激活
+ /// 优先级
+ public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
+ {
+ string scenePath = assetInfo.AssetPath;
+ var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority);
+ return handle;
+ }
#endregion
#region 资源加载
@@ -368,36 +404,28 @@ namespace YooAsset
public static RawFileOperation GetRawFileAsync(string location, string copyPath = null)
{
string assetPath = _locationServices.ConvertLocationToAssetPath(location);
- if (_playMode == EPlayMode.EditorPlayMode)
- {
- string bundleName = _bundleServices.GetBundleName(assetPath);
- BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
- RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
- OperationSystem.ProcessOperaiton(operation);
- return operation;
- }
- else if (_playMode == EPlayMode.OfflinePlayMode)
- {
- string bundleName = _bundleServices.GetBundleName(assetPath);
- BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
- RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
- OperationSystem.ProcessOperaiton(operation);
- return operation;
- }
- else if (_playMode == EPlayMode.HostPlayMode)
- {
- string bundleName = _bundleServices.GetBundleName(assetPath);
- BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
- RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
- OperationSystem.ProcessOperaiton(operation);
- return operation;
- }
- else
- {
- throw new NotImplementedException();
- }
+ return GetRawFileInternal(assetPath, copyPath);
}
+ ///
+ /// 异步获取原生文件
+ ///
+ /// 资源信息
+ /// 拷贝路径
+ public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
+ {
+ return GetRawFileInternal(assetInfo.AssetPath, copyPath);
+ }
+
+
+ ///
+ /// 同步加载资源对象
+ ///
+ /// 资源信息
+ public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo)
+ {
+ return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, true);
+ }
///
/// 同步加载资源对象
@@ -406,7 +434,8 @@ namespace YooAsset
/// 资源的定位地址
public static AssetOperationHandle LoadAssetSync(string location) where TObject : class
{
- return LoadAssetInternal(location, typeof(TObject), true);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadAssetInternal(assetPath, typeof(TObject), true);
}
///
@@ -416,7 +445,18 @@ namespace YooAsset
/// 资源类型
public static AssetOperationHandle LoadAssetSync(string location, System.Type type)
{
- return LoadAssetInternal(location, type, true);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadAssetInternal(assetPath, type, true);
+ }
+
+
+ ///
+ /// 同步加载子资源对象
+ ///
+ /// 资源信息
+ public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo)
+ {
+ return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, true);
}
///
@@ -426,7 +466,8 @@ namespace YooAsset
/// 资源的定位地址
public static SubAssetsOperationHandle LoadSubAssetsSync(string location)
{
- return LoadSubAssetsInternal(location, typeof(TObject), true);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadSubAssetsInternal(assetPath, typeof(TObject), true);
}
///
@@ -436,10 +477,20 @@ namespace YooAsset
/// 子对象类型
public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type)
{
- return LoadSubAssetsInternal(location, type, true);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadSubAssetsInternal(assetPath, type, true);
}
+ ///
+ /// 异步加载资源对象
+ ///
+ /// 资源信息
+ public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
+ {
+ return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, false);
+ }
+
///
/// 异步加载资源对象
///
@@ -447,7 +498,8 @@ namespace YooAsset
/// 资源的定位地址
public static AssetOperationHandle LoadAssetAsync(string location)
{
- return LoadAssetInternal(location, typeof(TObject), false);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadAssetInternal(assetPath, typeof(TObject), false);
}
///
@@ -457,7 +509,18 @@ namespace YooAsset
/// 资源类型
public static AssetOperationHandle LoadAssetAsync(string location, System.Type type)
{
- return LoadAssetInternal(location, type, false);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadAssetInternal(assetPath, type, false);
+ }
+
+
+ ///
+ /// 异步加载子资源对象
+ ///
+ /// 资源信息
+ public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
+ {
+ return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, false);
}
///
@@ -467,7 +530,8 @@ namespace YooAsset
/// 资源的定位地址
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location)
{
- return LoadSubAssetsInternal(location, typeof(TObject), false);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadSubAssetsInternal(assetPath, typeof(TObject), false);
}
///
@@ -477,21 +541,48 @@ namespace YooAsset
/// 子对象类型
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type)
{
- return LoadSubAssetsInternal(location, type, false);
+ string assetPath = _locationServices.ConvertLocationToAssetPath(location);
+ return LoadSubAssetsInternal(assetPath, type, false);
}
- private static AssetOperationHandle LoadAssetInternal(string location, System.Type assetType, bool waitForAsyncComplete)
+ private static RawFileOperation GetRawFileInternal(string assetPath, string copyPath)
+ {
+ string bundleName = _bundleServices.GetBundleName(assetPath);
+ BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
+
+ if (_playMode == EPlayMode.EditorPlayMode)
+ {
+ RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
+ OperationSystem.ProcessOperaiton(operation);
+ return operation;
+ }
+ else if (_playMode == EPlayMode.OfflinePlayMode)
+ {
+ RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
+ OperationSystem.ProcessOperaiton(operation);
+ return operation;
+ }
+ else if (_playMode == EPlayMode.HostPlayMode)
+ {
+ RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
+ OperationSystem.ProcessOperaiton(operation);
+ return operation;
+ }
+ else
+ {
+ throw new NotImplementedException();
+ }
+ }
+ private static AssetOperationHandle LoadAssetInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete)
{
- string assetPath = _locationServices.ConvertLocationToAssetPath(location);
var handle = AssetSystem.LoadAssetAsync(assetPath, assetType);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
}
- private static SubAssetsOperationHandle LoadSubAssetsInternal(string location, System.Type assetType, bool waitForAsyncComplete)
+ private static SubAssetsOperationHandle LoadSubAssetsInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete)
{
- string assetPath = _locationServices.ConvertLocationToAssetPath(location);
var handle = AssetSystem.LoadSubAssetsAsync(assetPath, assetType);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
@@ -562,10 +653,11 @@ namespace YooAsset
}
}
+
///
/// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件
///
- /// 资源列表
+ /// 资源定位列表
/// 同时下载的最大文件数
/// 下载失败的重试次数
public static PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
@@ -594,6 +686,38 @@ namespace YooAsset
throw new NotImplementedException();
}
}
+
+ ///
+ /// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件
+ ///
+ /// 资源信息列表
+ /// 同时下载的最大文件数
+ /// 下载失败的重试次数
+ public static PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
+ {
+ if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
+ {
+ List downloadList = new List();
+ var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
+ return operation;
+ }
+ else if (_playMode == EPlayMode.HostPlayMode)
+ {
+ if (_hostPlayModeImpl == null)
+ throw new Exception("YooAsset is not initialized.");
+
+ List assetPaths = new List(assetInfos.Length);
+ foreach (var assetInfo in assetInfos)
+ {
+ assetPaths.Add(assetInfo.AssetPath);
+ }
+ return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain);
+ }
+ else
+ {
+ throw new NotImplementedException();
+ }
+ }
#endregion
#region 资源解压