mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 12:10:09 +00:00
Compare commits
34 Commits
2.2.5-prev
...
2.2.7-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
748e74e515 | ||
|
|
d1d3ad9869 | ||
|
|
f9b72a22ae | ||
|
|
766cf90a19 | ||
|
|
8a2dc86cf7 | ||
|
|
5ca54b88fa | ||
|
|
7257c8778d | ||
|
|
dc21696ae1 | ||
|
|
7f566e5388 | ||
|
|
fe352ceb84 | ||
|
|
10750a0123 | ||
|
|
f2e6da649b | ||
|
|
9737cd06dd | ||
|
|
df8cf4d9ca | ||
|
|
36b4cbb8c2 | ||
|
|
bae84f65da | ||
|
|
313ec2d100 | ||
|
|
bfda5ec952 | ||
|
|
248bdba839 | ||
|
|
75dd3d0e5e | ||
|
|
8944ec0e02 | ||
|
|
25c5683a09 | ||
|
|
069e29ac07 | ||
|
|
942e4bf672 | ||
|
|
dca37a3794 | ||
|
|
f84419b7a6 | ||
|
|
aa3a049985 | ||
|
|
3f8c7bd91f | ||
|
|
11984d6972 | ||
|
|
31b0a3fb54 | ||
|
|
666d0b53a6 | ||
|
|
02250c3352 | ||
|
|
9e2030c83d | ||
|
|
be3fa0b688 |
@@ -2,6 +2,90 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.2.7-preview] - 2024-12-30
|
||||
|
||||
### Improvements
|
||||
|
||||
- 重构了下载器的委托方法。
|
||||
|
||||
- YooAssetSettings配置文件新增Package Manifest Prefix参数。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 资源清单前缀名称(默认为空)
|
||||
/// </summary>
|
||||
public string PackageManifestPrefix = string.Empty;
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#422) 修复了同步加载场景的NotImplementedException异常报错。
|
||||
- (#418) 修复了web远程文件系统初始化不正确的问题
|
||||
- (#392) 修复了引擎版本代码兼容相关的警告。
|
||||
- (#332) 修复了当用户的设备中有特殊字符时,URL路径无法被正确识别的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增代码字段:AsyncOperationBase.PackageName
|
||||
|
||||
### Changed
|
||||
|
||||
- 重命名DownloaderOperation.OnDownloadOver()方法为DownloaderFinish()
|
||||
- 重命名DownloaderOperation.OnDownloadProgress()方法为DownloadUpdate()
|
||||
- 重命名DownloaderOperation.OnDownloadError()方法为DownloadError()
|
||||
- 重命名DownloaderOperation.OnStartDownloadFile()方法为DownloadFileBegin()
|
||||
|
||||
## [2.2.6-preview] - 2024-12-27
|
||||
|
||||
### Improvements
|
||||
|
||||
- 增强了对Steam平台DLC拓展包的支持。
|
||||
|
||||
```csharp
|
||||
// 新增参数关闭Catalog目录查询内置文件的功能
|
||||
var fileSystemParams = CreateDefaultBuildinFileSystemParameters();
|
||||
fileSystemParams .AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
|
||||
```
|
||||
|
||||
- 资源句柄基类提供了统一的Release方法。
|
||||
|
||||
```csharp
|
||||
public abstract class HandleBase : IEnumerator, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release();
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose();
|
||||
}
|
||||
```
|
||||
|
||||
- 优化了场景卸载逻辑。
|
||||
|
||||
```csharp
|
||||
//框架内不在区分主场景和附加场景。
|
||||
//场景卸载后自动释放资源句柄。
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了Unity2020版本提示的脚本编译错误。
|
||||
- (#417) 修复了DefaultWebServerFileSystem文件系统内Catalog未起效的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增示例文件 GetCacheBundleSizeOperation.cs
|
||||
|
||||
可以获取指定Package的缓存资源总大小。
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了SceneHandle.IsMainScene()方法。
|
||||
|
||||
## [2.2.5-preview] - 2024-12-25
|
||||
|
||||
依赖的ScriptableBuildPipeline (SBP) 插件库版本切换为1.21.25版本!
|
||||
|
||||
@@ -56,11 +56,7 @@ namespace YooAsset.Editor
|
||||
public string EncryptedFilePath { set; get; }
|
||||
#endregion
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
private readonly HashSet<string> _assetPaths = new HashSet<string>(1000);
|
||||
#else
|
||||
private readonly HashSet<string> _assetPaths = new HashSet<string>();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 参与构建的资源列表
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
|
||||
buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
|
||||
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
|
||||
buildReport.Summary.BuildBundleType = buildParameters.BuildBundleType;
|
||||
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
|
||||
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
|
||||
buildReport.Summary.BuildPackageNote = buildParameters.PackageNote;
|
||||
@@ -115,7 +116,7 @@ namespace YooAsset.Editor
|
||||
buildReport.IndependAssets = new List<ReportIndependAsset>(buildMapContext.IndependAssets);
|
||||
|
||||
// 序列化文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetBuildReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
BuildReport.Serialize(filePath, buildReport);
|
||||
BuildLogger.Log($"Create build report file: {filePath}");
|
||||
|
||||
@@ -205,7 +205,9 @@ namespace YooAsset.Editor
|
||||
_packageListView = root.Q<ListView>("PackageListView");
|
||||
_packageListView.makeItem = MakePackageListViewItem;
|
||||
_packageListView.bindItem = BindPackageListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_packageListView.selectionChanged += PackageListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_packageListView.onSelectionChange += PackageListView_onSelectionChange;
|
||||
#else
|
||||
_packageListView.onSelectionChanged += PackageListView_onSelectionChange;
|
||||
@@ -250,7 +252,9 @@ namespace YooAsset.Editor
|
||||
_groupListView = root.Q<ListView>("GroupListView");
|
||||
_groupListView.makeItem = MakeGroupListViewItem;
|
||||
_groupListView.bindItem = BindGroupListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_groupListView.selectionChanged += GroupListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_groupListView.onSelectionChange += GroupListView_onSelectionChange;
|
||||
#else
|
||||
_groupListView.onSelectionChanged += GroupListView_onSelectionChange;
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace YooAsset.Editor
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_assetListView.selectionChanged += AssetListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
#else
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace YooAsset.Editor
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeBundleListViewItem;
|
||||
_bundleListView.bindItem = BindBundleListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_bundleListView.selectionChanged += BundleListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
#else
|
||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||
|
||||
@@ -38,6 +38,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string BuildPipeline;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的资源包类型
|
||||
/// </summary>
|
||||
public int BuildBundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 构建包裹名称
|
||||
/// </summary>
|
||||
|
||||
@@ -58,7 +58,9 @@ namespace YooAsset.Editor
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_assetListView.selectionChanged += AssetListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
#else
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
|
||||
@@ -66,7 +66,9 @@ namespace YooAsset.Editor
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeBundleListViewItem;
|
||||
_bundleListView.bindItem = BindBundleListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_bundleListView.selectionChanged += BundleListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
#else
|
||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace YooAsset.Editor
|
||||
_items.Add(new ItemWrapper("Build Seconds", ConvertTime(buildReport.Summary.BuildSeconds)));
|
||||
_items.Add(new ItemWrapper("Build Target", $"{buildReport.Summary.BuildTarget}"));
|
||||
_items.Add(new ItemWrapper("Build Pipeline", $"{buildReport.Summary.BuildPipeline}"));
|
||||
_items.Add(new ItemWrapper("Build Bundle Type", buildReport.Summary.BuildBundleType.ToString()));
|
||||
_items.Add(new ItemWrapper("Package Name", buildReport.Summary.BuildPackageName));
|
||||
_items.Add(new ItemWrapper("Package Version", buildReport.Summary.BuildPackageVersion));
|
||||
_items.Add(new ItemWrapper("Package Note", buildReport.Summary.BuildPackageNote));
|
||||
|
||||
@@ -25,26 +25,32 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string ConvertToWWWPath(string path)
|
||||
{
|
||||
string url;
|
||||
|
||||
// 获取对应平台的URL地址
|
||||
#if UNITY_EDITOR
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_WEBGL
|
||||
return path;
|
||||
url = path;
|
||||
#elif UNITY_IPHONE
|
||||
return StringUtility.Format("file://{0}", path);
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_ANDROID
|
||||
if (path.StartsWith("jar:file://"))
|
||||
return path;
|
||||
url = path;
|
||||
else
|
||||
return StringUtility.Format("jar:file://{0}", path);
|
||||
url = StringUtility.Format("jar:file://{0}", path);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
return new System.Uri(path).ToString();
|
||||
url = new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_OPENHARMONY
|
||||
return StringUtility.Format("file://{0}", path);
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
#else
|
||||
throw new System.NotImplementedException();
|
||||
throw new System.NotImplementedException();
|
||||
#endif
|
||||
|
||||
// For some special cases when users have special characters in their devices, url paths can not be identified correctly.
|
||||
return url.Replace("+", "%2B").Replace("#", "%23").Replace("?", "%3F");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +58,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static bool IsRequestLocalFile(string url)
|
||||
{
|
||||
//TODO : UNITY_STANDALONE_OSX平台目前无法确定
|
||||
//TODO UNITY_STANDALONE_OSX平台目前无法确定
|
||||
if (url.StartsWith("file:"))
|
||||
return true;
|
||||
if (url.StartsWith("jar:file:"))
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
//注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
@@ -104,6 +104,11 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO 场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalOnUpdate();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
_suspendLoad = false;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
// 注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
@@ -110,6 +110,11 @@ namespace YooAsset
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO 场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalOnUpdate();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
_suspendLoad = false;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace YooAsset
|
||||
// 重新尝试下载
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
//TODO : 拷贝本地文件失败后不再尝试!
|
||||
//TODO 拷贝本地文件失败后不再尝试!
|
||||
if (_isReuqestLocalFile)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -166,7 +166,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO : 防止下载器挂起陷入无限死循环!
|
||||
//TODO 防止下载器挂起陷入无限死循环!
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
InternalOnStart();
|
||||
@@ -174,7 +174,7 @@ namespace YooAsset
|
||||
|
||||
while (true)
|
||||
{
|
||||
//TODO : 如果是导入或解压本地文件,执行等待完毕
|
||||
//TODO 如果是导入或解压本地文件,执行等待完毕
|
||||
if (_isReuqestLocalFile)
|
||||
{
|
||||
InternalOnUpdate();
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace YooAsset
|
||||
// 重新尝试下载
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
//TODO : 拷贝本地文件失败后不再尝试!
|
||||
//TODO 拷贝本地文件失败后不再尝试!
|
||||
if (_isReuqestLocalFile)
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -188,7 +188,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO : 防止下载器挂起陷入无限死循环!
|
||||
//TODO 防止下载器挂起陷入无限死循环!
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
InternalOnStart();
|
||||
@@ -196,7 +196,7 @@ namespace YooAsset
|
||||
|
||||
while (true)
|
||||
{
|
||||
//TODO : 如果是导入或解压本地文件,执行等待完毕
|
||||
//TODO 如果是导入或解压本地文件,执行等待完毕
|
||||
if (_isReuqestLocalFile)
|
||||
{
|
||||
InternalOnUpdate();
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace YooAsset
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//TODO : 等待子线程验证文件完毕,该操作会挂起主线程
|
||||
//TODO 等待子线程验证文件完毕,该操作会挂起主线程
|
||||
InternalOnUpdate();
|
||||
if (IsDone)
|
||||
break;
|
||||
|
||||
@@ -63,6 +63,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool AppendFileExtension { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:禁用Catalog目录查询文件
|
||||
/// </summary>
|
||||
public bool DisableCatalogFile { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// </summary>
|
||||
@@ -138,6 +143,10 @@ namespace YooAsset
|
||||
{
|
||||
AppendFileExtension = (bool)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DISABLE_CATALOG_FILE)
|
||||
{
|
||||
DisableCatalogFile = (bool)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
@@ -172,10 +181,14 @@ namespace YooAsset
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
{
|
||||
if (DisableCatalogFile)
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
if (DisableCatalogFile)
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
@@ -306,7 +319,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// </summary>
|
||||
public bool RecordFile(string bundleGUID, FileWrapper wrapper)
|
||||
public bool RecordCatalogFile(string bundleGUID, FileWrapper wrapper)
|
||||
{
|
||||
if (_wrappers.ContainsKey(bundleGUID))
|
||||
{
|
||||
|
||||
@@ -48,7 +48,15 @@ namespace YooAsset
|
||||
|
||||
if (_initUnpackFIleSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadCatalogFile;
|
||||
if (_fileSystem.DisableCatalogFile)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadCatalogFile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace YooAsset
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
|
||||
@@ -133,11 +133,11 @@ namespace YooAsset
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
{
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
return true;
|
||||
return _wrappers.ContainsKey(bundle.BundleGUID);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
{
|
||||
@@ -201,9 +201,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// 记录内置文件信息
|
||||
/// </summary>
|
||||
public bool RecordFile(string bundleGUID, FileWrapper wrapper)
|
||||
public bool RecordCatalogFile(string bundleGUID, FileWrapper wrapper)
|
||||
{
|
||||
if (_wrappers.ContainsKey(bundleGUID))
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace YooAsset
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
|
||||
|
||||
140
Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs
Normal file
140
Assets/YooAsset/Runtime/FileSystem/FileSystemParameters.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件系统参数
|
||||
/// </summary>
|
||||
public class FileSystemParameters
|
||||
{
|
||||
internal readonly Dictionary<string, object> CreateParameters = new Dictionary<string, object>(100);
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统类
|
||||
/// 格式: "namespace.class,assembly"
|
||||
/// 格式: "命名空间.类型名,程序集"
|
||||
/// </summary>
|
||||
public string FileSystemClass { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统的根目录
|
||||
/// </summary>
|
||||
public string RootDirectory { private set; get; }
|
||||
|
||||
|
||||
public FileSystemParameters(string fileSystemClass, string rootDirectory)
|
||||
{
|
||||
FileSystemClass = fileSystemClass;
|
||||
RootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加自定义参数
|
||||
/// </summary>
|
||||
public void AddParameter(string name, object value)
|
||||
{
|
||||
CreateParameters.Add(name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件系统
|
||||
/// </summary>
|
||||
internal IFileSystem CreateFileSystem(string packageName)
|
||||
{
|
||||
YooLogger.Log($"The package {packageName} create file system : {FileSystemClass}");
|
||||
|
||||
Type classType = Type.GetType(FileSystemClass);
|
||||
if (classType == null)
|
||||
{
|
||||
YooLogger.Error($"Can not found file system class type {FileSystemClass}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var instance = (IFileSystem)System.Activator.CreateInstance(classType, true);
|
||||
if (instance == null)
|
||||
{
|
||||
YooLogger.Error($"Failed to create file system instance {FileSystemClass}");
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var param in CreateParameters)
|
||||
{
|
||||
instance.SetParameter(param.Key, param.Value);
|
||||
}
|
||||
instance.OnCreate(packageName, RootDirectory);
|
||||
return instance;
|
||||
}
|
||||
|
||||
#region 创建默认的文件系统类
|
||||
/// <summary>
|
||||
/// 创建默认的编辑器文件系统参数
|
||||
/// <param name="simulateBuildResult">模拟构建结果</param>
|
||||
/// </summary>
|
||||
public static FileSystemParameters CreateDefaultEditorFileSystemParameters(EditorSimulateBuildResult simulateBuildResult)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultEditorFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, simulateBuildResult.PackageRootDirectory);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的缓存文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的WebServer文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的WebRemote文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebRemoteFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ce5a2677e1696d488c3b883fa915ae0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,7 @@ namespace YooAsset
|
||||
public const string REMOTE_SERVICES = "REMOTE_SERVICES";
|
||||
public const string DECRYPTION_SERVICES = "DECRYPTION_SERVICES";
|
||||
public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION";
|
||||
public const string DISABLE_CATALOG_FILE = "DISABLE_CATALOG_FILE";
|
||||
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
|
||||
public const string DOWNLOAD_MAX_CONCURRENCY = "DOWNLOAD_MAX_CONCURRENCY";
|
||||
public const string DOWNLOAD_MAX_REQUEST_PER_FRAME = "DOWNLOAD_MAX_REQUEST_PER_FRAME";
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
@@ -29,111 +27,6 @@ namespace YooAsset
|
||||
WebPlayMode,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统参数
|
||||
/// </summary>
|
||||
public class FileSystemParameters
|
||||
{
|
||||
internal Dictionary<string, object> CreateParameters = new Dictionary<string, object>();
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统类
|
||||
/// 格式: "namespace.class,assembly"
|
||||
/// 格式: "命名空间.类型名,程序集"
|
||||
/// </summary>
|
||||
public string FileSystemClass { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统的根目录
|
||||
/// </summary>
|
||||
public string RootDirectory { private set; get; }
|
||||
|
||||
|
||||
public FileSystemParameters(string fileSystemClass, string rootDirectory)
|
||||
{
|
||||
FileSystemClass = fileSystemClass;
|
||||
RootDirectory = rootDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加自定义参数
|
||||
/// </summary>
|
||||
public void AddParameter(string name, object value)
|
||||
{
|
||||
CreateParameters.Add(name, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的编辑器文件系统参数
|
||||
/// <param name="simulateBuildResult">模拟构建结果</param>
|
||||
/// </summary>
|
||||
public static FileSystemParameters CreateDefaultEditorFileSystemParameters(EditorSimulateBuildResult simulateBuildResult)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultEditorFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, simulateBuildResult.PackageRootDirectory);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的缓存文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, verifyLevel);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的WebServer文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的WebRemote文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
|
||||
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, bool disableUnityWebCache = false)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化参数
|
||||
/// </summary>
|
||||
|
||||
@@ -42,6 +42,17 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public float Progress { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _packageName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
/// </summary>
|
||||
@@ -98,10 +109,6 @@ namespace YooAsset
|
||||
throw new System.NotImplementedException(this.GetType().Name);
|
||||
}
|
||||
|
||||
internal string GetPackageName()
|
||||
{
|
||||
return _packageName;
|
||||
}
|
||||
internal void SetPackageName(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace YooAsset
|
||||
// 终止临时队列里的任务
|
||||
foreach (var operation in _newList)
|
||||
{
|
||||
if (operation.GetPackageName() == packageName)
|
||||
if (operation.PackageName == packageName)
|
||||
{
|
||||
operation.SetAbort();
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace YooAsset
|
||||
// 终止正在进行的任务
|
||||
foreach (var operation in _operations)
|
||||
{
|
||||
if (operation.GetPackageName() == packageName)
|
||||
if (operation.PackageName == packageName)
|
||||
{
|
||||
operation.SetAbort();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class AllAssetsHandle : HandleBase, IDisposable
|
||||
public sealed class AllAssetsHandle : HandleBase
|
||||
{
|
||||
private System.Action<AllAssetsHandle> _callback;
|
||||
|
||||
@@ -47,23 +46,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class AssetHandle : HandleBase, IDisposable
|
||||
public sealed class AssetHandle : HandleBase
|
||||
{
|
||||
private System.Action<AssetHandle> _callback;
|
||||
|
||||
@@ -48,22 +46,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class HandleBase : IEnumerator
|
||||
public abstract class HandleBase : IEnumerator, IDisposable
|
||||
{
|
||||
private readonly AssetInfo _assetInfo;
|
||||
internal ProviderOperation Provider { private set; get; }
|
||||
@@ -15,6 +15,25 @@ namespace YooAsset
|
||||
}
|
||||
internal abstract void InvokeCallback();
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Release();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息
|
||||
/// </summary>
|
||||
@@ -121,17 +140,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放句柄
|
||||
/// </summary>
|
||||
internal void ReleaseInternal()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
#region 异步操作相关
|
||||
/// <summary>
|
||||
/// 异步操作任务
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class RawFileHandle : HandleBase, IDisposable
|
||||
public class RawFileHandle : HandleBase
|
||||
{
|
||||
private System.Action<RawFileHandle> _callback;
|
||||
|
||||
@@ -48,22 +45,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的二进制数据
|
||||
|
||||
@@ -112,25 +112,6 @@ namespace YooAsset
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景
|
||||
/// </summary>
|
||||
public bool IsMainScene()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (Provider is SceneProvider)
|
||||
{
|
||||
var temp = Provider as SceneProvider;
|
||||
return temp.SceneMode == LoadSceneMode.Single;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景
|
||||
/// </summary>
|
||||
@@ -147,17 +128,6 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 如果是主场景
|
||||
if (IsMainScene())
|
||||
{
|
||||
string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !";
|
||||
YooLogger.Error(error);
|
||||
var operation = new UnloadSceneOperation(error);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 卸载子场景
|
||||
// 注意:如果场景正在加载过程,必须等待加载完成后才可以卸载该场景。
|
||||
{
|
||||
var operation = new UnloadSceneOperation(Provider);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class SubAssetsHandle : HandleBase, IDisposable
|
||||
public sealed class SubAssetsHandle : HandleBase
|
||||
{
|
||||
private System.Action<SubAssetsHandle> _callback;
|
||||
|
||||
@@ -47,22 +46,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
@@ -106,14 +89,14 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
|
||||
List<TObject> ret = new List<TObject>(Provider.SubAssetObjects.Length);
|
||||
List<TObject> result = new List<TObject>(Provider.SubAssetObjects.Length);
|
||||
foreach (var assetObject in Provider.SubAssetObjects)
|
||||
{
|
||||
var retObject = assetObject as TObject;
|
||||
if (retObject != null)
|
||||
ret.Add(retObject);
|
||||
result.Add(retObject);
|
||||
}
|
||||
return ret.ToArray();
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
//TODO : 官方BUG
|
||||
//TODO 官方BUG
|
||||
// BUG环境:Windows平台,Unity2022.3.41f1版本,编辑器模式。
|
||||
// BUG描述:异步实例化Prefab预制体,有概率丢失Mono脚本里序列化的数组里某个成员!
|
||||
//_steps = ESteps.CloneAsync;
|
||||
|
||||
@@ -58,6 +58,9 @@ namespace YooAsset
|
||||
var loaderDic = _resManager._loaderDic;
|
||||
var providerDic = _resManager._providerDic;
|
||||
|
||||
// 清空所有场景句柄
|
||||
_resManager._sceneHandles.Clear();
|
||||
|
||||
// 释放所有资源句柄
|
||||
foreach (var provider in providerDic.Values)
|
||||
{
|
||||
@@ -79,7 +82,6 @@ namespace YooAsset
|
||||
// 清空数据
|
||||
providerDic.Clear();
|
||||
loaderDic.Clear();
|
||||
_resManager.ClearSceneHandle();
|
||||
|
||||
// 注意:调用底层接口释放所有资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
CheckError,
|
||||
PrepareDone,
|
||||
WaitDone,
|
||||
UnLoadScene,
|
||||
Done,
|
||||
}
|
||||
@@ -61,10 +61,10 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.PrepareDone;
|
||||
_steps = ESteps.WaitDone;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PrepareDone)
|
||||
if (_steps == ESteps.WaitDone)
|
||||
{
|
||||
if (_provider.IsDone == false)
|
||||
return;
|
||||
@@ -93,14 +93,19 @@ namespace YooAsset
|
||||
if (_asyncOp == null)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
|
||||
if (_asyncOp == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Unload scene failed, see the console logs !";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone == false)
|
||||
return;
|
||||
|
||||
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string ProviderGUID { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源系统
|
||||
/// </summary>
|
||||
public ResourceManager ResourceMgr { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
@@ -79,7 +74,6 @@ namespace YooAsset
|
||||
|
||||
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
|
||||
{
|
||||
ResourceMgr = manager;
|
||||
ProviderGUID = providerGUID;
|
||||
MainAssetInfo = assetInfo;
|
||||
|
||||
@@ -245,7 +239,7 @@ namespace YooAsset
|
||||
for (int i = _handles.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var handle = _handles[i];
|
||||
handle.ReleaseInternal();
|
||||
handle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,6 @@ namespace YooAsset
|
||||
private bool _suspendLoad;
|
||||
private FSLoadSceneOperation _loadSceneOp;
|
||||
|
||||
/// <summary>
|
||||
/// 场景加载模式
|
||||
/// </summary>
|
||||
public LoadSceneMode SceneMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _loadParams.loadSceneMode;
|
||||
}
|
||||
}
|
||||
|
||||
public SceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
_loadParams = loadParams;
|
||||
|
||||
@@ -9,12 +9,10 @@ namespace YooAsset
|
||||
{
|
||||
internal class ResourceManager
|
||||
{
|
||||
// 全局场景句柄集合
|
||||
private readonly static Dictionary<string, SceneHandle> _sceneHandles = new Dictionary<string, SceneHandle>(100);
|
||||
private static long _sceneCreateCount = 0;
|
||||
|
||||
internal readonly Dictionary<string, ProviderOperation> _providerDic = new Dictionary<string, ProviderOperation>(5000);
|
||||
internal readonly Dictionary<string, LoadBundleFileOperation> _loaderDic = new Dictionary<string, LoadBundleFileOperation>(5000);
|
||||
internal readonly List<SceneHandle> _sceneHandles = new List<SceneHandle>(100);
|
||||
private long _sceneCreateIndex = 0;
|
||||
private IBundleQuery _bundleQuery;
|
||||
|
||||
/// <summary>
|
||||
@@ -34,6 +32,15 @@ namespace YooAsset
|
||||
public void Initialize(InitializeParameters initializeParameters, IBundleQuery bundleServices)
|
||||
{
|
||||
_bundleQuery = bundleServices;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁管理器
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
{
|
||||
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,14 +100,8 @@ namespace YooAsset
|
||||
return completedProvider.CreateHandle<SceneHandle>();
|
||||
}
|
||||
|
||||
// 如果加载的是主场景,则卸载所有缓存的场景
|
||||
if (loadSceneParams.loadSceneMode == LoadSceneMode.Single)
|
||||
{
|
||||
UnloadAllScene();
|
||||
}
|
||||
|
||||
// 注意:同一个场景的ProviderGUID每次加载都会变化
|
||||
string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateCount}";
|
||||
string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateIndex}";
|
||||
ProviderOperation provider;
|
||||
{
|
||||
provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
|
||||
@@ -112,7 +113,7 @@ namespace YooAsset
|
||||
provider.Priority = priority;
|
||||
var handle = provider.CreateHandle<SceneHandle>();
|
||||
handle.PackageName = PackageName;
|
||||
_sceneHandles.Add(providerGUID, handle);
|
||||
_sceneHandles.Add(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -224,56 +225,6 @@ namespace YooAsset
|
||||
return provider.CreateHandle<RawFileHandle>();
|
||||
}
|
||||
|
||||
|
||||
internal void UnloadSubScene(string sceneName)
|
||||
{
|
||||
List<string> removeKeys = new List<string>();
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
var sceneHandle = valuePair.Value;
|
||||
if (sceneHandle.SceneName == sceneName)
|
||||
{
|
||||
// 释放子场景句柄
|
||||
sceneHandle.ReleaseInternal();
|
||||
removeKeys.Add(valuePair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string key in removeKeys)
|
||||
{
|
||||
_sceneHandles.Remove(key);
|
||||
}
|
||||
}
|
||||
internal void UnloadAllScene()
|
||||
{
|
||||
// 释放所有场景句柄
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
valuePair.Value.ReleaseInternal();
|
||||
}
|
||||
_sceneHandles.Clear();
|
||||
}
|
||||
internal void ClearSceneHandle()
|
||||
{
|
||||
// 释放资源包下的所有场景
|
||||
if (_bundleQuery.ManifestValid())
|
||||
{
|
||||
string packageName = PackageName;
|
||||
List<string> removeList = new List<string>();
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
if (valuePair.Value.PackageName == packageName)
|
||||
{
|
||||
removeList.Add(valuePair.Key);
|
||||
}
|
||||
}
|
||||
foreach (var key in removeList)
|
||||
{
|
||||
_sceneHandles.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal LoadBundleFileOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
|
||||
@@ -330,6 +281,25 @@ namespace YooAsset
|
||||
else
|
||||
return null;
|
||||
}
|
||||
private void OnSceneUnloaded(Scene scene)
|
||||
{
|
||||
List<SceneHandle> removeList = new List<SceneHandle>();
|
||||
foreach (var sceneHandle in _sceneHandles)
|
||||
{
|
||||
if (sceneHandle.IsValid)
|
||||
{
|
||||
if (sceneHandle.SceneObject == scene)
|
||||
{
|
||||
sceneHandle.Release();
|
||||
removeList.Add(sceneHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var sceneHandle in removeList)
|
||||
{
|
||||
_sceneHandles.Remove(sceneHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal List<DebugProviderInfo> GetDebugReportInfos()
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// </summary>
|
||||
public struct DownloaderFinishData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool Succeed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的更新数据
|
||||
/// </summary>
|
||||
public struct DownloadUpdateData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度 (0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件总数
|
||||
/// </summary>
|
||||
public int TotalDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载文件数量
|
||||
/// </summary>
|
||||
public int CurrentDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 下载数据总大小(单位:字节)
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载数据大小(单位:字节)
|
||||
/// </summary>
|
||||
public long CurrentDownloadBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的错误数据
|
||||
/// </summary>
|
||||
public struct DownloadErrorData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载失败的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的文件数据
|
||||
/// </summary>
|
||||
public struct DownloadFileData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6602c4be2ef295546b7bbb328de8fb0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,10 +15,27 @@ namespace YooAsset
|
||||
|
||||
private const int MAX_LOADER_COUNT = 64;
|
||||
|
||||
public delegate void OnDownloadOver(bool isSucceed);
|
||||
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
||||
public delegate void OnDownloadError(string fileName, string error);
|
||||
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
||||
#region 委托定义
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// </summary>
|
||||
public delegate void DownloaderFinish(DownloaderFinishData data);
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度更新
|
||||
/// </summary>
|
||||
public delegate void DownloadUpdate(DownloadUpdateData data);
|
||||
|
||||
/// <summary>
|
||||
/// 下载发生错误
|
||||
/// </summary>
|
||||
public delegate void DownloadError(DownloadErrorData data);
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载某个文件
|
||||
/// </summary>
|
||||
public delegate void DownloadFileBegin(DownloadFileData data);
|
||||
#endregion
|
||||
|
||||
private readonly string _packageName;
|
||||
private readonly int _downloadingMaxNumber;
|
||||
@@ -67,23 +84,23 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 当下载器结束(无论成功或失败)
|
||||
/// </summary>
|
||||
public OnDownloadOver OnDownloadOverCallback { set; get; }
|
||||
public DownloaderFinish DownloadFinishCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当下载进度发生变化
|
||||
/// </summary>
|
||||
public OnDownloadProgress OnDownloadProgressCallback { set; get; }
|
||||
public DownloadUpdate DownloadUpdateCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当某个文件下载失败
|
||||
/// 当下载器发生错误
|
||||
/// </summary>
|
||||
public OnDownloadError OnDownloadErrorCallback { set; get; }
|
||||
public DownloadError DownloadErrorCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当开始下载某个文件
|
||||
/// </summary>
|
||||
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
||||
|
||||
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
||||
|
||||
|
||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
@@ -160,7 +177,18 @@ namespace YooAsset
|
||||
_lastDownloadBytes = downloadBytes;
|
||||
_lastDownloadCount = _cachedDownloadCount;
|
||||
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
||||
OnDownloadProgressCallback?.Invoke(TotalDownloadCount, _lastDownloadCount, TotalDownloadBytes, _lastDownloadBytes);
|
||||
|
||||
if (DownloadUpdateCallback != null)
|
||||
{
|
||||
var data = new DownloadUpdateData();
|
||||
data.PackageName = _packageName;
|
||||
data.Progress = Progress;
|
||||
data.TotalDownloadCount = TotalDownloadCount;
|
||||
data.CurrentDownloadCount = _lastDownloadCount;
|
||||
data.TotalDownloadBytes = TotalDownloadBytes;
|
||||
data.CurrentDownloadBytes = _lastDownloadBytes;
|
||||
DownloadUpdateCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
|
||||
// 动态创建新的下载器到最大数量限制
|
||||
@@ -177,7 +205,15 @@ namespace YooAsset
|
||||
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
|
||||
_downloaders.Add(downloader);
|
||||
_bundleInfoList.RemoveAt(index);
|
||||
OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize);
|
||||
|
||||
if (DownloadFileBeginCallback != null)
|
||||
{
|
||||
var data = new DownloadFileData();
|
||||
data.PackageName = _packageName;
|
||||
data.FileName = bundleInfo.Bundle.BundleName;
|
||||
data.FileSize = bundleInfo.Bundle.FileSize;
|
||||
DownloadFileBeginCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,15 +227,37 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to download file : {bundleName}";
|
||||
OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.Error);
|
||||
OnDownloadOverCallback?.Invoke(false);
|
||||
|
||||
if (DownloadErrorCallback != null)
|
||||
{
|
||||
var data = new DownloadErrorData();
|
||||
data.PackageName = _packageName;
|
||||
data.FileName = bundleName;
|
||||
data.ErrorInfo = failedDownloader.Error;
|
||||
DownloadErrorCallback.Invoke(data);
|
||||
}
|
||||
|
||||
if (DownloadFinishCallback != null)
|
||||
{
|
||||
var data = new DownloaderFinishData();
|
||||
data.PackageName = _packageName;
|
||||
data.Succeed = false;
|
||||
DownloadFinishCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 结算成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
OnDownloadOverCallback?.Invoke(true);
|
||||
|
||||
if (DownloadFinishCallback != null)
|
||||
{
|
||||
var data = new DownloaderFinishData();
|
||||
data.PackageName = _packageName;
|
||||
data.Succeed = true;
|
||||
DownloadFinishCallback.Invoke(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.EditorFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.EditorFileSystemParameters);
|
||||
_impl.EditorFileSystem = _parameters.EditorFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.EditorFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -127,7 +127,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
|
||||
_impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -206,7 +206,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
|
||||
_impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.BuildinFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -249,7 +249,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.CacheFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.CacheFileSystemParameters);
|
||||
_impl.CacheFileSystem = _parameters.CacheFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.CacheFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -329,7 +329,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.WebServerFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebServerFileSystemParameters);
|
||||
_impl.WebServerFileSystem = _parameters.WebServerFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.WebServerFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -370,7 +370,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_impl.WebRemoteFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebRemoteFileSystemParameters);
|
||||
_impl.WebRemoteFileSystem = _parameters.WebRemoteFileSystemParameters.CreateFileSystem(_impl.PackageName);
|
||||
if (_impl.WebRemoteFileSystem == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -385,7 +385,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.InitWebRemoteFileSystem)
|
||||
{
|
||||
if (_initWebRemoteFileSystemOp == null)
|
||||
_initWebRemoteFileSystemOp = _impl.WebServerFileSystem.InitializeFileSystemAsync();
|
||||
_initWebRemoteFileSystemOp = _impl.WebRemoteFileSystem.InitializeFileSystemAsync();
|
||||
|
||||
Progress = _initWebRemoteFileSystemOp.Progress;
|
||||
if (_initWebRemoteFileSystemOp.IsDone == false)
|
||||
|
||||
@@ -5,32 +5,6 @@ namespace YooAsset
|
||||
{
|
||||
internal class PlayModeHelper
|
||||
{
|
||||
public static IFileSystem CreateFileSystem(string packageName, FileSystemParameters parameters)
|
||||
{
|
||||
YooLogger.Log($"The package {packageName} create file system : {parameters.FileSystemClass}");
|
||||
|
||||
Type classType = Type.GetType(parameters.FileSystemClass);
|
||||
if (classType == null)
|
||||
{
|
||||
YooLogger.Error($"Can not found file system class type {parameters.FileSystemClass}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var instance = (IFileSystem)System.Activator.CreateInstance(classType, true);
|
||||
if (instance == null)
|
||||
{
|
||||
YooLogger.Error($"Failed to create file system instance {parameters.FileSystemClass}");
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var param in parameters.CreateParameters)
|
||||
{
|
||||
instance.SetParameter(param.Key, param.Value);
|
||||
}
|
||||
instance.OnCreate(packageName, parameters.RootDirectory);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static List<BundleInfo> GetDownloadListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(1000);
|
||||
|
||||
@@ -57,7 +57,13 @@ namespace YooAsset
|
||||
_initializeError = string.Empty;
|
||||
_initializeStatus = EOperationStatus.None;
|
||||
|
||||
_resourceManager = null;
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
{
|
||||
_resourceManager.Destroy();
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
_bundleQuery = null;
|
||||
_playModeImpl = null;
|
||||
}
|
||||
@@ -74,6 +80,13 @@ namespace YooAsset
|
||||
// 检测初始化参数合法性
|
||||
CheckInitializeParameters(parameters);
|
||||
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
{
|
||||
_resourceManager.Destroy();
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
// 创建资源管理器
|
||||
InitializationOperation initializeOperation;
|
||||
_resourceManager = new ResourceManager(PackageName);
|
||||
@@ -196,7 +209,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// 请求最新的资源版本
|
||||
/// </summary>
|
||||
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
@@ -207,9 +220,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// 加载指定版本的资源清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
@@ -227,7 +240,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹资源
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">下载的包裹版本</param>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
@@ -257,8 +270,9 @@ namespace YooAsset
|
||||
return _playModeImpl.ClearCacheBundleFilesAsync(clearMode, clearParam);
|
||||
}
|
||||
|
||||
#region 包裹信息
|
||||
/// <summary>
|
||||
/// 获取当前激活包裹的版本信息
|
||||
/// 获取当前加载包裹的版本信息
|
||||
/// </summary>
|
||||
public string GetPackageVersion()
|
||||
{
|
||||
@@ -267,7 +281,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前激活包裹的备注信息
|
||||
/// 获取当前加载包裹的备注信息
|
||||
/// </summary>
|
||||
public string GetPackageNote()
|
||||
{
|
||||
@@ -276,13 +290,14 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前激活包裹的详细信息
|
||||
/// 获取当前加载包裹的详细信息
|
||||
/// </summary>
|
||||
public PackageDetails GetPackageDetails()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeImpl.ActiveManifest.GetPackageDetails();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源回收
|
||||
/// <summary>
|
||||
|
||||
@@ -6,10 +6,15 @@ namespace YooAsset
|
||||
internal class YooAssetSettings : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认的YooAsset文件夹名称
|
||||
/// YooAsset文件夹名称
|
||||
/// </summary>
|
||||
public string DefaultYooFolderName = "yoo";
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单前缀名称(默认为空)
|
||||
/// </summary>
|
||||
public string PackageManifestPrefix = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清单文件头标记
|
||||
|
||||
@@ -36,9 +36,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 获取构建报告文件名
|
||||
/// </summary>
|
||||
public static string GetReportFileName(string packageName, string packageVersion)
|
||||
public static string GetBuildReportFileName(string packageName, string packageVersion)
|
||||
{
|
||||
return $"{packageName}_{packageVersion}.report";
|
||||
if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
|
||||
return $"{packageName}_{packageVersion}.report";
|
||||
else
|
||||
return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.report";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,7 +49,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetManifestBinaryFileName(string packageName, string packageVersion)
|
||||
{
|
||||
return $"{packageName}_{packageVersion}.bytes";
|
||||
if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
|
||||
return $"{packageName}_{packageVersion}.bytes";
|
||||
else
|
||||
return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.bytes";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +60,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetManifestJsonFileName(string packageName, string packageVersion)
|
||||
{
|
||||
return $"{packageName}_{packageVersion}.json";
|
||||
if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
|
||||
return $"{packageName}_{packageVersion}.json";
|
||||
else
|
||||
return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.json";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,7 +71,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetPackageHashFileName(string packageName, string packageVersion)
|
||||
{
|
||||
return $"{packageName}_{packageVersion}.hash";
|
||||
if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
|
||||
return $"{packageName}_{packageVersion}.hash";
|
||||
else
|
||||
return $"{Setting.PackageManifestPrefix}_{packageName}_{packageVersion}.hash";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +82,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetPackageVersionFileName(string packageName)
|
||||
{
|
||||
return $"{packageName}.version";
|
||||
if (string.IsNullOrEmpty(Setting.PackageManifestPrefix))
|
||||
return $"{packageName}.version";
|
||||
else
|
||||
return $"{Setting.PackageManifestPrefix}_{packageName}.version";
|
||||
}
|
||||
|
||||
#region 路径相关
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ef838ec60c36249ba05eaa3c96273e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
|
||||
[DisplayName("定位地址: 文件名.智能尾缀")]
|
||||
public class AddressByFileNameAndExt : IAddressRule
|
||||
{
|
||||
public string GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
var ext = Path.GetExtension(data.AssetPath);
|
||||
if (ext == ".asset")
|
||||
{
|
||||
var a = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(data.AssetPath);
|
||||
if (a == null) return ".errortype";
|
||||
var type = a.GetType();
|
||||
var dt = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
return dt + $".{type.Name.ToLowerInvariant()}";
|
||||
}
|
||||
|
||||
return Path.GetFileName(data.AssetPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73aae15a0e1aec742a7e8f05755a2013
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d7171aa14ba0e649900533bfeed0edb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public static class HandleBaseExtension
|
||||
{
|
||||
public static bool IsSucceed(this HandleBase thisHandle)
|
||||
{
|
||||
return thisHandle.IsDone && thisHandle.Status == EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03c367406c5062c41ba3290201be20c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5280dfac6a481ee429c769ba5688c9d2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user