mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-21 07:50:20 +00:00
Compare commits
69 Commits
1.3.7
...
1.4.2-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
954e76ab33 | ||
|
|
82bda518c9 | ||
|
|
cdc5bcd31f | ||
|
|
61f6d480ae | ||
|
|
df6df3548c | ||
|
|
ac839450e2 | ||
|
|
4fa01e1a29 | ||
|
|
db2a45ec35 | ||
|
|
76c6f5cc1c | ||
|
|
339b519881 | ||
|
|
de2fab1370 | ||
|
|
fd4b6794cc | ||
|
|
f3e3f7cf85 | ||
|
|
dd824254a9 | ||
|
|
16943d4590 | ||
|
|
a95697088b | ||
|
|
f771a98f25 | ||
|
|
3b1a8beadf | ||
|
|
209e9d7705 | ||
|
|
de09a042e6 | ||
|
|
66cd491493 | ||
|
|
4a158319e5 | ||
|
|
b322a848ba | ||
|
|
4e759134bd | ||
|
|
5c16171781 | ||
|
|
08ad68d4a2 | ||
|
|
2ace30acd8 | ||
|
|
fc55b1be82 | ||
|
|
b287dfedcf | ||
|
|
d6984f0ad4 | ||
|
|
85cb1ed3f6 | ||
|
|
32b5240fcc | ||
|
|
7b9fda2298 | ||
|
|
15a605b677 | ||
|
|
f4a3fcece8 | ||
|
|
d67fc31c26 | ||
|
|
889000d8a8 | ||
|
|
e827e74cc7 | ||
|
|
45ca1ebf02 | ||
|
|
3a81d7babd | ||
|
|
a1d5949177 | ||
|
|
d7ae52160b | ||
|
|
e3fa33b9b5 | ||
|
|
ac251114ff | ||
|
|
824d1c1501 | ||
|
|
ac88fd5cf6 | ||
|
|
5197d42807 | ||
|
|
7a0f4caa9b | ||
|
|
5bf1d29edc | ||
|
|
2687466ed4 | ||
|
|
14512d6470 | ||
|
|
32268f5a4a | ||
|
|
81401ca0b8 | ||
|
|
688cc271d5 | ||
|
|
a290353cfa | ||
|
|
6038e7acd6 | ||
|
|
4abec5a389 | ||
|
|
a2b51a8044 | ||
|
|
19cb239746 | ||
|
|
7aab610be5 | ||
|
|
4ec5a126ac | ||
|
|
32643caf51 | ||
|
|
114ebab6ae | ||
|
|
d1463e1fc6 | ||
|
|
aa49980231 | ||
|
|
2696da092d | ||
|
|
5415d95f36 | ||
|
|
efa71c8bb7 | ||
|
|
d59df4c561 |
@@ -2,6 +2,62 @@
|
|||||||
|
|
||||||
All notable changes to this package will be documented in this file.
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [1.4.2-preview] - 2023-01-03
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了清单解析异步操作的进度条变化错误。
|
||||||
|
- 修复了更新资源清单错误计算超时时间的问题。
|
||||||
|
|
||||||
|
## [1.4.1-preview] - 2022-12-26
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了开启UniqueBundleName选项后,SBP构建报错的问题。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增了AssetsPackage.PreDownloadPackageAsync()方法
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 预下载指定版本的包裹资源
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="packageVersion">下载的包裹版本</param>
|
||||||
|
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||||
|
public PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout = 60)
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增了OperationHandleBase.GetDownloadReport()方法
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取下载报告
|
||||||
|
/// </summary>
|
||||||
|
public DownloadReport GetDownloadReport();
|
||||||
|
````
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 优化了资源清单更新流程,支持缓存下载的清单。
|
||||||
|
- 优化了清单文件的解析流程,支持分帧解析避免卡顿。
|
||||||
|
- 优化了缓存文件的验证流程,支持分帧处理。
|
||||||
|
- 初始化的时候支持覆盖安装检测,然后清理所有的缓存清单文件。
|
||||||
|
- ClearPackageUnusedCacheFilesAsync重名为ClearUnusedCacheFilesAsync
|
||||||
|
|
||||||
|
## [1.4.0-preview] - 2022-12-04
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- (#46)修复了资源包初始化失败之后,再次初始化发生异常的问题。
|
||||||
|
- 修复了在初始化失败的之后,销毁YooAssets会报异常的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 优化了资源收集界面,可以选择显示中文别名。
|
||||||
|
- **优化了补丁清单序列化方式,由文本数据修改为二进制数据。**
|
||||||
|
- 资源操作句柄增加using支持。
|
||||||
|
|
||||||
## [1.3.7] - 2022-11-26
|
## [1.3.7] - 2022-11-26
|
||||||
|
|
||||||
全新的太空战机Demo !
|
全新的太空战机Demo !
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace YooAsset.Editor
|
|||||||
var buildResult = builder.Run(buildParameters);
|
var buildResult = builder.Run(buildParameters);
|
||||||
if (buildResult.Success)
|
if (buildResult.Success)
|
||||||
{
|
{
|
||||||
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||||
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||||
return manifestFilePath;
|
return manifestFilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,8 +175,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
if (IsShaderAsset)
|
if (IsShaderAsset)
|
||||||
{
|
{
|
||||||
string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
_shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName(uniqueBundleName, packageName);
|
||||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -184,15 +183,16 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
IPackRule packRule = PackDirectory.StaticPackRule;
|
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||||
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
||||||
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
if (YooAssetSettingsData.Setting.RegularBundleName)
|
||||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
bundleName = EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||||
}
|
else
|
||||||
}
|
bundleName = EditorTools.GetRegularPath(bundleName).ToLower();
|
||||||
|
|
||||||
if (uniqueBundleName)
|
if (uniqueBundleName)
|
||||||
{
|
_shareBundleName = $"{packageName.ToLower()}_share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
if (string.IsNullOrEmpty(_shareBundleName) == false)
|
else
|
||||||
_shareBundleName = $"{packageName.ToLower()}_{_shareBundleName}";
|
_shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -200,12 +200,17 @@ namespace YooAsset.Editor
|
|||||||
if (IsRawAsset)
|
if (IsRawAsset)
|
||||||
{
|
{
|
||||||
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
|
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
|
||||||
_mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower();
|
_mainBundleName = mainBundleName.ToLower();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
_mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower(); ;
|
_mainBundleName = mainBundleName.ToLower(); ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uniqueBundleName)
|
||||||
|
{
|
||||||
|
_mainBundleName = $"{packageName.ToLower()}_{_mainBundleName}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,13 +182,14 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal PatchBundle CreatePatchBundle()
|
internal PatchBundle CreatePatchBundle()
|
||||||
{
|
{
|
||||||
string fileHash = PatchInfo.PatchFileHash;
|
PatchBundle patchBundle = new PatchBundle();
|
||||||
string fileCRC = PatchInfo.PatchFileCRC;
|
patchBundle.BundleName = BundleName;
|
||||||
long fileSize = PatchInfo.PatchFileSize;
|
patchBundle.FileHash = PatchInfo.PatchFileHash;
|
||||||
bool isRawFile = IsRawFile;
|
patchBundle.FileCRC = PatchInfo.PatchFileCRC;
|
||||||
byte loadMethod = (byte)LoadMethod;
|
patchBundle.FileSize = PatchInfo.PatchFileSize;
|
||||||
string[] tags = GetBundleTags();
|
patchBundle.IsRawFile = IsRawFile;
|
||||||
PatchBundle patchBundle = new PatchBundle(BundleName, fileHash, fileCRC, fileSize, isRawFile, loadMethod, tags);
|
patchBundle.LoadMethod = (byte)LoadMethod;
|
||||||
|
patchBundle.Tags = GetBundleTags();
|
||||||
return patchBundle;
|
return patchBundle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace YooAsset.Editor
|
|||||||
// 开始构建
|
// 开始构建
|
||||||
IBundleBuildResults buildResults;
|
IBundleBuildResults buildResults;
|
||||||
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
||||||
var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParametersContext.Parameters.PackageName);
|
||||||
var taskList = SBPBuildTasks.Create(shadersBunldeName);
|
var taskList = SBPBuildTasks.Create(shadersBunldeName);
|
||||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
||||||
if (exitCode < 0)
|
if (exitCode < 0)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 拷贝补丁清单文件
|
// 拷贝补丁清单文件
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(buildPackageName, buildPackageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildPackageName, buildPackageVersion);
|
||||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
@@ -53,7 +53,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 拷贝补丁清单哈希文件
|
// 拷贝补丁清单哈希文件
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestHashFileName(buildPackageName, buildPackageVersion);
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildPackageName, buildPackageVersion);
|
||||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
@@ -61,7 +61,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 拷贝补丁清单版本文件
|
// 拷贝补丁清单版本文件
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(buildPackageName);
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildPackageName);
|
||||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
|||||||
@@ -42,33 +42,42 @@ namespace YooAsset.Editor
|
|||||||
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
||||||
|
|
||||||
// 更新Unity内置资源包的引用关系
|
// 更新Unity内置资源包的引用关系
|
||||||
|
string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParameters.PackageName);
|
||||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
{
|
{
|
||||||
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
||||||
{
|
{
|
||||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||||
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
|
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results, shadersBunldeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建补丁清单文件
|
// 创建补丁清单文本文件
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||||
|
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
|
PatchManifestTools.SerializeToJson(filePath, patchManifest);
|
||||||
|
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建补丁清单二进制文件
|
||||||
string packageHash;
|
string packageHash;
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
PatchManifest.Serialize(filePath, patchManifest);
|
PatchManifestTools.SerializeToBinary(filePath, patchManifest);
|
||||||
packageHash = HashUtility.FileMD5(filePath);
|
packageHash = HashUtility.FileMD5(filePath);
|
||||||
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||||
|
|
||||||
var patchManifestContext = new PatchManifestContext();
|
PatchManifestContext patchManifestContext = new PatchManifestContext();
|
||||||
string jsonData = FileUtility.ReadFile(filePath);
|
byte[] bytesData = FileUtility.ReadAllBytes(filePath);
|
||||||
patchManifestContext.Manifest = PatchManifest.Deserialize(jsonData);
|
patchManifestContext.Manifest = PatchManifestTools.DeserializeFromBinary(bytesData);
|
||||||
context.SetContextObject(patchManifestContext);
|
context.SetContextObject(patchManifestContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建补丁清单哈希文件
|
// 创建补丁清单哈希文件
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
FileUtility.CreateFile(filePath, packageHash);
|
FileUtility.CreateFile(filePath, packageHash);
|
||||||
BuildRunner.Log($"创建补丁清单哈希文件:{filePath}");
|
BuildRunner.Log($"创建补丁清单哈希文件:{filePath}");
|
||||||
@@ -76,7 +85,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 创建补丁清单版本文件
|
// 创建补丁清单版本文件
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(buildParameters.PackageName);
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName);
|
||||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||||
FileUtility.CreateFile(filePath, buildParameters.PackageVersion);
|
FileUtility.CreateFile(filePath, buildParameters.PackageVersion);
|
||||||
BuildRunner.Log($"创建补丁清单版本文件:{filePath}");
|
BuildRunner.Log($"创建补丁清单版本文件:{filePath}");
|
||||||
@@ -157,10 +166,9 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新Unity内置资源包的引用关系
|
/// 更新Unity内置资源包的引用关系
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults)
|
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults, string shadersBunldeName)
|
||||||
{
|
{
|
||||||
// 获取所有依赖着色器资源包的资源包列表
|
// 获取所有依赖着色器资源包的资源包列表
|
||||||
string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
|
||||||
List<string> shaderBundleReferenceList = new List<string>();
|
List<string> shaderBundleReferenceList = new List<string>();
|
||||||
foreach (var valuePair in buildResults.BundleInfos)
|
foreach (var valuePair in buildResults.BundleInfos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace YooAsset.Editor
|
|||||||
// 4.更新补丁包输出的文件路径
|
// 4.更新补丁包输出的文件路径
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
string patchFileName = PatchManifest.CreateBundleFileName(outputNameStyle, bundleInfo.BundleName, bundleInfo.PatchInfo.PatchFileHash);
|
string patchFileName = PatchManifestTools.CreateBundleFileName(outputNameStyle, bundleInfo.BundleName, bundleInfo.PatchInfo.PatchFileHash, bundleInfo.IsRawFile);
|
||||||
bundleInfo.PatchInfo.PatchOutputFilePath = $"{packageOutputDirectory}/{patchFileName}";
|
bundleInfo.PatchInfo.PatchOutputFilePath = $"{packageOutputDirectory}/{patchFileName}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,23 +7,13 @@ namespace YooAsset.Editor
|
|||||||
public enum EOutputNameStyle
|
public enum EOutputNameStyle
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 000000000000000f000000000000000
|
/// 哈希值名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
HashName = 1,
|
HashName = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 000000000000000f000000000000000.bundle
|
/// 资源包名称 + 哈希值名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
HashName_Extension = 2,
|
BundleName_HashName = 4,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// bundle_name_000000000000000f000000000000000
|
|
||||||
/// </summary>
|
|
||||||
BundleName_HashName = 3,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// bundle_name_000000000000000f000000000000000.bundle
|
|
||||||
/// </summary>
|
|
||||||
BundleName_HashName_Extension = 4,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,12 +293,15 @@ namespace YooAsset.Editor
|
|||||||
// 根据规则设置获取资源包名称
|
// 根据规则设置获取资源包名称
|
||||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||||
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
|
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
|
||||||
return EditorTools.GetRegularPath(bundleName).ToLower();
|
if(YooAssetSettingsData.Setting.RegularBundleName)
|
||||||
|
return EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||||
|
else
|
||||||
|
return EditorTools.GetRegularPath(bundleName).ToLower();
|
||||||
}
|
}
|
||||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
List<string> tags = StringUtility.StringToStringList(group.AssetTags, ';');
|
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||||
List<string> temper = StringUtility.StringToStringList(AssetTags, ';');
|
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
|
||||||
tags.AddRange(temper);
|
tags.AddRange(temper);
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public class AssetBundleCollectorConfig
|
public class AssetBundleCollectorConfig
|
||||||
{
|
{
|
||||||
public const string ConfigVersion = "2.1";
|
public const string ConfigVersion = "2.2";
|
||||||
|
|
||||||
public const string XmlVersion = "Version";
|
public const string XmlVersion = "Version";
|
||||||
public const string XmlCommon = "Common";
|
public const string XmlCommon = "Common";
|
||||||
public const string XmlEnableAddressable = "AutoAddressable";
|
public const string XmlEnableAddressable = "AutoAddressable";
|
||||||
public const string XmlUniqueBundleName = "UniqueBundleName";
|
public const string XmlUniqueBundleName = "UniqueBundleName";
|
||||||
public const string XmlShowPackageView = "ShowPackageView";
|
public const string XmlShowPackageView = "ShowPackageView";
|
||||||
|
public const string XmlShowEditorAlias = "ShowEditorAlias";
|
||||||
|
|
||||||
public const string XmlPackage = "Package";
|
public const string XmlPackage = "Package";
|
||||||
public const string XmlPackageName = "PackageName";
|
public const string XmlPackageName = "PackageName";
|
||||||
@@ -65,6 +66,7 @@ namespace YooAsset.Editor
|
|||||||
bool enableAddressable = false;
|
bool enableAddressable = false;
|
||||||
bool uniqueBundleName = false;
|
bool uniqueBundleName = false;
|
||||||
bool showPackageView = false;
|
bool showPackageView = false;
|
||||||
|
bool showEditorAlias = false;
|
||||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||||
if (commonNodeList.Count > 0)
|
if (commonNodeList.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -75,10 +77,13 @@ namespace YooAsset.Editor
|
|||||||
throw new Exception($"Not found attribute {XmlUniqueBundleName} in {XmlCommon}");
|
throw new Exception($"Not found attribute {XmlUniqueBundleName} in {XmlCommon}");
|
||||||
if (commonElement.HasAttribute(XmlShowPackageView) == false)
|
if (commonElement.HasAttribute(XmlShowPackageView) == false)
|
||||||
throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}");
|
throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}");
|
||||||
|
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlShowEditorAlias} in {XmlCommon}");
|
||||||
|
|
||||||
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||||
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
|
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
|
||||||
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
|
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
|
||||||
|
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取包裹配置
|
// 读取包裹配置
|
||||||
@@ -138,7 +143,7 @@ namespace YooAsset.Editor
|
|||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
AssetBundleCollector collector = new AssetBundleCollector();
|
||||||
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
|
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
|
||||||
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
|
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
|
||||||
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
|
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
|
||||||
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
|
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
|
||||||
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
||||||
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
||||||
@@ -153,6 +158,7 @@ namespace YooAsset.Editor
|
|||||||
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
|
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
|
||||||
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
|
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
|
||||||
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
|
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
|
||||||
|
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
|
||||||
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
|
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
|
||||||
AssetBundleCollectorSettingData.SaveFile();
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
Debug.Log($"导入配置完毕!");
|
Debug.Log($"导入配置完毕!");
|
||||||
@@ -183,6 +189,7 @@ namespace YooAsset.Editor
|
|||||||
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
|
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
|
||||||
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
|
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
|
||||||
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
|
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
|
||||||
|
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
|
||||||
root.AppendChild(commonElement);
|
root.AppendChild(commonElement);
|
||||||
|
|
||||||
// 设置Package配置
|
// 设置Package配置
|
||||||
@@ -296,6 +303,23 @@ namespace YooAsset.Editor
|
|||||||
return UpdateXmlConfig(xmlDoc);
|
return UpdateXmlConfig(xmlDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2.1 -> 2.2
|
||||||
|
if (configVersion == "2.1")
|
||||||
|
{
|
||||||
|
// 添加公共元素属性
|
||||||
|
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||||
|
if (commonNodeList.Count > 0)
|
||||||
|
{
|
||||||
|
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||||
|
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
|
||||||
|
commonElement.SetAttribute(XmlShowEditorAlias, "False");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新版本
|
||||||
|
root.SetAttribute(XmlVersion, "2.2");
|
||||||
|
return UpdateXmlConfig(xmlDoc);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace YooAsset.Editor
|
|||||||
HashSet<string> result = new HashSet<string>();
|
HashSet<string> result = new HashSet<string>();
|
||||||
foreach (var group in Groups)
|
foreach (var group in Groups)
|
||||||
{
|
{
|
||||||
List<string> groupTags = StringUtility.StringToStringList(group.AssetTags, ';');
|
List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||||
foreach (var tag in groupTags)
|
foreach (var tag in groupTags)
|
||||||
{
|
{
|
||||||
if (result.Contains(tag) == false)
|
if (result.Contains(tag) == false)
|
||||||
@@ -111,7 +111,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
foreach (var collector in group.Collectors)
|
foreach (var collector in group.Collectors)
|
||||||
{
|
{
|
||||||
List<string> collectorTags = StringUtility.StringToStringList(collector.AssetTags, ';');
|
List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';');
|
||||||
foreach (var tag in collectorTags)
|
foreach (var tag in collectorTags)
|
||||||
{
|
{
|
||||||
if (result.Contains(tag) == false)
|
if (result.Contains(tag) == false)
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UniqueBundleName = false;
|
public bool UniqueBundleName = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示编辑器别名
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowEditorAlias = false;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹列表
|
/// 包裹列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -38,92 +38,6 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> GetActiveRuleNames()
|
|
||||||
{
|
|
||||||
if (_setting == null)
|
|
||||||
LoadSettingData();
|
|
||||||
|
|
||||||
List<string> names = new List<string>();
|
|
||||||
foreach (var pair in _cacheActiveRuleTypes)
|
|
||||||
{
|
|
||||||
names.Add(pair.Key);
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
public static List<string> GetAddressRuleNames()
|
|
||||||
{
|
|
||||||
if (_setting == null)
|
|
||||||
LoadSettingData();
|
|
||||||
|
|
||||||
List<string> names = new List<string>();
|
|
||||||
foreach (var pair in _cacheAddressRuleTypes)
|
|
||||||
{
|
|
||||||
names.Add(pair.Key);
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
public static List<string> GetPackRuleNames()
|
|
||||||
{
|
|
||||||
if (_setting == null)
|
|
||||||
LoadSettingData();
|
|
||||||
|
|
||||||
List<string> names = new List<string>();
|
|
||||||
foreach (var pair in _cachePackRuleTypes)
|
|
||||||
{
|
|
||||||
names.Add(pair.Key);
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
public static List<string> GetFilterRuleNames()
|
|
||||||
{
|
|
||||||
if (_setting == null)
|
|
||||||
LoadSettingData();
|
|
||||||
|
|
||||||
List<string> names = new List<string>();
|
|
||||||
foreach (var pair in _cacheFilterRuleTypes)
|
|
||||||
{
|
|
||||||
names.Add(pair.Key);
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
public static bool HasActiveRuleName(string ruleName)
|
|
||||||
{
|
|
||||||
foreach (var pair in _cacheActiveRuleTypes)
|
|
||||||
{
|
|
||||||
if (pair.Key == ruleName)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public static bool HasAddressRuleName(string ruleName)
|
|
||||||
{
|
|
||||||
foreach (var pair in _cacheAddressRuleTypes)
|
|
||||||
{
|
|
||||||
if (pair.Key == ruleName)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public static bool HasPackRuleName(string ruleName)
|
|
||||||
{
|
|
||||||
foreach (var pair in _cachePackRuleTypes)
|
|
||||||
{
|
|
||||||
if (pair.Key == ruleName)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public static bool HasFilterRuleName(string ruleName)
|
|
||||||
{
|
|
||||||
foreach (var pair in _cacheFilterRuleTypes)
|
|
||||||
{
|
|
||||||
if (pair.Key == ruleName)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载配置文件
|
/// 加载配置文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -146,6 +60,7 @@ namespace YooAsset.Editor
|
|||||||
typeof(PackCollector),
|
typeof(PackCollector),
|
||||||
typeof(PackGroup),
|
typeof(PackGroup),
|
||||||
typeof(PackRawFile),
|
typeof(PackRawFile),
|
||||||
|
typeof(PackShaderVariants)
|
||||||
};
|
};
|
||||||
|
|
||||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||||
@@ -266,7 +181,92 @@ namespace YooAsset.Editor
|
|||||||
SaveFile();
|
SaveFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实例类相关
|
public static List<RuleDisplayName> GetActiveRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||||
|
foreach (var pair in _cacheActiveRuleTypes)
|
||||||
|
{
|
||||||
|
RuleDisplayName ruleName = new RuleDisplayName();
|
||||||
|
ruleName.ClassName = pair.Key;
|
||||||
|
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||||
|
names.Add(ruleName);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
public static List<RuleDisplayName> GetAddressRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||||
|
foreach (var pair in _cacheAddressRuleTypes)
|
||||||
|
{
|
||||||
|
RuleDisplayName ruleName = new RuleDisplayName();
|
||||||
|
ruleName.ClassName = pair.Key;
|
||||||
|
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||||
|
names.Add(ruleName);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
public static List<RuleDisplayName> GetPackRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||||
|
foreach (var pair in _cachePackRuleTypes)
|
||||||
|
{
|
||||||
|
RuleDisplayName ruleName = new RuleDisplayName();
|
||||||
|
ruleName.ClassName = pair.Key;
|
||||||
|
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||||
|
names.Add(ruleName);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
public static List<RuleDisplayName> GetFilterRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||||
|
foreach (var pair in _cacheFilterRuleTypes)
|
||||||
|
{
|
||||||
|
RuleDisplayName ruleName = new RuleDisplayName();
|
||||||
|
ruleName.ClassName = pair.Key;
|
||||||
|
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||||
|
names.Add(ruleName);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
private static string GetRuleDisplayName(string name, Type type)
|
||||||
|
{
|
||||||
|
var attribute = EditorAttribute.GetAttribute<DisplayNameAttribute>(type);
|
||||||
|
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
|
||||||
|
return attribute.DisplayName;
|
||||||
|
else
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasActiveRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||||
|
}
|
||||||
|
public static bool HasAddressRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||||
|
}
|
||||||
|
public static bool HasPackRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||||
|
}
|
||||||
|
public static bool HasFilterRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||||
|
}
|
||||||
|
|
||||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||||
{
|
{
|
||||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||||
@@ -352,6 +352,11 @@ namespace YooAsset.Editor
|
|||||||
Setting.UniqueBundleName = uniqueBundleName;
|
Setting.UniqueBundleName = uniqueBundleName;
|
||||||
IsDirty = true;
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
|
public static void ModifyShowEditorAlias(bool showAlias)
|
||||||
|
{
|
||||||
|
Setting.ShowEditorAlias = showAlias;
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 资源包裹编辑相关
|
// 资源包裹编辑相关
|
||||||
public static AssetBundleCollectorPackage CreatePackage(string packageName)
|
public static AssetBundleCollectorPackage CreatePackage(string packageName)
|
||||||
|
|||||||
@@ -20,14 +20,15 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
private Button _saveButton;
|
private Button _saveButton;
|
||||||
private List<string> _collectorTypeList;
|
private List<string> _collectorTypeList;
|
||||||
private List<string> _activeRuleList;
|
private List<RuleDisplayName> _activeRuleList;
|
||||||
private List<string> _addressRuleList;
|
private List<RuleDisplayName> _addressRuleList;
|
||||||
private List<string> _packRuleList;
|
private List<RuleDisplayName> _packRuleList;
|
||||||
private List<string> _filterRuleList;
|
private List<RuleDisplayName> _filterRuleList;
|
||||||
|
|
||||||
private Toggle _showPackageToogle;
|
private Toggle _showPackageToogle;
|
||||||
private Toggle _enableAddressableToogle;
|
private Toggle _enableAddressableToogle;
|
||||||
private Toggle _uniqueBundleNameToogle;
|
private Toggle _uniqueBundleNameToogle;
|
||||||
|
private Toggle _showEditorAliasToggle;
|
||||||
|
|
||||||
private VisualElement _packageContainer;
|
private VisualElement _packageContainer;
|
||||||
private ListView _packageListView;
|
private ListView _packageListView;
|
||||||
@@ -42,7 +43,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
private VisualElement _collectorContainer;
|
private VisualElement _collectorContainer;
|
||||||
private ScrollView _collectorScrollView;
|
private ScrollView _collectorScrollView;
|
||||||
private PopupField<string> _activeRulePopupField;
|
private PopupField<RuleDisplayName> _activeRulePopupField;
|
||||||
|
|
||||||
private int _lastModifyPackageIndex = 0;
|
private int _lastModifyPackageIndex = 0;
|
||||||
private int _lastModifyGroupIndex = 0;
|
private int _lastModifyGroupIndex = 0;
|
||||||
@@ -95,6 +96,13 @@ namespace YooAsset.Editor
|
|||||||
RefreshWindow();
|
RefreshWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_showEditorAliasToggle = root.Q<Toggle>("ShowEditorAlias");
|
||||||
|
_showEditorAliasToggle.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleCollectorSettingData.ModifyShowEditorAlias(evt.newValue);
|
||||||
|
RefreshWindow();
|
||||||
|
});
|
||||||
|
|
||||||
// 配置修复按钮
|
// 配置修复按钮
|
||||||
var fixBtn = root.Q<Button>("FixButton");
|
var fixBtn = root.Q<Button>("FixButton");
|
||||||
fixBtn.clicked += FixBtn_clicked;
|
fixBtn.clicked += FixBtn_clicked;
|
||||||
@@ -236,21 +244,23 @@ namespace YooAsset.Editor
|
|||||||
// 分组激活规则
|
// 分组激活规则
|
||||||
var activeRuleContainer = root.Q("ActiveRuleContainer");
|
var activeRuleContainer = root.Q("ActiveRuleContainer");
|
||||||
{
|
{
|
||||||
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
|
_activeRulePopupField = new PopupField<RuleDisplayName>("Active Rule", _activeRuleList, 0);
|
||||||
_activeRulePopupField.name = "ActiveRuleMaskField";
|
_activeRulePopupField.name = "ActiveRuleMaskField";
|
||||||
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
activeRuleContainer.Add(_activeRulePopupField);
|
_activeRulePopupField.formatListItemCallback = FormatListItemCallback;
|
||||||
|
_activeRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||||
_activeRulePopupField.RegisterValueChangedCallback(evt =>
|
_activeRulePopupField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||||
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
if (selectPackage != null && selectGroup != null)
|
if (selectPackage != null && selectGroup != null)
|
||||||
{
|
{
|
||||||
selectGroup.ActiveRuleName = evt.newValue;
|
selectGroup.ActiveRuleName = evt.newValue.ClassName;
|
||||||
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
|
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
|
||||||
FillGroupViewData();
|
FillGroupViewData();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
activeRuleContainer.Add(_activeRulePopupField);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新窗体
|
// 刷新窗体
|
||||||
@@ -290,6 +300,9 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
_showPackageToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowPackageView);
|
_showPackageToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowPackageView);
|
||||||
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
|
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
|
||||||
|
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
|
||||||
|
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
|
||||||
|
|
||||||
_groupContainer.visible = false;
|
_groupContainer.visible = false;
|
||||||
_collectorContainer.visible = false;
|
_collectorContainer.visible = false;
|
||||||
|
|
||||||
@@ -321,6 +334,20 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
AssetBundleCollectorSettingData.SaveFile();
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
}
|
}
|
||||||
|
private string FormatListItemCallback(RuleDisplayName ruleDisplayName)
|
||||||
|
{
|
||||||
|
if (_showEditorAliasToggle.value)
|
||||||
|
return ruleDisplayName.DisplayName;
|
||||||
|
else
|
||||||
|
return ruleDisplayName.ClassName;
|
||||||
|
}
|
||||||
|
private string FormatSelectedValueCallback(RuleDisplayName ruleDisplayName)
|
||||||
|
{
|
||||||
|
if (_showEditorAliasToggle.value)
|
||||||
|
return ruleDisplayName.DisplayName;
|
||||||
|
else
|
||||||
|
return ruleDisplayName.ClassName;
|
||||||
|
}
|
||||||
|
|
||||||
// 包裹列表相关
|
// 包裹列表相关
|
||||||
private void FillPackageViewData()
|
private void FillPackageViewData()
|
||||||
@@ -334,7 +361,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
_packageListView.selectedIndex = _lastModifyPackageIndex;
|
_packageListView.selectedIndex = _lastModifyPackageIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_showPackageToogle.value)
|
if (_showPackageToogle.value)
|
||||||
_packageContainer.style.display = DisplayStyle.Flex;
|
_packageContainer.style.display = DisplayStyle.Flex;
|
||||||
else
|
else
|
||||||
@@ -410,7 +437,7 @@ namespace YooAsset.Editor
|
|||||||
_groupListView.itemsSource = selectPackage.Groups;
|
_groupListView.itemsSource = selectPackage.Groups;
|
||||||
_groupListView.Rebuild();
|
_groupListView.Rebuild();
|
||||||
|
|
||||||
if(_lastModifyGroupIndex >=0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
|
if (_lastModifyGroupIndex >= 0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
|
||||||
{
|
{
|
||||||
_groupListView.selectedIndex = _lastModifyGroupIndex;
|
_groupListView.selectedIndex = _lastModifyGroupIndex;
|
||||||
}
|
}
|
||||||
@@ -460,7 +487,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
_collectorContainer.visible = true;
|
_collectorContainer.visible = true;
|
||||||
_lastModifyGroupIndex = _groupListView.selectedIndex;
|
_lastModifyGroupIndex = _groupListView.selectedIndex;
|
||||||
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
|
_activeRulePopupField.SetValueWithoutNotify(GetActiveRuleIndex(selectGroup.ActiveRuleName));
|
||||||
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
||||||
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
||||||
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
||||||
@@ -564,21 +591,21 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
if (_enableAddressableToogle.value)
|
if (_enableAddressableToogle.value)
|
||||||
{
|
{
|
||||||
var popupField = new PopupField<string>(_addressRuleList, 0);
|
var popupField = new PopupField<RuleDisplayName>(_addressRuleList, 0);
|
||||||
popupField.name = "PopupField1";
|
popupField.name = "PopupField1";
|
||||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
popupField.style.width = 200;
|
popupField.style.width = 200;
|
||||||
elementBottom.Add(popupField);
|
elementBottom.Add(popupField);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var popupField = new PopupField<string>(_packRuleList, 0);
|
var popupField = new PopupField<RuleDisplayName>(_packRuleList, 0);
|
||||||
popupField.name = "PopupField2";
|
popupField.name = "PopupField2";
|
||||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
popupField.style.width = 150;
|
popupField.style.width = 230;
|
||||||
elementBottom.Add(popupField);
|
elementBottom.Add(popupField);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var popupField = new PopupField<string>(_filterRuleList, 0);
|
var popupField = new PopupField<RuleDisplayName>(_filterRuleList, 0);
|
||||||
popupField.name = "PopupField3";
|
popupField.name = "PopupField3";
|
||||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
popupField.style.width = 150;
|
popupField.style.width = 150;
|
||||||
@@ -667,7 +694,7 @@ namespace YooAsset.Editor
|
|||||||
popupField0.index = GetCollectorTypeIndex(collector.CollectorType.ToString());
|
popupField0.index = GetCollectorTypeIndex(collector.CollectorType.ToString());
|
||||||
popupField0.RegisterValueChangedCallback(evt =>
|
popupField0.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue);
|
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(evt.newValue);
|
||||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
if (foldout.value)
|
if (foldout.value)
|
||||||
{
|
{
|
||||||
@@ -676,13 +703,15 @@ namespace YooAsset.Editor
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Address Rule
|
// Address Rule
|
||||||
var popupField1 = element.Q<PopupField<string>>("PopupField1");
|
var popupField1 = element.Q<PopupField<RuleDisplayName>>("PopupField1");
|
||||||
if (popupField1 != null)
|
if (popupField1 != null)
|
||||||
{
|
{
|
||||||
popupField1.index = GetAddressRuleIndex(collector.AddressRuleName);
|
popupField1.index = GetAddressRuleIndex(collector.AddressRuleName);
|
||||||
|
popupField1.formatListItemCallback = FormatListItemCallback;
|
||||||
|
popupField1.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||||
popupField1.RegisterValueChangedCallback(evt =>
|
popupField1.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
collector.AddressRuleName = evt.newValue;
|
collector.AddressRuleName = evt.newValue.ClassName;
|
||||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
if (foldout.value)
|
if (foldout.value)
|
||||||
{
|
{
|
||||||
@@ -692,11 +721,13 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pack Rule
|
// Pack Rule
|
||||||
var popupField2 = element.Q<PopupField<string>>("PopupField2");
|
var popupField2 = element.Q<PopupField<RuleDisplayName>>("PopupField2");
|
||||||
popupField2.index = GetPackRuleIndex(collector.PackRuleName);
|
popupField2.index = GetPackRuleIndex(collector.PackRuleName);
|
||||||
|
popupField2.formatListItemCallback = FormatListItemCallback;
|
||||||
|
popupField2.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||||
popupField2.RegisterValueChangedCallback(evt =>
|
popupField2.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
collector.PackRuleName = evt.newValue;
|
collector.PackRuleName = evt.newValue.ClassName;
|
||||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
if (foldout.value)
|
if (foldout.value)
|
||||||
{
|
{
|
||||||
@@ -705,11 +736,13 @@ namespace YooAsset.Editor
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Filter Rule
|
// Filter Rule
|
||||||
var popupField3 = element.Q<PopupField<string>>("PopupField3");
|
var popupField3 = element.Q<PopupField<RuleDisplayName>>("PopupField3");
|
||||||
popupField3.index = GetFilterRuleIndex(collector.FilterRuleName);
|
popupField3.index = GetFilterRuleIndex(collector.FilterRuleName);
|
||||||
|
popupField3.formatListItemCallback = FormatListItemCallback;
|
||||||
|
popupField3.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||||
popupField3.RegisterValueChangedCallback(evt =>
|
popupField3.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
collector.FilterRuleName = evt.newValue;
|
collector.FilterRuleName = evt.newValue.ClassName;
|
||||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
if (foldout.value)
|
if (foldout.value)
|
||||||
{
|
{
|
||||||
@@ -815,7 +848,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < _addressRuleList.Count; i++)
|
for (int i = 0; i < _addressRuleList.Count; i++)
|
||||||
{
|
{
|
||||||
if (_addressRuleList[i] == ruleName)
|
if (_addressRuleList[i].ClassName == ruleName)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -824,7 +857,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < _packRuleList.Count; i++)
|
for (int i = 0; i < _packRuleList.Count; i++)
|
||||||
{
|
{
|
||||||
if (_packRuleList[i] == ruleName)
|
if (_packRuleList[i].ClassName == ruleName)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -833,11 +866,20 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < _filterRuleList.Count; i++)
|
for (int i = 0; i < _filterRuleList.Count; i++)
|
||||||
{
|
{
|
||||||
if (_filterRuleList[i] == ruleName)
|
if (_filterRuleList[i].ClassName == ruleName)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
private RuleDisplayName GetActiveRuleIndex(string ruleName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _activeRuleList.Count; i++)
|
||||||
|
{
|
||||||
|
if (_activeRuleList[i].ClassName == ruleName)
|
||||||
|
return _activeRuleList[i];
|
||||||
|
}
|
||||||
|
return _activeRuleList[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||||
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||||
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
|
<ui:Toggle label="Show Editor Alias" name="ShowEditorAlias" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
|
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|||||||
@@ -50,13 +50,5 @@ namespace YooAsset.Editor
|
|||||||
AssetTags = assetTags;
|
AssetTags = assetTags;
|
||||||
IsRawAsset = isRawAsset;
|
IsRawAsset = isRawAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源包名称追加包裹名
|
|
||||||
/// </summary>
|
|
||||||
public void BundleNameAppendPackageName(string packageName)
|
|
||||||
{
|
|
||||||
BundleName = $"{packageName.ToLower()}_{BundleName}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,14 +36,6 @@ namespace YooAsset.Editor
|
|||||||
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
||||||
{
|
{
|
||||||
CollectAssets = collectAssets;
|
CollectAssets = collectAssets;
|
||||||
|
|
||||||
if (UniqueBundleName)
|
|
||||||
{
|
|
||||||
foreach (var collectAsset in CollectAssets)
|
|
||||||
{
|
|
||||||
collectAsset.BundleNameAppendPackageName(PackageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[DisplayName("启用分组")]
|
||||||
/// 启用分组
|
|
||||||
/// </summary>
|
|
||||||
public class EnableGroup : IActiveRule
|
public class EnableGroup : IActiveRule
|
||||||
{
|
{
|
||||||
public bool IsActiveGroup()
|
public bool IsActiveGroup()
|
||||||
@@ -12,9 +10,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("禁用分组")]
|
||||||
/// 禁用分组
|
|
||||||
/// </summary>
|
|
||||||
public class DisableGroup : IActiveRule
|
public class DisableGroup : IActiveRule
|
||||||
{
|
{
|
||||||
public bool IsActiveGroup()
|
public bool IsActiveGroup()
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[DisplayName("以文件名称为定位地址")]
|
||||||
/// 以文件名为定位地址
|
|
||||||
/// </summary>
|
|
||||||
public class AddressByFileName : IAddressRule
|
public class AddressByFileName : IAddressRule
|
||||||
{
|
{
|
||||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
@@ -13,9 +11,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("以分组名称+文件名称为定位地址")]
|
||||||
/// 以组名+文件名为定位地址
|
|
||||||
/// </summary>
|
|
||||||
public class AddressByGroupAndFileName : IAddressRule
|
public class AddressByGroupAndFileName : IAddressRule
|
||||||
{
|
{
|
||||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
@@ -25,9 +21,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("以收集器名称+文件名称为定位地址")]
|
||||||
/// 以收集器名+文件名为定位地址
|
|
||||||
/// </summary>
|
|
||||||
public class AddressByCollectorAndFileName : IAddressRule
|
public class AddressByCollectorAndFileName : IAddressRule
|
||||||
{
|
{
|
||||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ using System.IO;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[DisplayName("收集所有资源")]
|
||||||
/// 收集所有资源
|
|
||||||
/// </summary>
|
|
||||||
public class CollectAll : IFilterRule
|
public class CollectAll : IFilterRule
|
||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
@@ -15,9 +13,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("收集场景")]
|
||||||
/// 只收集场景
|
|
||||||
/// </summary>
|
|
||||||
public class CollectScene : IFilterRule
|
public class CollectScene : IFilterRule
|
||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
@@ -25,10 +21,8 @@ namespace YooAsset.Editor
|
|||||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("收集预制体")]
|
||||||
/// 只收集预制体
|
|
||||||
/// </summary>
|
|
||||||
public class CollectPrefab : IFilterRule
|
public class CollectPrefab : IFilterRule
|
||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
@@ -37,15 +31,13 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("收集精灵类型的纹理")]
|
||||||
/// 只收集精灵类型的资源
|
|
||||||
/// </summary>
|
|
||||||
public class CollectSprite : IFilterRule
|
public class CollectSprite : IFilterRule
|
||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
{
|
{
|
||||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||||
if(mainAssetType == typeof(Texture2D))
|
if (mainAssetType == typeof(Texture2D))
|
||||||
{
|
{
|
||||||
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||||
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||||
@@ -60,9 +52,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[DisplayName("收集着色器变种集合")]
|
||||||
/// 只收集着色器变种收集文件
|
|
||||||
/// </summary>
|
|
||||||
public class CollectShaderVariants : IFilterRule
|
public class CollectShaderVariants : IFilterRule
|
||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ namespace YooAsset.Editor
|
|||||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
|
||||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("以文件路径作为资源包名")]
|
||||||
public class PackSeparately : IPackRule
|
public class PackSeparately : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
string bundleName = StringUtility.RemoveExtension(data.AssetPath);
|
return StringUtility.RemoveExtension(data.AssetPath);
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,14 +25,14 @@ namespace YooAsset.Editor
|
|||||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
|
||||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("以父类文件夹路径作为资源包名")]
|
||||||
public class PackDirectory : IPackRule
|
public class PackDirectory : IPackRule
|
||||||
{
|
{
|
||||||
public static PackDirectory StaticPackRule = new PackDirectory();
|
public static PackDirectory StaticPackRule = new PackDirectory();
|
||||||
|
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
return Path.GetDirectoryName(data.AssetPath);
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ namespace YooAsset.Editor
|
|||||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
|
||||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("以收集器路径下顶级文件夹为资源包名")]
|
||||||
public class PackTopDirectory : IPackRule
|
public class PackTopDirectory : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
@@ -55,7 +56,7 @@ namespace YooAsset.Editor
|
|||||||
if (Path.HasExtension(splits[0]))
|
if (Path.HasExtension(splits[0]))
|
||||||
throw new Exception($"Not found root directory : {assetPath}");
|
throw new Exception($"Not found root directory : {assetPath}");
|
||||||
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
return bundleName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -68,6 +69,7 @@ namespace YooAsset.Editor
|
|||||||
/// 以收集器路径作为资源包名
|
/// 以收集器路径作为资源包名
|
||||||
/// 注意:收集的所有文件打进一个资源包
|
/// 注意:收集的所有文件打进一个资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("以收集器路径作为资源包名")]
|
||||||
public class PackCollector : IPackRule
|
public class PackCollector : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
@@ -75,13 +77,11 @@ namespace YooAsset.Editor
|
|||||||
string collectPath = data.CollectPath;
|
string collectPath = data.CollectPath;
|
||||||
if (AssetDatabase.IsValidFolder(collectPath))
|
if (AssetDatabase.IsValidFolder(collectPath))
|
||||||
{
|
{
|
||||||
string bundleName = collectPath;
|
return collectPath;
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string bundleName = StringUtility.RemoveExtension(collectPath);
|
return StringUtility.RemoveExtension(collectPath);
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +90,7 @@ namespace YooAsset.Editor
|
|||||||
/// 以分组名称作为资源包名
|
/// 以分组名称作为资源包名
|
||||||
/// 注意:收集的所有文件打进一个资源包
|
/// 注意:收集的所有文件打进一个资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("以分组名称作为资源包名")]
|
||||||
public class PackGroup : IPackRule
|
public class PackGroup : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
@@ -99,9 +100,10 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 原生文件打包模式
|
/// 打包原生文件
|
||||||
/// 注意:原生文件打包支持:图片,音频,视频,文本
|
/// 注意:原生文件打包支持:图片,音频,视频,文本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("打包原生文件")]
|
||||||
public class PackRawFile : IPackRule
|
public class PackRawFile : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
@@ -120,14 +122,14 @@ namespace YooAsset.Editor
|
|||||||
if (depends.Length != 1)
|
if (depends.Length != 1)
|
||||||
throw new Exception($"{nameof(PackRawFile)} is not support estension : {extension}");
|
throw new Exception($"{nameof(PackRawFile)} is not support estension : {extension}");
|
||||||
|
|
||||||
string bundleName = data.AssetPath;
|
return data.AssetPath;
|
||||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 着色器变种收集文件
|
/// 打包着色器变种集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[DisplayName("打包着色器变种集合")]
|
||||||
public class PackShaderVariants : IPackRule
|
public class PackShaderVariants : IPackRule
|
||||||
{
|
{
|
||||||
public string GetBundleName(PackRuleData data)
|
public string GetBundleName(PackRuleData data)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class RuleDisplayName
|
||||||
|
{
|
||||||
|
public string ClassName;
|
||||||
|
public string DisplayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c4b754a3b15abc44fa2727f57721e18b
|
guid: df712711c3830af419b7ada8fee53dda
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -109,7 +109,7 @@ namespace YooAsset.Editor
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_reportFilePath = selectFilePath;
|
_reportFilePath = selectFilePath;
|
||||||
string jsonData = FileUtility.ReadFile(_reportFilePath);
|
string jsonData = FileUtility.ReadAllText(_reportFilePath);
|
||||||
_buildReport = BuildReport.Deserialize(jsonData);
|
_buildReport = BuildReport.Deserialize(jsonData);
|
||||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||||
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||||
|
|||||||
36
Assets/YooAsset/Editor/EditorAttribute.cs
Normal file
36
Assets/YooAsset/Editor/EditorAttribute.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器显示名字
|
||||||
|
/// </summary>
|
||||||
|
public class DisplayNameAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string DisplayName;
|
||||||
|
|
||||||
|
public DisplayNameAttribute(string name)
|
||||||
|
{
|
||||||
|
this.DisplayName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class EditorAttribute
|
||||||
|
{
|
||||||
|
internal static T GetAttribute<T>(Type type) where T : Attribute
|
||||||
|
{
|
||||||
|
return (T)type.GetCustomAttribute(typeof(T), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
|
||||||
|
{
|
||||||
|
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
|
||||||
|
{
|
||||||
|
return (T)field.GetCustomAttribute(typeof(T), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 223f217ed81460541b5ea7eb7a7d82a4
|
guid: 92d5f73b21059af43b7f56165b7acd63
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -285,6 +285,35 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region StringUtility
|
||||||
|
public static List<string> StringToStringList(string str, char separator)
|
||||||
|
{
|
||||||
|
List<string> result = new List<string>();
|
||||||
|
if (!String.IsNullOrEmpty(str))
|
||||||
|
{
|
||||||
|
string[] splits = str.Split(separator);
|
||||||
|
foreach (string split in splits)
|
||||||
|
{
|
||||||
|
string value = split.Trim(); //移除首尾空格
|
||||||
|
if (!String.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
result.Add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T NameToEnum<T>(string name)
|
||||||
|
{
|
||||||
|
if (Enum.IsDefined(typeof(T), name) == false)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Enum {typeof(T)} is not defined name {name}");
|
||||||
|
}
|
||||||
|
return (T)Enum.Parse(typeof(T), name);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 文件
|
#region 文件
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建文件所在的目录
|
/// 创建文件所在的目录
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace YooAsset
|
|||||||
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||||
private static long _sceneCreateCount = 0;
|
private static long _sceneCreateCount = 0;
|
||||||
|
|
||||||
|
private string _packageName;
|
||||||
private bool _simulationOnEditor;
|
private bool _simulationOnEditor;
|
||||||
private int _loadingMaxNumber;
|
private int _loadingMaxNumber;
|
||||||
public IDecryptionServices DecryptionServices { private set; get; }
|
public IDecryptionServices DecryptionServices { private set; get; }
|
||||||
@@ -23,8 +24,9 @@ namespace YooAsset
|
|||||||
/// 初始化
|
/// 初始化
|
||||||
/// 注意:在使用AssetSystem之前需要初始化
|
/// 注意:在使用AssetSystem之前需要初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
public void Initialize(string packageName, bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||||
{
|
{
|
||||||
|
_packageName = packageName;
|
||||||
_simulationOnEditor = simulationOnEditor;
|
_simulationOnEditor = simulationOnEditor;
|
||||||
_loadingMaxNumber = loadingMaxNumber;
|
_loadingMaxNumber = loadingMaxNumber;
|
||||||
DecryptionServices = decryptionServices;
|
DecryptionServices = decryptionServices;
|
||||||
@@ -73,15 +75,15 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
provider.Destroy();
|
provider.Destroy();
|
||||||
}
|
}
|
||||||
|
_providers.Clear();
|
||||||
|
|
||||||
foreach (var loader in _loaders)
|
foreach (var loader in _loaders)
|
||||||
{
|
{
|
||||||
loader.Destroy(true);
|
loader.Destroy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_providers.Clear();
|
|
||||||
_loaders.Clear();
|
_loaders.Clear();
|
||||||
ClearSceneHandle();
|
|
||||||
|
|
||||||
|
ClearSceneHandle();
|
||||||
DecryptionServices = null;
|
DecryptionServices = null;
|
||||||
BundleServices = null;
|
BundleServices = null;
|
||||||
}
|
}
|
||||||
@@ -184,7 +186,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
var handle = provider.CreateHandle<SceneOperationHandle>();
|
var handle = provider.CreateHandle<SceneOperationHandle>();
|
||||||
handle.PackageName = BundleServices.GetPackageName();
|
handle.PackageName = _packageName;
|
||||||
_sceneHandles.Add(providerGUID, handle);
|
_sceneHandles.Add(providerGUID, handle);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@@ -298,19 +300,21 @@ namespace YooAsset
|
|||||||
internal void ClearSceneHandle()
|
internal void ClearSceneHandle()
|
||||||
{
|
{
|
||||||
// 释放资源包下的所有场景
|
// 释放资源包下的所有场景
|
||||||
string packageName = BundleServices.GetPackageName();
|
if (BundleServices.IsServicesValid())
|
||||||
List<string> removeList = new List<string>();
|
|
||||||
foreach (var valuePair in _sceneHandles)
|
|
||||||
{
|
{
|
||||||
if (valuePair.Value.PackageName == packageName)
|
string packageName = _packageName;
|
||||||
|
List<string> removeList = new List<string>();
|
||||||
|
foreach (var valuePair in _sceneHandles)
|
||||||
{
|
{
|
||||||
removeList.Add(valuePair.Key);
|
if (valuePair.Value.PackageName == packageName)
|
||||||
|
{
|
||||||
|
removeList.Add(valuePair.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var key in removeList)
|
||||||
|
{
|
||||||
|
_sceneHandles.Remove(key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var key in removeList)
|
|
||||||
{
|
|
||||||
_sceneHandles.Remove(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public sealed class AssetOperationHandle : OperationHandleBase
|
public sealed class AssetOperationHandle : OperationHandleBase, IDisposable
|
||||||
{
|
{
|
||||||
private System.Action<AssetOperationHandle> _callback;
|
private System.Action<AssetOperationHandle> _callback;
|
||||||
|
|
||||||
@@ -37,6 +38,33 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 等待异步执行完毕
|
||||||
|
/// </summary>
|
||||||
|
public void WaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
if (IsValidWithWarning == false)
|
||||||
|
return;
|
||||||
|
Provider.WaitForAsyncComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放资源句柄
|
||||||
|
/// </summary>
|
||||||
|
public void Release()
|
||||||
|
{
|
||||||
|
this.ReleaseInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放资源句柄
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this.ReleaseInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源对象
|
/// 资源对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -61,25 +89,6 @@ namespace YooAsset
|
|||||||
return Provider.AssetObject as TAsset;
|
return Provider.AssetObject as TAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 等待异步执行完毕
|
|
||||||
/// </summary>
|
|
||||||
public void WaitForAsyncComplete()
|
|
||||||
{
|
|
||||||
if (IsValidWithWarning == false)
|
|
||||||
return;
|
|
||||||
Provider.WaitForAsyncComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 释放资源句柄
|
|
||||||
/// </summary>
|
|
||||||
public void Release()
|
|
||||||
{
|
|
||||||
this.ReleaseInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步初始化游戏对象
|
/// 同步初始化游戏对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal abstract void InvokeCallback();
|
internal abstract void InvokeCallback();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源信息
|
/// 获取资源信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,6 +23,18 @@ namespace YooAsset
|
|||||||
return _assetInfo;
|
return _assetInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取下载报告
|
||||||
|
/// </summary>
|
||||||
|
public DownloadReport GetDownloadReport()
|
||||||
|
{
|
||||||
|
if (IsValidWithWarning == false)
|
||||||
|
{
|
||||||
|
return DownloadReport.CreateDefaultReport();
|
||||||
|
}
|
||||||
|
return Provider.GetDownloadReport();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前状态
|
/// 当前状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public class RawFileOperationHandle : OperationHandleBase
|
public class RawFileOperationHandle : OperationHandleBase, IDisposable
|
||||||
{
|
{
|
||||||
private System.Action<RawFileOperationHandle> _callback;
|
private System.Action<RawFileOperationHandle> _callback;
|
||||||
|
|
||||||
@@ -54,7 +55,15 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
this.ReleaseInternal();
|
this.ReleaseInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放资源句柄
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this.ReleaseInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取原生文件的二进制数据
|
/// 获取原生文件的二进制数据
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public sealed class SubAssetsOperationHandle : OperationHandleBase
|
public sealed class SubAssetsOperationHandle : OperationHandleBase, IDisposable
|
||||||
{
|
{
|
||||||
private System.Action<SubAssetsOperationHandle> _callback;
|
private System.Action<SubAssetsOperationHandle> _callback;
|
||||||
|
|
||||||
@@ -36,19 +37,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 子资源对象集合
|
|
||||||
/// </summary>
|
|
||||||
public UnityEngine.Object[] AllAssetObjects
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsValidWithWarning == false)
|
|
||||||
return null;
|
|
||||||
return Provider.AllAssetObjects;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 等待异步执行完毕
|
/// 等待异步执行完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -67,6 +55,27 @@ namespace YooAsset
|
|||||||
this.ReleaseInternal();
|
this.ReleaseInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放资源句柄
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this.ReleaseInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子资源对象集合
|
||||||
|
/// </summary>
|
||||||
|
public UnityEngine.Object[] AllAssetObjects
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsValidWithWarning == false)
|
||||||
|
return null;
|
||||||
|
return Provider.AllAssetObjects;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取子资源对象
|
/// 获取子资源对象
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ namespace YooAsset
|
|||||||
// 2. 检测服务器下载结果
|
// 2. 检测服务器下载结果
|
||||||
if (_steps == ESteps.CheckDownload)
|
if (_steps == ESteps.CheckDownload)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _downloader.DownloadProgress;
|
||||||
|
DownloadedBytes = _downloader.DownloadedBytes;
|
||||||
if (_downloader.IsDone() == false)
|
if (_downloader.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.Unpack)
|
if (_steps == ESteps.Unpack)
|
||||||
{
|
{
|
||||||
int failedTryAgain = 1;
|
int failedTryAgain = 1;
|
||||||
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
|
var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
|
||||||
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||||
_steps = ESteps.CheckUnpack;
|
_steps = ESteps.CheckUnpack;
|
||||||
}
|
}
|
||||||
@@ -116,6 +118,8 @@ namespace YooAsset
|
|||||||
// 4.检测内置文件解压结果
|
// 4.检测内置文件解压结果
|
||||||
if (_steps == ESteps.CheckUnpack)
|
if (_steps == ESteps.CheckUnpack)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _unpacker.DownloadProgress;
|
||||||
|
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||||
if (_unpacker.IsDone() == false)
|
if (_unpacker.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -146,6 +150,10 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 设置下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||||
|
|
||||||
// Load assetBundle file
|
// Load assetBundle file
|
||||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||||
if (loadMethod == EBundleLoadMethod.Normal)
|
if (loadMethod == EBundleLoadMethod.Normal)
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ namespace YooAsset
|
|||||||
// 2. 检测服务器下载结果
|
// 2. 检测服务器下载结果
|
||||||
if (_steps == ESteps.CheckDownload)
|
if (_steps == ESteps.CheckDownload)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _downloader.DownloadProgress;
|
||||||
|
DownloadedBytes = _downloader.DownloadedBytes;
|
||||||
if (_downloader.IsDone() == false)
|
if (_downloader.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -106,6 +108,10 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 设置下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||||
|
|
||||||
// Load assetBundle file
|
// Load assetBundle file
|
||||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||||
if (loadMethod == EBundleLoadMethod.Normal)
|
if (loadMethod == EBundleLoadMethod.Normal)
|
||||||
@@ -171,6 +177,8 @@ namespace YooAsset
|
|||||||
// 6. 检测AssetBundle加载结果
|
// 6. 检测AssetBundle加载结果
|
||||||
if (_steps == ESteps.CheckLoadWebFile)
|
if (_steps == ESteps.CheckLoadWebFile)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = _webRequest.downloadedBytes;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace YooAsset
|
|||||||
/// 所属资源系统
|
/// 所属资源系统
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetSystemImpl Impl { private set; get; }
|
public AssetSystemImpl Impl { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包文件信息
|
/// 资源包文件信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,7 +47,9 @@ namespace YooAsset
|
|||||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
||||||
internal AssetBundle CacheBundle { set; get; }
|
internal AssetBundle CacheBundle { set; get; }
|
||||||
internal string FileLoadPath { set; get; }
|
internal string FileLoadPath { set; get; }
|
||||||
|
internal float DownloadProgress { set; get; }
|
||||||
|
internal ulong DownloadedBytes { set; get; }
|
||||||
|
|
||||||
|
|
||||||
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
|
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
|
||||||
{
|
{
|
||||||
@@ -82,34 +84,6 @@ namespace YooAsset
|
|||||||
RefCount--;
|
RefCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 轮询更新
|
|
||||||
/// </summary>
|
|
||||||
public abstract void Update();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 销毁
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Destroy(bool forceDestroy)
|
|
||||||
{
|
|
||||||
IsDestroyed = true;
|
|
||||||
|
|
||||||
// Check fatal
|
|
||||||
if (forceDestroy == false)
|
|
||||||
{
|
|
||||||
if (RefCount > 0)
|
|
||||||
throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}");
|
|
||||||
if (IsDone() == false)
|
|
||||||
throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CacheBundle != null)
|
|
||||||
{
|
|
||||||
CacheBundle.Unload(true);
|
|
||||||
CacheBundle = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否完毕(无论成功或失败)
|
/// 是否完毕(无论成功或失败)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -159,6 +133,35 @@ namespace YooAsset
|
|||||||
_providers.Clear();
|
_providers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 轮询更新
|
||||||
|
/// </summary>
|
||||||
|
public abstract void Update();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销毁
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Destroy(bool forceDestroy)
|
||||||
|
{
|
||||||
|
IsDestroyed = true;
|
||||||
|
|
||||||
|
// Check fatal
|
||||||
|
if (forceDestroy == false)
|
||||||
|
{
|
||||||
|
if (RefCount > 0)
|
||||||
|
throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}");
|
||||||
|
if (IsDone() == false)
|
||||||
|
throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CacheBundle != null)
|
||||||
|
{
|
||||||
|
CacheBundle.Unload(true);
|
||||||
|
CacheBundle = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主线程等待异步操作完毕
|
/// 主线程等待异步操作完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源包加载器列表
|
/// 依赖的资源包加载器列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly List<BundleLoaderBase> _dependBundles;
|
internal readonly List<BundleLoaderBase> DependBundles;
|
||||||
|
|
||||||
|
|
||||||
public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
|
public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
|
||||||
{
|
{
|
||||||
_dependBundles = dpendBundles;
|
DependBundles = dpendBundles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -22,7 +22,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDone()
|
public bool IsDone()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
if (loader.IsDone() == false)
|
if (loader.IsDone() == false)
|
||||||
return false;
|
return false;
|
||||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSucceed()
|
public bool IsSucceed()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetLastError()
|
public string GetLastError()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void WaitForAsyncComplete()
|
public void WaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
if (loader.IsDone() == false)
|
if (loader.IsDone() == false)
|
||||||
loader.WaitForAsyncComplete();
|
loader.WaitForAsyncComplete();
|
||||||
@@ -77,7 +77,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Reference()
|
public void Reference()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
loader.Reference();
|
loader.Reference();
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Release()
|
public void Release()
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
loader.Release();
|
loader.Release();
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
|
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
|
||||||
{
|
{
|
||||||
foreach (var loader in _dependBundles)
|
foreach (var loader in DependBundles)
|
||||||
{
|
{
|
||||||
var bundleInfo = new DebugBundleInfo();
|
var bundleInfo = new DebugBundleInfo();
|
||||||
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;
|
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ namespace YooAsset
|
|||||||
// 2. 检测下载结果
|
// 2. 检测下载结果
|
||||||
if (_steps == ESteps.CheckDownload)
|
if (_steps == ESteps.CheckDownload)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _downloader.DownloadProgress;
|
||||||
|
DownloadedBytes = _downloader.DownloadedBytes;
|
||||||
if (_downloader.IsDone() == false)
|
if (_downloader.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.Unpack)
|
if (_steps == ESteps.Unpack)
|
||||||
{
|
{
|
||||||
int failedTryAgain = 1;
|
int failedTryAgain = 1;
|
||||||
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
|
var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
|
||||||
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||||
_steps = ESteps.CheckUnpack;
|
_steps = ESteps.CheckUnpack;
|
||||||
}
|
}
|
||||||
@@ -99,6 +101,8 @@ namespace YooAsset
|
|||||||
// 4. 检测解压结果
|
// 4. 检测解压结果
|
||||||
if (_steps == ESteps.CheckUnpack)
|
if (_steps == ESteps.CheckUnpack)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _unpacker.DownloadProgress;
|
||||||
|
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||||
if (_unpacker.IsDone() == false)
|
if (_unpacker.IsDone() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -117,6 +121,10 @@ namespace YooAsset
|
|||||||
// 5. 检测结果
|
// 5. 检测结果
|
||||||
if (_steps == ESteps.CheckFile)
|
if (_steps == ESteps.CheckFile)
|
||||||
{
|
{
|
||||||
|
// 设置下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
if (File.Exists(FileLoadPath))
|
if (File.Exists(FileLoadPath))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,15 +7,6 @@ namespace YooAsset
|
|||||||
internal sealed class BundledAssetProvider : BundledProvider
|
internal sealed class BundledAssetProvider : BundledProvider
|
||||||
{
|
{
|
||||||
private AssetBundleRequest _cacheRequest;
|
private AssetBundleRequest _cacheRequest;
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_cacheRequest == null)
|
|
||||||
return 0;
|
|
||||||
return _cacheRequest.progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BundledAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public BundledAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
@@ -109,6 +100,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Progress = _cacheRequest.progress;
|
||||||
if (_cacheRequest.isDone == false)
|
if (_cacheRequest.isDone == false)
|
||||||
return;
|
return;
|
||||||
AssetObject = _cacheRequest.asset;
|
AssetObject = _cacheRequest.asset;
|
||||||
|
|||||||
@@ -35,6 +35,23 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取下载报告
|
||||||
|
/// </summary>
|
||||||
|
public override DownloadReport GetDownloadReport()
|
||||||
|
{
|
||||||
|
DownloadReport result = new DownloadReport();
|
||||||
|
result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
|
||||||
|
result.DownloadedBytes = OwnerBundle.DownloadedBytes;
|
||||||
|
foreach (var dependBundle in DependBundleGroup.DependBundles)
|
||||||
|
{
|
||||||
|
result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
|
||||||
|
result.DownloadedBytes += dependBundle.DownloadedBytes;
|
||||||
|
}
|
||||||
|
result.Progress = result.DownloadedBytes / result.TotalSize;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源包的调试信息列表
|
/// 获取资源包的调试信息列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -3,17 +3,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal class BundledRawFileProvider : BundledProvider
|
internal class BundledRawFileProvider : BundledProvider
|
||||||
{
|
{
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return 1f;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,15 +13,6 @@ namespace YooAsset
|
|||||||
private readonly bool _activateOnLoad;
|
private readonly bool _activateOnLoad;
|
||||||
private readonly int _priority;
|
private readonly int _priority;
|
||||||
private AsyncOperation _asyncOp;
|
private AsyncOperation _asyncOp;
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_asyncOp == null)
|
|
||||||
return 0;
|
|
||||||
return _asyncOp.progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
|
public BundledSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
@@ -93,6 +84,7 @@ namespace YooAsset
|
|||||||
// 3. 检测加载结果
|
// 3. 检测加载结果
|
||||||
if (Status == EStatus.Checking)
|
if (Status == EStatus.Checking)
|
||||||
{
|
{
|
||||||
|
Progress = _asyncOp.progress;
|
||||||
if (_asyncOp.isDone)
|
if (_asyncOp.isDone)
|
||||||
{
|
{
|
||||||
if (SceneObject.IsValid() && _activateOnLoad)
|
if (SceneObject.IsValid() && _activateOnLoad)
|
||||||
|
|||||||
@@ -7,15 +7,6 @@ namespace YooAsset
|
|||||||
internal sealed class BundledSubAssetsProvider : BundledProvider
|
internal sealed class BundledSubAssetsProvider : BundledProvider
|
||||||
{
|
{
|
||||||
private AssetBundleRequest _cacheRequest;
|
private AssetBundleRequest _cacheRequest;
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_cacheRequest == null)
|
|
||||||
return 0;
|
|
||||||
return _cacheRequest.progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BundledSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public BundledSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
@@ -98,6 +89,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Progress = _cacheRequest.progress;
|
||||||
if (_cacheRequest.isDone == false)
|
if (_cacheRequest.isDone == false)
|
||||||
return;
|
return;
|
||||||
AllAssetObjects = _cacheRequest.allAssets;
|
AllAssetObjects = _cacheRequest.allAssets;
|
||||||
|
|||||||
@@ -3,17 +3,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal sealed class CompletedProvider : ProviderBase
|
internal sealed class CompletedProvider : ProviderBase
|
||||||
{
|
{
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return 1f;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
|
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal sealed class DatabaseAssetProvider : ProviderBase
|
internal sealed class DatabaseAssetProvider : ProviderBase
|
||||||
{
|
{
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return 1f;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public DatabaseAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal class DatabaseRawFileProvider : ProviderBase
|
internal class DatabaseRawFileProvider : ProviderBase
|
||||||
{
|
{
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return 1f;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,6 @@ namespace YooAsset
|
|||||||
private readonly bool _activateOnLoad;
|
private readonly bool _activateOnLoad;
|
||||||
private readonly int _priority;
|
private readonly int _priority;
|
||||||
private AsyncOperation _asyncOp;
|
private AsyncOperation _asyncOp;
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_asyncOp == null)
|
|
||||||
return 0;
|
|
||||||
return _asyncOp.progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
|
public DatabaseSceneProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
@@ -61,6 +52,7 @@ namespace YooAsset
|
|||||||
// 2. 检测加载结果
|
// 2. 检测加载结果
|
||||||
if (Status == EStatus.Checking)
|
if (Status == EStatus.Checking)
|
||||||
{
|
{
|
||||||
|
Progress = _asyncOp.progress;
|
||||||
if (_asyncOp.isDone)
|
if (_asyncOp.isDone)
|
||||||
{
|
{
|
||||||
if (SceneObject.IsValid() && _activateOnLoad)
|
if (SceneObject.IsValid() && _activateOnLoad)
|
||||||
|
|||||||
@@ -6,17 +6,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal sealed class DatabaseSubAssetsProvider : ProviderBase
|
internal sealed class DatabaseSubAssetsProvider : ProviderBase
|
||||||
{
|
{
|
||||||
public override float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return 1f;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
public DatabaseSubAssetsProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string LastError { protected set; get; } = string.Empty;
|
public string LastError { protected set; get; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载进度
|
||||||
|
/// </summary>
|
||||||
|
public float Progress { protected set; get; } = 0f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引用计数
|
/// 引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -84,17 +89,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载进度
|
|
||||||
/// </summary>
|
|
||||||
public virtual float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected bool IsWaitForAsyncComplete { private set; get; } = false;
|
protected bool IsWaitForAsyncComplete { private set; get; } = false;
|
||||||
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
|
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
|
||||||
@@ -120,6 +114,14 @@ namespace YooAsset
|
|||||||
IsDestroyed = true;
|
IsDestroyed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取下载进度
|
||||||
|
/// </summary>
|
||||||
|
public virtual DownloadReport GetDownloadReport()
|
||||||
|
{
|
||||||
|
return DownloadReport.CreateDefaultReport();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否可以销毁
|
/// 是否可以销毁
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -219,6 +221,9 @@ namespace YooAsset
|
|||||||
private TaskCompletionSource<object> _taskCompletionSource;
|
private TaskCompletionSource<object> _taskCompletionSource;
|
||||||
protected void InvokeCompletion()
|
protected void InvokeCompletion()
|
||||||
{
|
{
|
||||||
|
// 进度百分百完成
|
||||||
|
Progress = 1f;
|
||||||
|
|
||||||
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
|
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
|
||||||
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
|
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
|
||||||
foreach (var hande in tempers)
|
foreach (var hande in tempers)
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ namespace YooAsset
|
|||||||
private EOperationStatus _initializeStatus = EOperationStatus.None;
|
private EOperationStatus _initializeStatus = EOperationStatus.None;
|
||||||
private EPlayMode _playMode;
|
private EPlayMode _playMode;
|
||||||
private IBundleServices _bundleServices;
|
private IBundleServices _bundleServices;
|
||||||
|
private IPlayModeServices _playModeServices;
|
||||||
private AssetSystemImpl _assetSystemImpl;
|
private AssetSystemImpl _assetSystemImpl;
|
||||||
private EditorSimulateModeImpl _editorSimulateModeImpl;
|
|
||||||
private OfflinePlayModeImpl _offlinePlayModeImpl;
|
|
||||||
private HostPlayModeImpl _hostPlayModeImpl;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹名
|
/// 包裹名
|
||||||
@@ -59,11 +57,8 @@ namespace YooAsset
|
|||||||
_isInitialize = false;
|
_isInitialize = false;
|
||||||
_initializeError = string.Empty;
|
_initializeError = string.Empty;
|
||||||
_initializeStatus = EOperationStatus.None;
|
_initializeStatus = EOperationStatus.None;
|
||||||
|
|
||||||
_bundleServices = null;
|
_bundleServices = null;
|
||||||
_editorSimulateModeImpl = null;
|
_playModeServices = null;
|
||||||
_offlinePlayModeImpl = null;
|
|
||||||
_hostPlayModeImpl = null;
|
|
||||||
|
|
||||||
if (_assetSystemImpl != null)
|
if (_assetSystemImpl != null)
|
||||||
{
|
{
|
||||||
@@ -78,6 +73,9 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public InitializationOperation InitializeAsync(InitializeParameters parameters)
|
public InitializationOperation InitializeAsync(InitializeParameters parameters)
|
||||||
{
|
{
|
||||||
|
// 注意:WebGL平台因为网络原因可能会初始化失败!
|
||||||
|
ResetInitializeAfterFailed();
|
||||||
|
|
||||||
// 检测初始化参数合法性
|
// 检测初始化参数合法性
|
||||||
CheckInitializeParameters(parameters);
|
CheckInitializeParameters(parameters);
|
||||||
|
|
||||||
@@ -86,36 +84,39 @@ namespace YooAsset
|
|||||||
_assetSystemImpl = new AssetSystemImpl();
|
_assetSystemImpl = new AssetSystemImpl();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||||
{
|
{
|
||||||
_editorSimulateModeImpl = new EditorSimulateModeImpl();
|
var editorSimulateModeImpl = new EditorSimulateModeImpl();
|
||||||
_bundleServices = _editorSimulateModeImpl;
|
_bundleServices = editorSimulateModeImpl;
|
||||||
_assetSystemImpl.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
_playModeServices = editorSimulateModeImpl;
|
||||||
|
_assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as EditorSimulateModeParameters;
|
var initializeParameters = parameters as EditorSimulateModeParameters;
|
||||||
initializeOperation = _editorSimulateModeImpl.InitializeAsync(
|
initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulatePatchManifestPath);
|
||||||
initializeParameters.LocationToLower,
|
|
||||||
initializeParameters.SimulatePatchManifestPath);
|
|
||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||||
{
|
{
|
||||||
_offlinePlayModeImpl = new OfflinePlayModeImpl();
|
var offlinePlayModeImpl = new OfflinePlayModeImpl();
|
||||||
_bundleServices = _offlinePlayModeImpl;
|
_bundleServices = offlinePlayModeImpl;
|
||||||
_assetSystemImpl.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
_playModeServices = offlinePlayModeImpl;
|
||||||
|
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as OfflinePlayModeParameters;
|
var initializeParameters = parameters as OfflinePlayModeParameters;
|
||||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync(
|
initializeOperation = offlinePlayModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower);
|
||||||
initializeParameters.LocationToLower,
|
|
||||||
PackageName);
|
|
||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
else if (_playMode == EPlayMode.HostPlayMode)
|
||||||
{
|
{
|
||||||
_hostPlayModeImpl = new HostPlayModeImpl();
|
var hostPlayModeImpl = new HostPlayModeImpl();
|
||||||
_bundleServices = _hostPlayModeImpl;
|
_bundleServices = hostPlayModeImpl;
|
||||||
_assetSystemImpl.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
_playModeServices = hostPlayModeImpl;
|
||||||
|
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as HostPlayModeParameters;
|
var initializeParameters = parameters as HostPlayModeParameters;
|
||||||
initializeOperation = _hostPlayModeImpl.InitializeAsync(
|
initializeOperation = hostPlayModeImpl.InitializeAsync(
|
||||||
|
PackageName,
|
||||||
initializeParameters.LocationToLower,
|
initializeParameters.LocationToLower,
|
||||||
initializeParameters.DefaultHostServer,
|
initializeParameters.DefaultHostServer,
|
||||||
initializeParameters.FallbackHostServer,
|
initializeParameters.FallbackHostServer,
|
||||||
initializeParameters.QueryServices,
|
initializeParameters.QueryServices
|
||||||
PackageName);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -127,6 +128,18 @@ namespace YooAsset
|
|||||||
initializeOperation.Completed += InitializeOperation_Completed;
|
initializeOperation.Completed += InitializeOperation_Completed;
|
||||||
return initializeOperation;
|
return initializeOperation;
|
||||||
}
|
}
|
||||||
|
private void ResetInitializeAfterFailed()
|
||||||
|
{
|
||||||
|
if (_isInitialize && _initializeStatus == EOperationStatus.Failed)
|
||||||
|
{
|
||||||
|
_isInitialize = false;
|
||||||
|
_initializeStatus = EOperationStatus.None;
|
||||||
|
_initializeError = string.Empty;
|
||||||
|
_bundleServices = null;
|
||||||
|
_playModeServices = null;
|
||||||
|
_assetSystemImpl = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
private void CheckInitializeParameters(InitializeParameters parameters)
|
private void CheckInitializeParameters(InitializeParameters parameters)
|
||||||
{
|
{
|
||||||
if (_isInitialize)
|
if (_isInitialize)
|
||||||
@@ -184,98 +197,54 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 向网络端请求最新的资源版本
|
/// 向网络端请求最新的资源版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
|
||||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(int timeout = 60)
|
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
return _playModeServices.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||||
{
|
|
||||||
var operation = new EditorPlayModeUpdatePackageVersionOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.UpdatePackageVersionAsync(PackageName, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 向网络端请求并更新补丁清单
|
/// 向网络端请求并更新补丁清单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="packageVersion">更新的包裹版本</param>
|
/// <param name="packageVersion">更新的包裹版本</param>
|
||||||
|
/// <param name="autoActiveManifest">自动激活清单</param>
|
||||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
DebugCheckUpdateManifest();
|
DebugCheckUpdateManifest();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
return _playModeServices.UpdatePackageManifestAsync(packageVersion, timeout);
|
||||||
{
|
|
||||||
var operation = new EditorPlayModeUpdatePackageManifestOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.UpdatePackageManifestAsync(PackageName, packageVersion, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检查本地包裹内容的完整性
|
/// 预下载指定版本的包裹资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CheckPackageContentsOperation CheckPackageContentsAsync()
|
/// <param name="packageVersion">下载的包裹版本</param>
|
||||||
|
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||||
|
public PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
return _playModeServices.PreDownloadPackageAsync(packageVersion, timeout);
|
||||||
{
|
|
||||||
var operation = new EditorSimulateModeCheckPackageContentsOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
var operation = new OfflinePlayModeCheckPackageContentsOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CheckPackageContentsAsync(PackageName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清理本地包裹未使用的缓存文件
|
/// 检查包裹内容的完整性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ClearPackageUnusedCacheFilesOperation ClearPackageUnusedCacheFilesAsync()
|
public CheckPackageContentsOperation CheckPackageContentsAsync(string packageVersion)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
var operation = new ClearPackageUnusedCacheFilesOperation(this);
|
return _playModeServices.CheckPackageContentsOperation(packageVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清理包裹未使用的缓存文件
|
||||||
|
/// </summary>
|
||||||
|
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
var operation = new ClearUnusedCacheFilesOperation(this);
|
||||||
OperationSystem.StartOperation(operation);
|
OperationSystem.StartOperation(operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
@@ -286,22 +255,9 @@ namespace YooAsset
|
|||||||
public string GetPackageVersion()
|
public string GetPackageVersion()
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
if (_playModeServices.ActiveManifest == null)
|
||||||
{
|
return string.Empty;
|
||||||
return _editorSimulateModeImpl.GetPackageVersion();
|
return _playModeServices.ActiveManifest.PackageVersion;
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
return _offlinePlayModeImpl.GetPackageVersion();
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.GetPackageVersion();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -374,7 +330,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
string[] tags = new string[] { tag };
|
string[] tags = new string[] { tag };
|
||||||
return _bundleServices.GetAssetInfos(tags);
|
return _playModeServices.ActiveManifest.GetAssetsInfoByTags(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -384,7 +340,7 @@ namespace YooAsset
|
|||||||
public AssetInfo[] GetAssetInfos(string[] tags)
|
public AssetInfo[] GetAssetInfos(string[] tags)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _bundleServices.GetAssetInfos(tags);
|
return _playModeServices.ActiveManifest.GetAssetsInfoByTags(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -405,7 +361,7 @@ namespace YooAsset
|
|||||||
public bool CheckLocationValid(string location)
|
public bool CheckLocationValid(string location)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
string assetPath = _bundleServices.TryMappingToAssetPath(location);
|
string assetPath = _playModeServices.ActiveManifest.TryMappingToAssetPath(location);
|
||||||
return string.IsNullOrEmpty(assetPath) == false;
|
return string.IsNullOrEmpty(assetPath) == false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -692,7 +648,7 @@ namespace YooAsset
|
|||||||
public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeServices.CreatePatchDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -705,20 +661,7 @@ namespace YooAsset
|
|||||||
public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
|
return _playModeServices.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -730,53 +673,7 @@ namespace YooAsset
|
|||||||
public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
|
return _playModeServices.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="locations">资源定位列表</param>
|
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
/// <param name="timeout">超时时间</param>
|
|
||||||
public PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
|
||||||
{
|
|
||||||
DebugCheckInitialize();
|
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
|
||||||
foreach (var location in locations)
|
|
||||||
{
|
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
|
||||||
assetInfos.Add(assetInfo);
|
|
||||||
}
|
|
||||||
return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -789,20 +686,7 @@ namespace YooAsset
|
|||||||
public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
|
return _playModeServices.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -816,7 +700,7 @@ namespace YooAsset
|
|||||||
public PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
public PatchUnpackerOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return CreatePatchUnpacker(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
|
return _playModeServices.CreatePatchUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -828,26 +712,7 @@ namespace YooAsset
|
|||||||
public PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
public PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
return _playModeServices.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -858,58 +723,7 @@ namespace YooAsset
|
|||||||
public PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
public PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
return _playModeServices.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 包裹更新
|
|
||||||
/// <summary>
|
|
||||||
/// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="packageVersion">指定更新的包裹版本</param>
|
|
||||||
/// <param name="timeout">超时时间</param>
|
|
||||||
public DownloadPackageOperation DownloadPackageAsync(string packageVersion, int timeout = 60)
|
|
||||||
{
|
|
||||||
DebugCheckInitialize();
|
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
|
||||||
{
|
|
||||||
var operation = new EditorPlayModeDownloadPackageOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
|
||||||
{
|
|
||||||
var operation = new OfflinePlayModeDownloadPackageOperation();
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
|
||||||
{
|
|
||||||
return _hostPlayModeImpl.DownloadPackageAsync(PackageName, packageVersion, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -922,7 +736,15 @@ namespace YooAsset
|
|||||||
// NOTE : 编辑器模拟模式下始终返回TRUE
|
// NOTE : 编辑器模拟模式下始终返回TRUE
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||||
return true;
|
return true;
|
||||||
return _bundleServices.IsIncludeBundleFile(fileName);
|
return _playModeServices.ActiveManifest.IsIncludeBundleFile(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源定位地址转换为资源信息类
|
||||||
|
/// </summary>
|
||||||
|
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
|
||||||
|
{
|
||||||
|
return _playModeServices.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -936,31 +758,13 @@ namespace YooAsset
|
|||||||
throw new Exception($"Package initialize failed ! {_initializeError}");
|
throw new Exception($"Package initialize failed ! {_initializeError}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
|
||||||
private void DebugCheckLocation(string location)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(location) == false)
|
|
||||||
{
|
|
||||||
// 检查路径末尾是否有空格
|
|
||||||
int index = location.LastIndexOf(" ");
|
|
||||||
if (index != -1)
|
|
||||||
{
|
|
||||||
if (location.Length == index + 1)
|
|
||||||
YooLogger.Warning($"Found blank character in location : \"{location}\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
|
|
||||||
YooLogger.Warning($"Found illegal character in location : \"{location}\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
[Conditional("DEBUG")]
|
||||||
private void DebugCheckUpdateManifest()
|
private void DebugCheckUpdateManifest()
|
||||||
{
|
{
|
||||||
var loadedBundleInfos = _assetSystemImpl.GetLoadedBundleInfos();
|
var loadedBundleInfos = _assetSystemImpl.GetLoadedBundleInfos();
|
||||||
if (loadedBundleInfos.Count > 0)
|
if (loadedBundleInfos.Count > 0)
|
||||||
{
|
{
|
||||||
YooLogger.Error($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
|
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -974,33 +778,5 @@ namespace YooAsset
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 私有方法
|
|
||||||
/// <summary>
|
|
||||||
/// 资源定位地址转换为资源信息类,失败时内部会发出错误日志。
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>如果转换失败会返回一个无效的资源信息类</returns>
|
|
||||||
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
|
|
||||||
{
|
|
||||||
DebugCheckLocation(location);
|
|
||||||
string assetPath = _bundleServices.MappingToAssetPath(location);
|
|
||||||
PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath);
|
|
||||||
if (patchAsset != null)
|
|
||||||
{
|
|
||||||
AssetInfo assetInfo = new AssetInfo(patchAsset, assetType);
|
|
||||||
return assetInfo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string error;
|
|
||||||
if (string.IsNullOrEmpty(location))
|
|
||||||
error = $"The location is null or empty !";
|
|
||||||
else
|
|
||||||
error = $"The location is invalid : {location}";
|
|
||||||
AssetInfo assetInfo = new AssetInfo(error);
|
|
||||||
return assetInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,9 +73,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证并缓存补丁包文件
|
/// 验证并缓存本地文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static EVerifyResult VerifyAndCacheBundle(PatchBundle patchBundle, EVerifyLevel verifyLevel)
|
public static EVerifyResult VerifyAndCacheLocalBundleFile(PatchBundle patchBundle, EVerifyLevel verifyLevel)
|
||||||
{
|
{
|
||||||
var verifyResult = VerifyContentInternal(patchBundle.CachedFilePath, patchBundle.FileSize, patchBundle.FileCRC, verifyLevel);
|
var verifyResult = VerifyContentInternal(patchBundle.CachedFilePath, patchBundle.FileSize, patchBundle.FileCRC, verifyLevel);
|
||||||
if (verifyResult == EVerifyResult.Succeed)
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
@@ -83,10 +83,40 @@ namespace YooAsset
|
|||||||
return verifyResult;
|
return verifyResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证并缓存下载文件
|
||||||
|
/// </summary>
|
||||||
|
public static EVerifyResult VerifyAndCacheDownloadBundleFile(string tempFilePath, PatchBundle patchBundle, EVerifyLevel verifyLevel)
|
||||||
|
{
|
||||||
|
var verifyResult = VerifyContentInternal(tempFilePath, patchBundle.FileSize, patchBundle.FileCRC, verifyLevel);
|
||||||
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string destFilePath = patchBundle.CachedFilePath;
|
||||||
|
if (File.Exists(destFilePath))
|
||||||
|
File.Delete(destFilePath);
|
||||||
|
|
||||||
|
FileInfo fileInfo = new FileInfo(tempFilePath);
|
||||||
|
fileInfo.MoveTo(destFilePath);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
verifyResult = EVerifyResult.FileMoveFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
CacheBundle(patchBundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return verifyResult;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证文件完整性
|
/// 验证文件完整性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static EVerifyResult VerifyContentInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
|
private static EVerifyResult VerifyContentInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,181 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器
|
|
||||||
/// </summary>
|
|
||||||
internal abstract class CacheVerifier
|
|
||||||
{
|
|
||||||
public abstract void InitVerifier(List<VerifyInfo> verifyInfos);
|
|
||||||
public abstract bool UpdateVerifier();
|
|
||||||
public abstract float GetVerifierProgress();
|
|
||||||
|
|
||||||
public List<VerifyInfo> VerifySuccessList { protected set; get; }
|
|
||||||
public List<VerifyInfo> VerifyFailList { protected set; get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器(线程版)
|
|
||||||
/// </summary>
|
|
||||||
internal class CacheVerifierWithThread : CacheVerifier
|
|
||||||
{
|
|
||||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
|
||||||
private readonly List<VerifyInfo> _waitingList = new List<VerifyInfo>(1000);
|
|
||||||
private readonly List<VerifyInfo> _verifyingList = new List<VerifyInfo>(100);
|
|
||||||
private int _verifyMaxNum;
|
|
||||||
private int _verifyTotalCount;
|
|
||||||
|
|
||||||
public override void InitVerifier(List<VerifyInfo> verifyInfos)
|
|
||||||
{
|
|
||||||
_waitingList.AddRange(verifyInfos);
|
|
||||||
VerifySuccessList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
VerifyFailList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
|
|
||||||
// 设置同时验证的最大数
|
|
||||||
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
|
||||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
|
||||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
|
||||||
_verifyTotalCount = _waitingList.Count;
|
|
||||||
if (_verifyMaxNum < 1)
|
|
||||||
_verifyMaxNum = 1;
|
|
||||||
}
|
|
||||||
public override bool UpdateVerifier()
|
|
||||||
{
|
|
||||||
_syncContext.Update();
|
|
||||||
|
|
||||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (_verifyingList.Count >= _verifyMaxNum)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
if (_verifyingList.Count >= _verifyMaxNum)
|
|
||||||
break;
|
|
||||||
|
|
||||||
var verifyIno = _waitingList[i];
|
|
||||||
if (VerifyFileWithThread(verifyIno))
|
|
||||||
{
|
|
||||||
_waitingList.RemoveAt(i);
|
|
||||||
_verifyingList.Add(verifyIno);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Warning("The thread pool is failed queued.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public override float GetVerifierProgress()
|
|
||||||
{
|
|
||||||
if (_verifyTotalCount == 0)
|
|
||||||
return 1f;
|
|
||||||
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool VerifyFileWithThread(VerifyInfo verifyInfo)
|
|
||||||
{
|
|
||||||
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), verifyInfo);
|
|
||||||
}
|
|
||||||
private void VerifyInThread(object infoObj)
|
|
||||||
{
|
|
||||||
VerifyInfo verifyInfo = (VerifyInfo)infoObj;
|
|
||||||
verifyInfo.Result = CacheSystem.VerifyBundle(verifyInfo.VerifyBundle, CacheSystem.InitVerifyLevel);
|
|
||||||
_syncContext.Post(VerifyCallback, verifyInfo);
|
|
||||||
}
|
|
||||||
private void VerifyCallback(object obj)
|
|
||||||
{
|
|
||||||
VerifyInfo verifyIno = (VerifyInfo)obj;
|
|
||||||
if (verifyIno.Result == EVerifyResult.Succeed)
|
|
||||||
{
|
|
||||||
VerifySuccessList.Add(verifyIno);
|
|
||||||
CacheSystem.CacheBundle(verifyIno.VerifyBundle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VerifyFailList.Add(verifyIno);
|
|
||||||
|
|
||||||
// NOTE:不期望删除断点续传的资源文件
|
|
||||||
/*
|
|
||||||
if (File.Exists(patchBundle.CachedBundleFilePath))
|
|
||||||
File.Delete(patchBundle.CachedBundleFilePath);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
_verifyingList.Remove(verifyIno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 本地缓存文件验证器(非线程版)
|
|
||||||
/// </summary>
|
|
||||||
internal class CacheVerifierWithoutThread : CacheVerifier
|
|
||||||
{
|
|
||||||
private readonly List<VerifyInfo> _waitingList = new List<VerifyInfo>(1000);
|
|
||||||
private readonly List<VerifyInfo> _verifyingList = new List<VerifyInfo>(100);
|
|
||||||
private int _verifyMaxNum;
|
|
||||||
private int _verifyTotalCount;
|
|
||||||
|
|
||||||
public override void InitVerifier(List<VerifyInfo> verifyInfos)
|
|
||||||
{
|
|
||||||
_waitingList.AddRange(verifyInfos);
|
|
||||||
VerifySuccessList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
VerifyFailList = new List<VerifyInfo>(verifyInfos.Count);
|
|
||||||
|
|
||||||
// 设置同时验证的最大数
|
|
||||||
_verifyMaxNum = 32;
|
|
||||||
_verifyTotalCount = _waitingList.Count;
|
|
||||||
}
|
|
||||||
public override bool UpdateVerifier()
|
|
||||||
{
|
|
||||||
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
if (_verifyingList.Count >= _verifyMaxNum)
|
|
||||||
break;
|
|
||||||
|
|
||||||
var verifyIno = _waitingList[i];
|
|
||||||
VerifyFileWithoutThread(verifyIno);
|
|
||||||
_waitingList.RemoveAt(i);
|
|
||||||
_verifyingList.Add(verifyIno);
|
|
||||||
}
|
|
||||||
|
|
||||||
_verifyingList.Clear();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public override float GetVerifierProgress()
|
|
||||||
{
|
|
||||||
if (_verifyTotalCount == 0)
|
|
||||||
return 1f;
|
|
||||||
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VerifyFileWithoutThread(VerifyInfo verifyIno)
|
|
||||||
{
|
|
||||||
var verifyResult = CacheSystem.VerifyAndCacheBundle(verifyIno.VerifyBundle, CacheSystem.InitVerifyLevel);
|
|
||||||
if (verifyResult == EVerifyResult.Succeed)
|
|
||||||
{
|
|
||||||
VerifySuccessList.Add(verifyIno);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VerifyFailList.Add(verifyIno);
|
|
||||||
|
|
||||||
// NOTE:不期望删除断点续传的资源文件
|
|
||||||
/*
|
|
||||||
if (File.Exists(patchBundle.CachedBundleFilePath))
|
|
||||||
File.Delete(patchBundle.CachedBundleFilePath);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件不存在
|
/// 文件不存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
FileNotExisted = -4,
|
FileNotExisted = -5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件移动失败(重命名失败)
|
||||||
|
/// </summary>
|
||||||
|
FileMoveFailed = -4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件内容不足(小于正常大小)
|
/// 文件内容不足(小于正常大小)
|
||||||
|
|||||||
30
Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs
Normal file
30
Assets/YooAsset/Runtime/DownloadSystem/DownloadReport.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
public struct DownloadReport
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 下载进度(0f~1f)
|
||||||
|
/// </summary>
|
||||||
|
public float Progress;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 需要下载的总字节数
|
||||||
|
/// </summary>
|
||||||
|
public ulong TotalSize;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已经下载的字节数
|
||||||
|
/// </summary>
|
||||||
|
public ulong DownloadedBytes;
|
||||||
|
|
||||||
|
public static DownloadReport CreateDefaultReport()
|
||||||
|
{
|
||||||
|
DownloadReport report = new DownloadReport();
|
||||||
|
report.Progress = 0f;
|
||||||
|
report.TotalSize = 0;
|
||||||
|
report.DownloadedBytes = 0;
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 60c7594328ef976408edadfdf2b9aa3d
|
guid: d40b8341fcd4ad2478eb1a890ebf0476
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -7,8 +7,12 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
CheckLocalFile,
|
CheckLocalFile,
|
||||||
CreateDownload,
|
CheckTempFile,
|
||||||
|
PrepareDownload,
|
||||||
|
CreateResumeDownloader,
|
||||||
|
CreateGeneralDownloader,
|
||||||
CheckDownload,
|
CheckDownload,
|
||||||
|
VerifyDownload,
|
||||||
TryAgain,
|
TryAgain,
|
||||||
Succeed,
|
Succeed,
|
||||||
Failed,
|
Failed,
|
||||||
@@ -30,7 +34,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载进度
|
/// 下载进度(0f~1f)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float DownloadProgress
|
public float DownloadProgress
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace YooAsset
|
|||||||
internal sealed class FileDownloader : DownloaderBase
|
internal sealed class FileDownloader : DownloaderBase
|
||||||
{
|
{
|
||||||
private readonly bool _breakResume;
|
private readonly bool _breakResume;
|
||||||
|
private readonly string _tempFilePath;
|
||||||
private UnityWebRequest _webRequest = null;
|
private UnityWebRequest _webRequest = null;
|
||||||
private DownloadHandlerFileRange _downloadHandle = null;
|
private DownloadHandlerFileRange _downloadHandle = null;
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ namespace YooAsset
|
|||||||
public FileDownloader(BundleInfo bundleInfo, bool breakResume) : base(bundleInfo)
|
public FileDownloader(BundleInfo bundleInfo, bool breakResume) : base(bundleInfo)
|
||||||
{
|
{
|
||||||
_breakResume = breakResume;
|
_breakResume = breakResume;
|
||||||
|
_tempFilePath = bundleInfo.Bundle.CachedFilePath + ".temp";
|
||||||
}
|
}
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
@@ -32,10 +34,26 @@ namespace YooAsset
|
|||||||
if (IsDone())
|
if (IsDone())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 检测本地文件
|
// 检测本地正式文件
|
||||||
if (_steps == ESteps.CheckLocalFile)
|
if (_steps == ESteps.CheckLocalFile)
|
||||||
{
|
{
|
||||||
var verifyResult = CacheSystem.VerifyAndCacheBundle(_bundleInfo.Bundle, EVerifyLevel.High);
|
var verifyResult = CacheSystem.VerifyAndCacheLocalBundleFile(_bundleInfo.Bundle, CacheSystem.InitVerifyLevel);
|
||||||
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (File.Exists(_bundleInfo.Bundle.CachedFilePath))
|
||||||
|
File.Delete(_bundleInfo.Bundle.CachedFilePath);
|
||||||
|
_steps = ESteps.CheckTempFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测本地临时文件
|
||||||
|
if (_steps == ESteps.CheckTempFile)
|
||||||
|
{
|
||||||
|
var verifyResult = CacheSystem.VerifyAndCacheDownloadBundleFile(_tempFilePath, _bundleInfo.Bundle, EVerifyLevel.High);
|
||||||
if (verifyResult == EVerifyResult.Succeed)
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Succeed;
|
_steps = ESteps.Succeed;
|
||||||
@@ -44,19 +62,16 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (verifyResult == EVerifyResult.FileOverflow)
|
if (verifyResult == EVerifyResult.FileOverflow)
|
||||||
{
|
{
|
||||||
string cacheFilePath = _bundleInfo.Bundle.CachedFilePath;
|
if (File.Exists(_tempFilePath))
|
||||||
if (File.Exists(cacheFilePath))
|
File.Delete(_tempFilePath);
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
}
|
||||||
_steps = ESteps.CreateDownload;
|
_steps = ESteps.PrepareDownload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateDownload)
|
if (_steps == ESteps.PrepareDownload)
|
||||||
{
|
{
|
||||||
string fileSavePath = _bundleInfo.Bundle.CachedFilePath;
|
|
||||||
|
|
||||||
// 重置变量
|
// 重置变量
|
||||||
_downloadProgress = 0f;
|
_downloadProgress = 0f;
|
||||||
_downloadedBytes = 0;
|
_downloadedBytes = 0;
|
||||||
@@ -66,53 +81,73 @@ namespace YooAsset
|
|||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||||
_tryAgainTimer = 0f;
|
_tryAgainTimer = 0f;
|
||||||
|
|
||||||
// 是否开启断点续传下载
|
// 获取请求地址
|
||||||
if (_breakResume)
|
_requestURL = GetRequestURL();
|
||||||
{
|
|
||||||
long fileLength = -1;
|
|
||||||
if (File.Exists(fileSavePath))
|
|
||||||
{
|
|
||||||
FileInfo fileInfo = new FileInfo(fileSavePath);
|
|
||||||
fileLength = fileInfo.Length;
|
|
||||||
_fileOriginLength = (ulong)fileLength;
|
|
||||||
_downloadedBytes = _fileOriginLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
_requestURL = GetRequestURL();
|
if (_breakResume)
|
||||||
_webRequest = UnityWebRequest.Get(_requestURL);
|
_steps = ESteps.CreateResumeDownloader;
|
||||||
|
else
|
||||||
|
_steps = ESteps.CreateGeneralDownloader;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建普通的下载器
|
||||||
|
if (_steps == ESteps.CreateGeneralDownloader)
|
||||||
|
{
|
||||||
|
if (File.Exists(_tempFilePath))
|
||||||
|
{
|
||||||
|
File.Delete(_tempFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||||
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest.downloadHandler = handler;
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
|
||||||
|
if (DownloadSystem.CertificateHandlerInstance != null)
|
||||||
|
{
|
||||||
|
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
||||||
|
_webRequest.disposeCertificateHandlerOnDispose = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_webRequest.SendWebRequest();
|
||||||
|
_steps = ESteps.CheckDownload;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建断点续传下载器
|
||||||
|
if (_steps == ESteps.CreateResumeDownloader)
|
||||||
|
{
|
||||||
|
long fileLength = -1;
|
||||||
|
if (File.Exists(_tempFilePath))
|
||||||
|
{
|
||||||
|
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
||||||
|
fileLength = fileInfo.Length;
|
||||||
|
_fileOriginLength = (ulong)fileLength;
|
||||||
|
_downloadedBytes = _fileOriginLength;
|
||||||
|
}
|
||||||
|
|
||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
var handler = new DownloadHandlerFile(fileSavePath, true);
|
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||||
handler.removeFileOnAbort = false;
|
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
||||||
|
handler.removeFileOnAbort = false;
|
||||||
#else
|
#else
|
||||||
var handler = new DownloadHandlerFileRange(fileSavePath, _bundleInfo.Bundle.FileSize, _webRequest);
|
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
||||||
_downloadHandle = handler;
|
var handler = new DownloadHandlerFileRange(_tempFilePath, _bundleInfo.Bundle.FileSize, _webRequest);
|
||||||
|
_downloadHandle = handler;
|
||||||
#endif
|
#endif
|
||||||
|
_webRequest.downloadHandler = handler;
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
if (fileLength > 0)
|
||||||
|
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
|
||||||
|
|
||||||
if (DownloadSystem.CertificateHandlerInstance != null)
|
if (DownloadSystem.CertificateHandlerInstance != null)
|
||||||
{
|
|
||||||
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
|
||||||
_webRequest.disposeCertificateHandlerOnDispose = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_webRequest.downloadHandler = handler;
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
if (fileLength > 0)
|
|
||||||
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
_steps = ESteps.CheckDownload;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_requestURL = GetRequestURL();
|
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
||||||
_webRequest = new UnityWebRequest(_requestURL, UnityWebRequest.kHttpVerbGET);
|
_webRequest.disposeCertificateHandlerOnDispose = false;
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(fileSavePath);
|
|
||||||
handler.removeFileOnAbort = true;
|
|
||||||
_webRequest.downloadHandler = handler;
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
_steps = ESteps.CheckDownload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_webRequest.SendWebRequest();
|
||||||
|
_steps = ESteps.CheckDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
@@ -145,78 +180,77 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 检查文件完整性
|
// 如果网络异常
|
||||||
if (hasError == false)
|
|
||||||
{
|
|
||||||
var verifyResult = CacheSystem.VerifyAndCacheBundle(_bundleInfo.Bundle, EVerifyLevel.High);
|
|
||||||
if (verifyResult != EVerifyResult.Succeed)
|
|
||||||
{
|
|
||||||
hasError = true;
|
|
||||||
_lastError = $"Verify bundle content failed : {_bundleInfo.Bundle.FileName}";
|
|
||||||
_lastCode = _webRequest.responseCode;
|
|
||||||
|
|
||||||
// 验证失败后删除文件
|
|
||||||
string cacheFilePath = _bundleInfo.Bundle.CachedFilePath;
|
|
||||||
if (File.Exists(cacheFilePath))
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果下载失败
|
|
||||||
if (hasError)
|
if (hasError)
|
||||||
{
|
{
|
||||||
// 注意:非断点续传下载失败之后删除文件
|
if (_breakResume)
|
||||||
if (_breakResume == false)
|
|
||||||
{
|
|
||||||
string cacheFilePath = _bundleInfo.Bundle.CachedFilePath;
|
|
||||||
if (File.Exists(cacheFilePath))
|
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// 注意:下载断点续传文件发生特殊错误码之后删除文件
|
// 注意:下载断点续传文件发生特殊错误码之后删除文件
|
||||||
if (DownloadSystem.ClearFileResponseCodes != null)
|
if (DownloadSystem.ClearFileResponseCodes != null)
|
||||||
{
|
{
|
||||||
if (DownloadSystem.ClearFileResponseCodes.Contains(_webRequest.responseCode))
|
if (DownloadSystem.ClearFileResponseCodes.Contains(_webRequest.responseCode))
|
||||||
{
|
{
|
||||||
string cacheFilePath = _bundleInfo.Bundle.CachedFilePath;
|
if (File.Exists(_tempFilePath))
|
||||||
if (File.Exists(cacheFilePath))
|
File.Delete(_tempFilePath);
|
||||||
File.Delete(cacheFilePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 失败后重新尝试
|
|
||||||
if (_failedTryAgain > 0)
|
|
||||||
{
|
|
||||||
ReportWarning();
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ReportError();
|
// 注意:非断点续传下载失败之后删除文件
|
||||||
_steps = ESteps.Failed;
|
if (File.Exists(_tempFilePath))
|
||||||
|
File.Delete(_tempFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_lastError = string.Empty;
|
_steps = ESteps.VerifyDownload;
|
||||||
_lastCode = 0;
|
|
||||||
_steps = ESteps.Succeed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 释放下载器
|
// 释放下载器
|
||||||
DisposeWebRequest();
|
DisposeWebRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证下载文件
|
||||||
|
if (_steps == ESteps.VerifyDownload)
|
||||||
|
{
|
||||||
|
var verifyResult = CacheSystem.VerifyAndCacheDownloadBundleFile(_tempFilePath, _bundleInfo.Bundle, EVerifyLevel.High);
|
||||||
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
_lastError = string.Empty;
|
||||||
|
_lastCode = 0;
|
||||||
|
_steps = ESteps.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lastError = $"Verify bundle content failed : {_bundleInfo.Bundle.FileName}";
|
||||||
|
|
||||||
|
// 验证失败后删除文件
|
||||||
|
if (File.Exists(_tempFilePath))
|
||||||
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
if (_steps == ESteps.TryAgain)
|
if (_steps == ESteps.TryAgain)
|
||||||
{
|
{
|
||||||
|
if (_failedTryAgain <= 0)
|
||||||
|
{
|
||||||
|
ReportError();
|
||||||
|
_steps = ESteps.Failed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
if (_tryAgainTimer > 1f)
|
if (_tryAgainTimer > 1f)
|
||||||
{
|
{
|
||||||
_failedTryAgain--;
|
_failedTryAgain--;
|
||||||
_steps = ESteps.CreateDownload;
|
_steps = ESteps.PrepareDownload;
|
||||||
|
ReportWarning();
|
||||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class UnityWebDataRequester
|
internal class UnityWebDataRequester
|
||||||
{
|
{
|
||||||
protected UnityWebRequest _webRequest;
|
private UnityWebRequest _webRequest;
|
||||||
protected UnityWebRequestAsyncOperation _operationHandle;
|
private UnityWebRequestAsyncOperation _operationHandle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求URL地址
|
/// 请求URL地址
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -11,8 +12,14 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class UnityWebFileRequester
|
internal class UnityWebFileRequester
|
||||||
{
|
{
|
||||||
protected UnityWebRequest _webRequest;
|
private UnityWebRequest _webRequest;
|
||||||
protected UnityWebRequestAsyncOperation _operationHandle;
|
private UnityWebRequestAsyncOperation _operationHandle;
|
||||||
|
|
||||||
|
// 超时相关
|
||||||
|
private float _timeout;
|
||||||
|
private bool _isAbort = false;
|
||||||
|
private ulong _latestDownloadBytes;
|
||||||
|
private float _latestDownloadRealtime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求URL地址
|
/// 请求URL地址
|
||||||
@@ -23,11 +30,15 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发送GET请求
|
/// 发送GET请求
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SendRequest(string url, string savePath)
|
public void SendRequest(string url, string savePath, float timeout = 60)
|
||||||
{
|
{
|
||||||
if (_webRequest == null)
|
if (_webRequest == null)
|
||||||
{
|
{
|
||||||
URL = url;
|
URL = url;
|
||||||
|
_timeout = timeout;
|
||||||
|
_latestDownloadBytes = 0;
|
||||||
|
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||||
|
|
||||||
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
|
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
@@ -96,5 +107,28 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测超时
|
||||||
|
/// </summary>
|
||||||
|
public void CheckTimeout()
|
||||||
|
{
|
||||||
|
// 注意:在连续时间段内无新增下载数据及判定为超时
|
||||||
|
if (_isAbort == false)
|
||||||
|
{
|
||||||
|
if (_latestDownloadBytes != _webRequest.downloadedBytes)
|
||||||
|
{
|
||||||
|
_latestDownloadBytes = _webRequest.downloadedBytes;
|
||||||
|
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||||
|
}
|
||||||
|
|
||||||
|
float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
|
||||||
|
if (offset > _timeout)
|
||||||
|
{
|
||||||
|
_webRequest.Abort();
|
||||||
|
_isAbort = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检查本地包裹内容的完整性
|
/// 检查包裹内容的完整性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class CheckPackageContentsOperation : AsyncOperationBase
|
public abstract class CheckPackageContentsOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
@@ -43,90 +43,106 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
CheckLoadedManifest,
|
CheckActiveManifest,
|
||||||
InitVerifyingCache,
|
LoadCacheManifest,
|
||||||
UpdateVerifyingCache,
|
VerifyPackage,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
private readonly string _packageVersion;
|
||||||
|
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||||
|
private VerifyPackageOperation _verifyOperation;
|
||||||
|
private PatchManifest _verifyManifest;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
|
||||||
|
|
||||||
internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName)
|
internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName, string packageVersion)
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
_steps = ESteps.CheckLoadedManifest;
|
_steps = ESteps.CheckActiveManifest;
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.CheckLoadedManifest)
|
if (_steps == ESteps.CheckActiveManifest)
|
||||||
{
|
{
|
||||||
if (_impl.LocalPatchManifest == null)
|
// 检测当前激活的清单对象
|
||||||
|
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_verifyManifest = _impl.ActiveManifest;
|
||||||
Status = EOperationStatus.Failed;
|
_steps = ESteps.VerifyPackage;
|
||||||
Error = $"Not found loaded package : {_packageName}";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.LoadCacheManifest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.LoadCacheManifest)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(true);
|
if (_loadCacheManifestOp == null)
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
{
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
OperationSystem.StartOperation(_loadCacheManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_verifyManifest = _loadCacheManifestOp.Manifest;
|
||||||
|
_steps = ESteps.VerifyPackage;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _loadCacheManifestOp.Error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.VerifyPackage)
|
||||||
{
|
{
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
if (_verifyOperation == null)
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
|
||||||
{
|
{
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
_verifyOperation = VerifyPackageOperation.CreateOperation(_verifyManifest, _impl);
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
|
}
|
||||||
|
|
||||||
bool verifySucceed = true;
|
Progress = _verifyOperation.Progress;
|
||||||
foreach (var verifyInfo in _cacheVerifier.VerifyFailList)
|
if (_verifyOperation.IsDone == false)
|
||||||
{
|
return;
|
||||||
// 注意:跳过内置资源文件
|
|
||||||
if (verifyInfo.IsBuildinFile)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
verifySucceed = false;
|
bool verifySucceed = true;
|
||||||
YooLogger.Warning($"Failed verify file : {verifyInfo.VerifyFilePath}");
|
foreach (var verifyInfo in _verifyOperation.VerifyFailList)
|
||||||
}
|
{
|
||||||
|
// 注意:跳过内置资源文件
|
||||||
|
if (verifyInfo.IsBuildinFile)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (verifySucceed)
|
verifySucceed = false;
|
||||||
{
|
YooLogger.Warning($"Failed verify file : {verifyInfo.VerifyFilePath}");
|
||||||
_steps = ESteps.Done;
|
}
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
if (verifySucceed)
|
||||||
else
|
{
|
||||||
{
|
_steps = ESteps.Done;
|
||||||
_steps = ESteps.Done;
|
Status = EOperationStatus.Succeed;
|
||||||
Status = EOperationStatus.Failed;
|
}
|
||||||
Error = $"The package resource {_packageName} content has verify failed file !";
|
else
|
||||||
}
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The package resource {_packageName} content has verify failed file !";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清理本地包裹未使用的缓存文件
|
/// 清理本地包裹未使用的缓存文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ClearPackageUnusedCacheFilesOperation : AsyncOperationBase
|
public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
@@ -18,11 +18,11 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly AssetsPackage _package;
|
private readonly AssetsPackage _package;
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
private List<string> _unusedCacheFilePaths;
|
private List<string> _unusedCacheFilePaths;
|
||||||
private int _unusedFileTotalCount = 0;
|
private int _unusedFileTotalCount = 0;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal ClearPackageUnusedCacheFilesOperation(AssetsPackage package)
|
internal ClearUnusedCacheFilesOperation(AssetsPackage package)
|
||||||
{
|
{
|
||||||
_package = package;
|
_package = package;
|
||||||
}
|
}
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
public abstract class DownloadPackageOperation : AsyncOperationBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 创建包裹下载器
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
/// <param name="timeout">超时时间(单位:秒)</param>
|
|
||||||
public abstract PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 编辑器下模拟运行的更新资源包裹操作
|
|
||||||
/// </summary>
|
|
||||||
internal sealed class EditorPlayModeDownloadPackageOperation : DownloadPackageOperation
|
|
||||||
{
|
|
||||||
internal override void Start()
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
internal override void Update()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建包裹下载器
|
|
||||||
/// </summary>
|
|
||||||
public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 离线模式的更新资源包裹操作
|
|
||||||
/// </summary>
|
|
||||||
internal sealed class OfflinePlayModeDownloadPackageOperation : DownloadPackageOperation
|
|
||||||
{
|
|
||||||
internal override void Start()
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
internal override void Update()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建包裹下载器
|
|
||||||
/// </summary>
|
|
||||||
public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
|
||||||
var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 联机模式的更新资源包裹操作
|
|
||||||
/// </summary>
|
|
||||||
internal sealed class HostPlayModeDownloadPackageOperation : DownloadPackageOperation
|
|
||||||
{
|
|
||||||
private enum ESteps
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
LoadWebManifest,
|
|
||||||
CheckWebManifest,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int RequestCount = 0;
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
|
||||||
private readonly string _packageName;
|
|
||||||
private readonly string _packageVersion;
|
|
||||||
private readonly int _timeout;
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
private PatchManifest _remotePatchManifest;
|
|
||||||
|
|
||||||
internal HostPlayModeDownloadPackageOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
|
|
||||||
{
|
|
||||||
_impl = impl;
|
|
||||||
_packageName = packageName;
|
|
||||||
_packageVersion = packageVersion;
|
|
||||||
_timeout = timeout;
|
|
||||||
}
|
|
||||||
internal override void Start()
|
|
||||||
{
|
|
||||||
RequestCount++;
|
|
||||||
_steps = ESteps.LoadWebManifest;
|
|
||||||
}
|
|
||||||
internal override void Update()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_steps == ESteps.LoadWebManifest)
|
|
||||||
{
|
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageVersion);
|
|
||||||
string webURL = GetPatchManifestRequestURL(fileName);
|
|
||||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
|
||||||
_downloader = new UnityWebDataRequester();
|
|
||||||
_downloader.SendRequest(webURL, _timeout);
|
|
||||||
_steps = ESteps.CheckWebManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckWebManifest)
|
|
||||||
{
|
|
||||||
Progress = _downloader.Progress();
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Check error
|
|
||||||
if (_downloader.HasError())
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = _downloader.GetError();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 解析补丁清单
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_remotePatchManifest = PatchManifest.Deserialize(_downloader.GetText());
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
catch(System.Exception e)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = e.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_downloader.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建包裹下载器
|
|
||||||
/// </summary>
|
|
||||||
public override PackageDownloaderOperation CreatePackageDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
|
||||||
if (Status == EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Create package downloader : {_remotePatchManifest.PackageName} {_remotePatchManifest.PackageVersion}");
|
|
||||||
List<BundleInfo> downloadList = GetDownloadList();
|
|
||||||
var operation = new PackageDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Error($"{nameof(DownloadPackageOperation)} status is failed !");
|
|
||||||
var operation = new PackageDownloaderOperation(null, downloadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取补丁清单请求地址
|
|
||||||
/// </summary>
|
|
||||||
private string GetPatchManifestRequestURL(string fileName)
|
|
||||||
{
|
|
||||||
// 轮流返回请求地址
|
|
||||||
if (RequestCount % 2 == 0)
|
|
||||||
return _impl.GetPatchDownloadFallbackURL(fileName);
|
|
||||||
else
|
|
||||||
return _impl.GetPatchDownloadMainURL(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取下载列表
|
|
||||||
/// </summary>
|
|
||||||
private List<BundleInfo> GetDownloadList()
|
|
||||||
{
|
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
|
||||||
foreach (var patchBundle in _remotePatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 忽略缓存文件
|
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 忽略APP资源
|
|
||||||
if (_impl.IsBuildinPatchBundle(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
downloadList.Add(patchBundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _impl.ConvertToDownloadList(downloadList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,7 @@ namespace YooAsset
|
|||||||
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
||||||
public delegate void OnDownloadError(string fileName, string error);
|
public delegate void OnDownloadError(string fileName, string error);
|
||||||
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
||||||
|
|
||||||
private readonly int _downloadingMaxNumber;
|
private readonly int _downloadingMaxNumber;
|
||||||
private readonly int _failedTryAgain;
|
private readonly int _failedTryAgain;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
@@ -29,10 +29,10 @@ namespace YooAsset
|
|||||||
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||||
|
|
||||||
// 数据相关
|
// 数据相关
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
private bool _isPause = false;
|
private bool _isPause = false;
|
||||||
private long _lastDownloadBytes = 0;
|
private long _lastDownloadBytes = 0;
|
||||||
private int _lastDownloadCount = 0;
|
private int _lastDownloadCount = 0;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -74,7 +74,7 @@ namespace YooAsset
|
|||||||
/// 当开始下载某个文件
|
/// 当开始下载某个文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
{
|
{
|
||||||
@@ -183,9 +183,9 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
var failedDownloader = _failedList[0];
|
var failedDownloader = _failedList[0];
|
||||||
string fileName = failedDownloader.GetBundleInfo().Bundle.BundleName;
|
string fileName = failedDownloader.GetBundleInfo().Bundle.BundleName;
|
||||||
Error = $"Failed to download file : {fileName}";
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Failed to download file : {fileName}";
|
||||||
OnDownloadErrorCallback?.Invoke(fileName, failedDownloader.GetLastError());
|
OnDownloadErrorCallback?.Invoke(fileName, failedDownloader.GetLastError());
|
||||||
OnDownloadOverCallback?.Invoke(false);
|
OnDownloadOverCallback?.Invoke(false);
|
||||||
}
|
}
|
||||||
@@ -241,19 +241,22 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class PackageDownloaderOperation : DownloaderOperation
|
|
||||||
{
|
|
||||||
internal PackageDownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public sealed class PatchDownloaderOperation : DownloaderOperation
|
public sealed class PatchDownloaderOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal PatchDownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal PatchDownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建空的下载器
|
||||||
|
/// </summary>
|
||||||
|
internal static PatchDownloaderOperation CreateEmptyDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public sealed class PatchUnpackerOperation : DownloaderOperation
|
public sealed class PatchUnpackerOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
@@ -261,5 +264,15 @@ namespace YooAsset
|
|||||||
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建空的解压器
|
||||||
|
/// </summary>
|
||||||
|
internal static PatchUnpackerOperation CreateEmptyUnpacker(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
|
var operation = new PatchUnpackerOperation(downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class InitializationOperation : AsyncOperationBase
|
public abstract class InitializationOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
public string PackageVersion { protected set; get; }
|
||||||
/// 初始化内部加载的包裹版本
|
|
||||||
/// </summary>
|
|
||||||
public string InitializedPackageVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,50 +21,49 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Load,
|
LoadEditorManifest,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly EditorSimulateModeImpl _impl;
|
private readonly EditorSimulateModeImpl _impl;
|
||||||
private readonly string _simulatePatchManifestPath;
|
private readonly string _simulateManifestPath;
|
||||||
|
private LoadEditorManifestOperation _loadEditorManifestOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulatePatchManifestPath)
|
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulateManifestPath)
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_simulatePatchManifestPath = simulatePatchManifestPath;
|
_simulateManifestPath = simulateManifestPath;
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
_steps = ESteps.Load;
|
_steps = ESteps.LoadEditorManifest;
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.Load)
|
if (_steps == ESteps.LoadEditorManifest)
|
||||||
{
|
{
|
||||||
if (File.Exists(_simulatePatchManifestPath) == false)
|
if (_loadEditorManifestOp == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_loadEditorManifestOp = new LoadEditorManifestOperation(_simulateManifestPath);
|
||||||
Status = EOperationStatus.Failed;
|
OperationSystem.StartOperation(_loadEditorManifestOp);
|
||||||
Error = $"Not found simulation manifest file : {_simulatePatchManifestPath}";
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (_loadEditorManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_loadEditorManifestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Load simulation manifest file : {_simulatePatchManifestPath}");
|
PackageVersion = _loadEditorManifestOp.Manifest.PackageVersion;
|
||||||
string jsonContent = FileUtility.ReadFile(_simulatePatchManifestPath);
|
_impl.ActiveManifest = _loadEditorManifestOp.Manifest;
|
||||||
var manifest = PatchManifest.Deserialize(jsonContent);
|
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
|
||||||
_impl.SetSimulatePatchManifest(manifest);
|
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = e.Message;
|
Error = _loadEditorManifestOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,101 +77,95 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
QueryAppPackageVersion,
|
QueryBuildinPackageVersion,
|
||||||
LoadAppManifest,
|
LoadBuildinManifest,
|
||||||
InitVerifyingCache,
|
VerifyPackage,
|
||||||
UpdateVerifyingCache,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly OfflinePlayModeImpl _impl;
|
private readonly OfflinePlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
|
||||||
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||||
private AppManifestLoader _appManifestLoader;
|
private VerifyPackageOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
|
||||||
|
|
||||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, string packageName)
|
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, string packageName)
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
_steps = ESteps.QueryAppPackageVersion;
|
_steps = ESteps.QueryBuildinPackageVersion;
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.QueryAppPackageVersion)
|
if (_steps == ESteps.QueryBuildinPackageVersion)
|
||||||
{
|
{
|
||||||
_appPackageVersionQuerier.Update();
|
if (_queryBuildinPackageVersionOp == null)
|
||||||
if (_appPackageVersionQuerier.IsDone == false)
|
{
|
||||||
|
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_packageName);
|
||||||
|
OperationSystem.StartOperation(_queryBuildinPackageVersionOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queryBuildinPackageVersionOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string error = _appPackageVersionQuerier.Error;
|
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||||
if (string.IsNullOrEmpty(error) == false)
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.LoadBuildinManifest;
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = error;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_appManifestLoader = new AppManifestLoader(_packageName, _appPackageVersionQuerier.Version);
|
_steps = ESteps.Done;
|
||||||
_steps = ESteps.LoadAppManifest;
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _queryBuildinPackageVersionOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadAppManifest)
|
if (_steps == ESteps.LoadBuildinManifest)
|
||||||
{
|
{
|
||||||
_appManifestLoader.Update();
|
if (_loadBuildinManifestOp == null)
|
||||||
Progress = _appManifestLoader.Progress;
|
{
|
||||||
if (_appManifestLoader.IsDone == false)
|
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion);
|
||||||
|
OperationSystem.StartOperation(_loadBuildinManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Progress = _loadBuildinManifestOp.Progress;
|
||||||
|
if (_loadBuildinManifestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var manifest = _appManifestLoader.Manifest;
|
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||||
if (manifest == null)
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||||
Status = EOperationStatus.Failed;
|
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||||
Error = _appManifestLoader.Error;
|
_steps = ESteps.VerifyPackage;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
_steps = ESteps.Done;
|
||||||
_impl.SetAppPatchManifest(manifest);
|
Status = EOperationStatus.Failed;
|
||||||
_steps = ESteps.InitVerifyingCache;
|
Error = _loadBuildinManifestOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.VerifyPackage)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList();
|
if (_verifyOperation == null)
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
{
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
Progress = _verifyOperation.Progress;
|
||||||
{
|
if (_verifyOperation.IsDone)
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,426 +180,239 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
|
CheckAppFootPrint,
|
||||||
|
QueryCachePackageVersion,
|
||||||
TryLoadCacheManifest,
|
TryLoadCacheManifest,
|
||||||
QueryAppPackageVersion,
|
QueryBuildinPackageVersion,
|
||||||
CopyAppManifest,
|
UnpackBuildinManifest,
|
||||||
LoadAppManifest,
|
LoadBuildinManifest,
|
||||||
InitVerifyingCache,
|
VerifyPackage,
|
||||||
UpdateVerifyingCache,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
|
||||||
private readonly AppPackageVersionQuerier _appPackageVersionQuerier;
|
private QueryCachePackageVersionOperation _queryCachePackageVersionOp;
|
||||||
private AppManifestCopyer _appManifestCopyer;
|
private UnpackBuildinManifestOperation _unpackBuildinManifestOp;
|
||||||
private AppManifestLoader _appManifestLoader;
|
private LoadBuildinManifestOperation _loadBuildinManifestOp;
|
||||||
|
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||||
|
private VerifyPackageOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
|
||||||
|
|
||||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, string packageName)
|
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, string packageName)
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_appPackageVersionQuerier = new AppPackageVersionQuerier(packageName);
|
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryLoadCacheManifest;
|
_steps = ESteps.CheckAppFootPrint;
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.TryLoadCacheManifest)
|
if (_steps == ESteps.CheckAppFootPrint)
|
||||||
{
|
{
|
||||||
if (PersistentHelper.CheckCacheManifestFileExists(_packageName))
|
var appFootPrint = new AppFootPrint();
|
||||||
|
appFootPrint.Load();
|
||||||
|
|
||||||
|
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
||||||
|
if (appFootPrint.IsDirty())
|
||||||
{
|
{
|
||||||
try
|
PersistentHelper.DeleteManifestFolder();
|
||||||
{
|
appFootPrint.Coverage();
|
||||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
}
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
_steps = ESteps.QueryCachePackageVersion;
|
||||||
_steps = ESteps.InitVerifyingCache;
|
}
|
||||||
}
|
|
||||||
catch (System.Exception e)
|
if (_steps == ESteps.QueryCachePackageVersion)
|
||||||
{
|
{
|
||||||
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,我们主动把损坏的文件删除。
|
if (_queryCachePackageVersionOp == null)
|
||||||
YooLogger.Warning($"Failed to load cache manifest file : {e.Message}");
|
{
|
||||||
PersistentHelper.DeleteCacheManifestFile(_packageName);
|
_queryCachePackageVersionOp = new QueryCachePackageVersionOperation(_packageName);
|
||||||
_steps = ESteps.QueryAppPackageVersion;
|
OperationSystem.StartOperation(_queryCachePackageVersionOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_queryCachePackageVersionOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_queryCachePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryLoadCacheManifest;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.QueryAppPackageVersion;
|
_steps = ESteps.QueryBuildinPackageVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.QueryAppPackageVersion)
|
if (_steps == ESteps.TryLoadCacheManifest)
|
||||||
{
|
{
|
||||||
_appPackageVersionQuerier.Update();
|
if (_loadCacheManifestOp == null)
|
||||||
if (_appPackageVersionQuerier.IsDone == false)
|
{
|
||||||
|
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _queryCachePackageVersionOp.PackageVersion);
|
||||||
|
OperationSystem.StartOperation(_loadCacheManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
PackageVersion = _loadCacheManifestOp.Manifest.PackageVersion;
|
||||||
|
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||||
|
_steps = ESteps.VerifyPackage;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.QueryBuildinPackageVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.QueryBuildinPackageVersion)
|
||||||
|
{
|
||||||
|
if (_queryBuildinPackageVersionOp == null)
|
||||||
|
{
|
||||||
|
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_packageName);
|
||||||
|
OperationSystem.StartOperation(_queryBuildinPackageVersionOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queryBuildinPackageVersionOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 注意:为了兼容MOD模式,初始化动态新增的包裹的时候,如果内置清单不存在也不需要报错!
|
// 注意:为了兼容MOD模式,初始化动态新增的包裹的时候,如果内置清单不存在也不需要报错!
|
||||||
string error = _appPackageVersionQuerier.Error;
|
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||||
if (string.IsNullOrEmpty(error) == false)
|
{
|
||||||
|
_steps = ESteps.UnpackBuildinManifest;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
string error = _queryBuildinPackageVersionOp.Error;
|
||||||
YooLogger.Log($"Failed to load buildin package version file : {error}");
|
YooLogger.Log($"Failed to load buildin package version file : {error}");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_appManifestCopyer = new AppManifestCopyer(_packageName, _appPackageVersionQuerier.Version);
|
|
||||||
_appManifestLoader = new AppManifestLoader(_packageName, _appPackageVersionQuerier.Version);
|
|
||||||
_steps = ESteps.CopyAppManifest;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.CopyAppManifest)
|
if (_steps == ESteps.UnpackBuildinManifest)
|
||||||
{
|
{
|
||||||
_appManifestCopyer.Update();
|
if (_unpackBuildinManifestOp == null)
|
||||||
Progress = _appManifestCopyer.Progress;
|
{
|
||||||
if (_appManifestCopyer.IsDone == false)
|
_unpackBuildinManifestOp = new UnpackBuildinManifestOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion);
|
||||||
|
OperationSystem.StartOperation(_unpackBuildinManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_unpackBuildinManifestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string error = _appManifestCopyer.Error;
|
if (_unpackBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||||
if (string.IsNullOrEmpty(error) == false)
|
{
|
||||||
|
_steps = ESteps.LoadBuildinManifest;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = error;
|
Error = _unpackBuildinManifestOp.Error;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.LoadAppManifest;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadAppManifest)
|
if (_steps == ESteps.LoadBuildinManifest)
|
||||||
{
|
{
|
||||||
_appManifestLoader.Update();
|
if (_loadBuildinManifestOp == null)
|
||||||
Progress = _appManifestLoader.Progress;
|
{
|
||||||
if (_appManifestLoader.IsDone == false)
|
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion);
|
||||||
|
OperationSystem.StartOperation(_loadBuildinManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Progress = _loadBuildinManifestOp.Progress;
|
||||||
|
if (_loadBuildinManifestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var manifest = _appManifestLoader.Manifest;
|
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
|
||||||
if (manifest == null)
|
{
|
||||||
|
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||||
|
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||||
|
_steps = ESteps.VerifyPackage;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _appManifestLoader.Error;
|
Error = _loadBuildinManifestOp.Error;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.VerifyPackage)
|
||||||
|
{
|
||||||
|
if (_verifyOperation == null)
|
||||||
{
|
{
|
||||||
InitializedPackageVersion = manifest.PackageVersion;
|
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
Progress = _verifyOperation.Progress;
|
||||||
{
|
if (_verifyOperation.IsDone)
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(false);
|
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
|
||||||
{
|
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置补丁清单版本查询器
|
/// 应用程序水印
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class AppPackageVersionQuerier
|
internal class AppFootPrint
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private string _footPrint;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 读取应用程序水印
|
||||||
|
/// </summary>
|
||||||
|
public void Load()
|
||||||
{
|
{
|
||||||
LoadStaticVersion,
|
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
|
||||||
CheckStaticVersion,
|
if (File.Exists(footPrintFilePath))
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly string _buildinPackageName;
|
|
||||||
private ESteps _steps = ESteps.LoadStaticVersion;
|
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内置包裹版本
|
|
||||||
/// </summary>
|
|
||||||
public string Version { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误日志
|
|
||||||
/// </summary>
|
|
||||||
public string Error { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已经完成
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDone
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
{
|
||||||
return _steps == ESteps.Done;
|
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
|
|
||||||
public AppPackageVersionQuerier(string buildinPackageName)
|
|
||||||
{
|
|
||||||
_buildinPackageName = buildinPackageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新流程
|
|
||||||
/// </summary>
|
|
||||||
public void Update()
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_steps == ESteps.LoadStaticVersion)
|
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(_buildinPackageName);
|
Coverage();
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
|
||||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
|
||||||
_downloader = new UnityWebDataRequester();
|
|
||||||
_downloader.SendRequest(url);
|
|
||||||
_steps = ESteps.CheckStaticVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckStaticVersion)
|
|
||||||
{
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_downloader.HasError())
|
|
||||||
{
|
|
||||||
Error = _downloader.GetError();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Version = _downloader.GetText();
|
|
||||||
if (string.IsNullOrEmpty(Version))
|
|
||||||
Error = $"Buildin package version file content is empty !";
|
|
||||||
}
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
_downloader.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内置补丁清单加载器
|
|
||||||
/// </summary>
|
|
||||||
internal class AppManifestLoader
|
|
||||||
{
|
|
||||||
private enum ESteps
|
|
||||||
{
|
|
||||||
LoadAppManifest,
|
|
||||||
CheckAppManifest,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly string _buildinPackageName;
|
|
||||||
private readonly string _buildinPackageVersion;
|
|
||||||
private ESteps _steps = ESteps.LoadAppManifest;
|
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载结果
|
|
||||||
/// </summary>
|
|
||||||
public PatchManifest Manifest { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误日志
|
|
||||||
/// </summary>
|
|
||||||
public string Error { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已经完成
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDone
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _steps == ESteps.Done;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载进度
|
/// 检测水印是否发生变化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Progress
|
public bool IsDirty()
|
||||||
{
|
{
|
||||||
get
|
#if UNITY_EDITOR
|
||||||
{
|
return _footPrint != Application.version;
|
||||||
if (_downloader == null)
|
#else
|
||||||
return 0;
|
return _footPrint != Application.buildGUID;
|
||||||
return _downloader.Progress();
|
#endif
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public AppManifestLoader(string buildinPackageName, string buildinPackageVersion)
|
|
||||||
{
|
|
||||||
_buildinPackageName = buildinPackageName;
|
|
||||||
_buildinPackageVersion = buildinPackageVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新流程
|
/// 覆盖掉水印
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Update()
|
public void Coverage()
|
||||||
{
|
{
|
||||||
if (IsDone)
|
#if UNITY_EDITOR
|
||||||
return;
|
_footPrint = Application.version;
|
||||||
|
#else
|
||||||
if (_steps == ESteps.LoadAppManifest)
|
_footPrint = Application.buildGUID;
|
||||||
{
|
#endif
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, _buildinPackageVersion);
|
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
FileUtility.CreateFile(footPrintFilePath, _footPrint);
|
||||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
YooLogger.Log($"Save application foot print : {_footPrint}");
|
||||||
_downloader = new UnityWebDataRequester();
|
|
||||||
_downloader.SendRequest(url);
|
|
||||||
_steps = ESteps.CheckAppManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckAppManifest)
|
|
||||||
{
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_downloader.HasError())
|
|
||||||
{
|
|
||||||
Error = _downloader.GetError();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 解析APP里的补丁清单
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Manifest = PatchManifest.Deserialize(_downloader.GetText());
|
|
||||||
}
|
|
||||||
catch (System.Exception e)
|
|
||||||
{
|
|
||||||
Error = e.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
_downloader.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内置补丁清单复制器
|
|
||||||
/// </summary>
|
|
||||||
internal class AppManifestCopyer
|
|
||||||
{
|
|
||||||
private enum ESteps
|
|
||||||
{
|
|
||||||
CopyAppManifest,
|
|
||||||
CheckAppManifest,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly string _buildinPackageName;
|
|
||||||
private readonly string _buildinPackageVersion;
|
|
||||||
private ESteps _steps = ESteps.CopyAppManifest;
|
|
||||||
private UnityWebFileRequester _downloader;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误日志
|
|
||||||
/// </summary>
|
|
||||||
public string Error { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已经完成
|
|
||||||
/// </summary>
|
|
||||||
public bool IsDone
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _steps == ESteps.Done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载进度
|
|
||||||
/// </summary>
|
|
||||||
public float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_downloader == null)
|
|
||||||
return 0;
|
|
||||||
return _downloader.Progress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public AppManifestCopyer(string buildinPackageName, string buildinPackageVersion)
|
|
||||||
{
|
|
||||||
_buildinPackageName = buildinPackageName;
|
|
||||||
_buildinPackageVersion = buildinPackageVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新流程
|
|
||||||
/// </summary>
|
|
||||||
public void Update()
|
|
||||||
{
|
|
||||||
if (IsDone)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_steps == ESteps.CopyAppManifest)
|
|
||||||
{
|
|
||||||
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName);
|
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_buildinPackageName, _buildinPackageVersion);
|
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
|
||||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
|
||||||
_downloader = new UnityWebFileRequester();
|
|
||||||
_downloader.SendRequest(url, savePath);
|
|
||||||
_steps = ESteps.CheckAppManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckAppManifest)
|
|
||||||
{
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_downloader.HasError())
|
|
||||||
{
|
|
||||||
Error = _downloader.GetError();
|
|
||||||
}
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
_downloader.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ba3f4fc8cf6941f4a96ab928cec547e3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class DeserializeManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
DeserializeFileHeader,
|
||||||
|
PrepareAssetList,
|
||||||
|
DeserializeAssetList,
|
||||||
|
PrepareBundleList,
|
||||||
|
DeserializeBundleList,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly BufferReader _buffer;
|
||||||
|
private int _patchAssetCount;
|
||||||
|
private int _patchBundleCount;
|
||||||
|
private int _progressTotalValue;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析的清单实例
|
||||||
|
/// </summary>
|
||||||
|
public PatchManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
public DeserializeManifestOperation(byte[] binaryData)
|
||||||
|
{
|
||||||
|
_buffer = new BufferReader(binaryData);
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.DeserializeFileHeader;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.DeserializeFileHeader)
|
||||||
|
{
|
||||||
|
if (_buffer.IsValid == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "Buffer is invalid !";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取文件标记
|
||||||
|
uint fileSign = _buffer.ReadUInt32();
|
||||||
|
if (fileSign != YooAssetSettings.PatchManifestFileSign)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "The manifest file format is invalid !";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取文件版本
|
||||||
|
string fileVersion = _buffer.ReadUTF8();
|
||||||
|
if (fileVersion != YooAssetSettings.PatchManifestFileVersion)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.PatchManifestFileVersion}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取文件头信息
|
||||||
|
Manifest = new PatchManifest();
|
||||||
|
Manifest.FileVersion = fileVersion;
|
||||||
|
Manifest.EnableAddressable = _buffer.ReadBool();
|
||||||
|
Manifest.OutputNameStyle = _buffer.ReadInt32();
|
||||||
|
Manifest.PackageName = _buffer.ReadUTF8();
|
||||||
|
Manifest.PackageVersion = _buffer.ReadUTF8();
|
||||||
|
|
||||||
|
_steps = ESteps.PrepareAssetList;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.PrepareAssetList)
|
||||||
|
{
|
||||||
|
_patchAssetCount = _buffer.ReadInt32();
|
||||||
|
Manifest.AssetList = new List<PatchAsset>(_patchAssetCount);
|
||||||
|
Manifest.AssetDic = new Dictionary<string, PatchAsset>(_patchAssetCount);
|
||||||
|
_progressTotalValue = _patchAssetCount;
|
||||||
|
_steps = ESteps.DeserializeAssetList;
|
||||||
|
}
|
||||||
|
if (_steps == ESteps.DeserializeAssetList)
|
||||||
|
{
|
||||||
|
while (_patchAssetCount > 0)
|
||||||
|
{
|
||||||
|
var patchAsset = new PatchAsset();
|
||||||
|
patchAsset.Address = _buffer.ReadUTF8();
|
||||||
|
patchAsset.AssetPath = _buffer.ReadUTF8();
|
||||||
|
patchAsset.AssetTags = _buffer.ReadUTF8Array();
|
||||||
|
patchAsset.BundleID = _buffer.ReadInt32();
|
||||||
|
patchAsset.DependIDs = _buffer.ReadInt32Array();
|
||||||
|
Manifest.AssetList.Add(patchAsset);
|
||||||
|
|
||||||
|
// 注意:我们不允许原始路径存在重名
|
||||||
|
string assetPath = patchAsset.AssetPath;
|
||||||
|
if (Manifest.AssetDic.ContainsKey(assetPath))
|
||||||
|
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||||
|
else
|
||||||
|
Manifest.AssetDic.Add(assetPath, patchAsset);
|
||||||
|
|
||||||
|
_patchAssetCount--;
|
||||||
|
Progress = 1f - _patchAssetCount / _progressTotalValue;
|
||||||
|
if (OperationSystem.IsBusy)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_patchAssetCount <= 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.PrepareBundleList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.PrepareBundleList)
|
||||||
|
{
|
||||||
|
_patchBundleCount = _buffer.ReadInt32();
|
||||||
|
Manifest.BundleList = new List<PatchBundle>(_patchBundleCount);
|
||||||
|
Manifest.BundleDic = new Dictionary<string, PatchBundle>(_patchBundleCount);
|
||||||
|
_progressTotalValue = _patchBundleCount;
|
||||||
|
_steps = ESteps.DeserializeBundleList;
|
||||||
|
}
|
||||||
|
if (_steps == ESteps.DeserializeBundleList)
|
||||||
|
{
|
||||||
|
while (_patchBundleCount > 0)
|
||||||
|
{
|
||||||
|
var patchBundle = new PatchBundle();
|
||||||
|
patchBundle.BundleName = _buffer.ReadUTF8();
|
||||||
|
patchBundle.FileHash = _buffer.ReadUTF8();
|
||||||
|
patchBundle.FileCRC = _buffer.ReadUTF8();
|
||||||
|
patchBundle.FileSize = _buffer.ReadInt64();
|
||||||
|
patchBundle.IsRawFile = _buffer.ReadBool();
|
||||||
|
patchBundle.LoadMethod = _buffer.ReadByte();
|
||||||
|
patchBundle.Tags = _buffer.ReadUTF8Array();
|
||||||
|
Manifest.BundleList.Add(patchBundle);
|
||||||
|
|
||||||
|
patchBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
|
||||||
|
Manifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
|
||||||
|
|
||||||
|
_patchBundleCount--;
|
||||||
|
Progress = 1f - _patchBundleCount / _progressTotalValue;
|
||||||
|
if (OperationSystem.IsBusy)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_patchBundleCount <= 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
Manifest = null;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = e.Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6b03684bc5163694ab3983243512b4cc
|
guid: a800be1f31ec6364f8cdd0d8c7eef269
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class DownloadManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
DownloadPackageHashFile,
|
||||||
|
DownloadManifestFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int RequestCount = 0;
|
||||||
|
private readonly IRemoteServices _remoteServices;
|
||||||
|
private readonly string _packageName;
|
||||||
|
private readonly string _packageVersion;
|
||||||
|
private readonly int _timeout;
|
||||||
|
private UnityWebFileRequester _downloader1;
|
||||||
|
private UnityWebFileRequester _downloader2;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
_remoteServices = remoteServices;
|
||||||
|
_packageName = packageName;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
RequestCount++;
|
||||||
|
_steps = ESteps.DownloadPackageHashFile;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.DownloadPackageHashFile)
|
||||||
|
{
|
||||||
|
if (_downloader1 == null)
|
||||||
|
{
|
||||||
|
string savePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||||
|
string webURL = GetDownloadRequestURL(fileName);
|
||||||
|
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
||||||
|
_downloader1 = new UnityWebFileRequester();
|
||||||
|
_downloader1.SendRequest(webURL, savePath, _timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader1.CheckTimeout();
|
||||||
|
if (_downloader1.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader1.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader1.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.DownloadManifestFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader1.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.DownloadManifestFile)
|
||||||
|
{
|
||||||
|
if (_downloader2 == null)
|
||||||
|
{
|
||||||
|
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||||
|
string webURL = GetDownloadRequestURL(fileName);
|
||||||
|
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||||
|
_downloader2 = new UnityWebFileRequester();
|
||||||
|
_downloader2.SendRequest(webURL, savePath, _timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader2.CheckTimeout();
|
||||||
|
if (_downloader2.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader2.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader2.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader2.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDownloadRequestURL(string fileName)
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
if (RequestCount % 2 == 0)
|
||||||
|
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||||
|
else
|
||||||
|
return _remoteServices.GetRemoteMainURL(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fccaa9437207a174d858ce44f14f5a03
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadBuildinManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadBuildinManifest,
|
||||||
|
CheckDeserializeManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _buildinPackageName;
|
||||||
|
private readonly string _buildinPackageVersion;
|
||||||
|
private UnityWebDataRequester _downloader;
|
||||||
|
private DeserializeManifestOperation _deserializer;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载的清单实例
|
||||||
|
/// </summary>
|
||||||
|
public PatchManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public LoadBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion)
|
||||||
|
{
|
||||||
|
_buildinPackageName = buildinPackageName;
|
||||||
|
_buildinPackageVersion = buildinPackageVersion;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadBuildinManifest;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadBuildinManifest)
|
||||||
|
{
|
||||||
|
if (_downloader == null)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||||
|
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||||
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
|
_downloader = new UnityWebDataRequester();
|
||||||
|
_downloader.SendRequest(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte[] bytesData = _downloader.GetData();
|
||||||
|
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||||
|
OperationSystem.StartOperation(_deserializer);
|
||||||
|
_steps = ESteps.CheckDeserializeManifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckDeserializeManifest)
|
||||||
|
{
|
||||||
|
Progress = _deserializer.Progress;
|
||||||
|
if (_deserializer.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
Manifest = _deserializer.Manifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _deserializer.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f3a2fe7d8d4747d43b3ac48097341e36
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadCacheManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
QueryCachePackageHash,
|
||||||
|
VerifyFileHash,
|
||||||
|
LoadCacheManifest,
|
||||||
|
CheckDeserializeManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _packageName;
|
||||||
|
private readonly string _packageVersion;
|
||||||
|
private QueryCachePackageHashOperation _queryCachePackageHashOp;
|
||||||
|
private DeserializeManifestOperation _deserializer;
|
||||||
|
private string _manifestFilePath;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载的清单实例
|
||||||
|
/// </summary>
|
||||||
|
public PatchManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public LoadCacheManifestOperation(string packageName, string packageVersion)
|
||||||
|
{
|
||||||
|
_packageName = packageName;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.QueryCachePackageHash;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.QueryCachePackageHash)
|
||||||
|
{
|
||||||
|
if (_queryCachePackageHashOp == null)
|
||||||
|
{
|
||||||
|
_queryCachePackageHashOp = new QueryCachePackageHashOperation(_packageName, _packageVersion);
|
||||||
|
OperationSystem.StartOperation(_queryCachePackageHashOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_queryCachePackageHashOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_queryCachePackageHashOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.VerifyFileHash;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _queryCachePackageHashOp.Error;
|
||||||
|
ClearCacheFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.VerifyFileHash)
|
||||||
|
{
|
||||||
|
_manifestFilePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||||
|
if (File.Exists(_manifestFilePath) == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Not found cache manifest file : {_manifestFilePath}";
|
||||||
|
ClearCacheFile();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileHash = HashUtility.FileMD5(_manifestFilePath);
|
||||||
|
if (fileHash != _queryCachePackageHashOp.PackageHash)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "Failed to verify cache manifest file hash !";
|
||||||
|
ClearCacheFile();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadCacheManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadCacheManifest)
|
||||||
|
{
|
||||||
|
byte[] bytesData = File.ReadAllBytes(_manifestFilePath);
|
||||||
|
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||||
|
OperationSystem.StartOperation(_deserializer);
|
||||||
|
_steps = ESteps.CheckDeserializeManifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckDeserializeManifest)
|
||||||
|
{
|
||||||
|
Progress = _deserializer.Progress;
|
||||||
|
if (_deserializer.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
Manifest = _deserializer.Manifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _deserializer.Error;
|
||||||
|
ClearCacheFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearCacheFile()
|
||||||
|
{
|
||||||
|
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,主动把损坏的文件删除。
|
||||||
|
if (File.Exists(_manifestFilePath))
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Failed to load cache manifest file : {Error}");
|
||||||
|
YooLogger.Warning($"Invalid cache manifest file have been removed : {_manifestFilePath}");
|
||||||
|
File.Delete(_manifestFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
string hashFilePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||||
|
if (File.Exists(hashFilePath))
|
||||||
|
{
|
||||||
|
File.Delete(hashFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5067db2d5b2aa1240aef2f9a952a2e0c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadEditorManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadEditorManifest,
|
||||||
|
CheckDeserializeManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _manifestFilePath;
|
||||||
|
private DeserializeManifestOperation _deserializer;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载的清单实例
|
||||||
|
/// </summary>
|
||||||
|
public PatchManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public LoadEditorManifestOperation(string manifestFilePath)
|
||||||
|
{
|
||||||
|
_manifestFilePath = manifestFilePath;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadEditorManifest;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadEditorManifest)
|
||||||
|
{
|
||||||
|
if (File.Exists(_manifestFilePath) == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Not found simulation manifest file : {_manifestFilePath}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YooLogger.Log($"Load editor manifest file : {_manifestFilePath}");
|
||||||
|
byte[] bytesData = FileUtility.ReadAllBytes(_manifestFilePath);
|
||||||
|
_deserializer = new DeserializeManifestOperation(bytesData);
|
||||||
|
OperationSystem.StartOperation(_deserializer);
|
||||||
|
_steps = ESteps.CheckDeserializeManifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckDeserializeManifest)
|
||||||
|
{
|
||||||
|
Progress = _deserializer.Progress;
|
||||||
|
if (_deserializer.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_deserializer.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
Manifest = _deserializer.Manifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _deserializer.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 246df4d20b431c648a0821231a805e6b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class QueryBuildinPackageVersionOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadBuildinPackageVersionFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _packageName;
|
||||||
|
private UnityWebDataRequester _downloader;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包裹版本
|
||||||
|
/// </summary>
|
||||||
|
public string PackageVersion { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public QueryBuildinPackageVersionOperation(string packageName)
|
||||||
|
{
|
||||||
|
_packageName = packageName;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadBuildinPackageVersionFile;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadBuildinPackageVersionFile)
|
||||||
|
{
|
||||||
|
if (_downloader == null)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||||
|
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||||
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
|
_downloader = new UnityWebDataRequester();
|
||||||
|
_downloader.SendRequest(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PackageVersion = _downloader.GetText();
|
||||||
|
if (string.IsNullOrEmpty(PackageVersion))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Buildin package version file content is empty !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdc251ea99d82e54199dfba540f2814d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class QueryCachePackageHashOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadCachePackageHashFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _packageName;
|
||||||
|
private readonly string _packageVersion;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包裹哈希值
|
||||||
|
/// </summary>
|
||||||
|
public string PackageHash { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public QueryCachePackageHashOperation(string packageName, string packageVersion)
|
||||||
|
{
|
||||||
|
_packageName = packageName;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadCachePackageHashFile;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadCachePackageHashFile)
|
||||||
|
{
|
||||||
|
string filePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||||
|
if (File.Exists(filePath) == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Cache package hash file not found : {filePath}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageHash = FileUtility.ReadAllText(filePath);
|
||||||
|
if (string.IsNullOrEmpty(PackageHash))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Cache package hash file content is empty !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 60db6a6586340664ab7e9f85cec0eef4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class QueryCachePackageVersionOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadCachePackageVersionFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _packageName;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包裹版本
|
||||||
|
/// </summary>
|
||||||
|
public string PackageVersion { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public QueryCachePackageVersionOperation(string packageName)
|
||||||
|
{
|
||||||
|
_packageName = packageName;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadCachePackageVersionFile;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadCachePackageVersionFile)
|
||||||
|
{
|
||||||
|
string filePath = PersistentHelper.GetCachePackageVersionFilePath(_packageName);
|
||||||
|
if (File.Exists(filePath) == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Cache package version file not found : {filePath}";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageVersion = FileUtility.ReadAllText(filePath);
|
||||||
|
if (string.IsNullOrEmpty(PackageVersion))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Cache package version file content is empty !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 29a2cbdd051ba1247a24693d56cdc2c3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class QueryRemotePackageVersionOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
DownloadPackageVersion,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int RequestCount = 0;
|
||||||
|
private readonly IRemoteServices _remoteServices;
|
||||||
|
private readonly string _packageName;
|
||||||
|
private readonly bool _appendTimeTicks;
|
||||||
|
private readonly int _timeout;
|
||||||
|
private UnityWebDataRequester _downloader;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 包裹版本
|
||||||
|
/// </summary>
|
||||||
|
public string PackageVersion { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout)
|
||||||
|
{
|
||||||
|
_remoteServices = remoteServices;
|
||||||
|
_packageName = packageName;
|
||||||
|
_appendTimeTicks = appendTimeTicks;
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
RequestCount++;
|
||||||
|
_steps = ESteps.DownloadPackageVersion;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.DownloadPackageVersion)
|
||||||
|
{
|
||||||
|
if (_downloader == null)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||||
|
string webURL = GetPackageVersionRequestURL(fileName);
|
||||||
|
YooLogger.Log($"Beginning to request package version : {webURL}");
|
||||||
|
_downloader = new UnityWebDataRequester();
|
||||||
|
_downloader.SendRequest(webURL, _timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
Progress = _downloader.Progress();
|
||||||
|
if (_downloader.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PackageVersion = _downloader.GetText();
|
||||||
|
if (string.IsNullOrEmpty(PackageVersion))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Remote package version is empty : {_downloader.URL}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetPackageVersionRequestURL(string fileName)
|
||||||
|
{
|
||||||
|
string url;
|
||||||
|
|
||||||
|
// 轮流返回请求地址
|
||||||
|
if (RequestCount % 2 == 0)
|
||||||
|
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||||
|
else
|
||||||
|
url = _remoteServices.GetRemoteMainURL(fileName);
|
||||||
|
|
||||||
|
// 在URL末尾添加时间戳
|
||||||
|
if (_appendTimeTicks)
|
||||||
|
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
||||||
|
else
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1d702a1a39789a34da99cbb854708b82
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnpackBuildinManifestOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
UnpackManifestHashFile,
|
||||||
|
UnpackManifestFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string _buildinPackageName;
|
||||||
|
private readonly string _buildinPackageVersion;
|
||||||
|
private UnityWebFileRequester _downloader1;
|
||||||
|
private UnityWebFileRequester _downloader2;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public UnpackBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion)
|
||||||
|
{
|
||||||
|
_buildinPackageName = buildinPackageName;
|
||||||
|
_buildinPackageVersion = buildinPackageVersion;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.UnpackManifestHashFile;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(_steps == ESteps.UnpackManifestHashFile)
|
||||||
|
{
|
||||||
|
if (_downloader1 == null)
|
||||||
|
{
|
||||||
|
string savePath = PersistentHelper.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
|
||||||
|
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||||
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
|
_downloader1 = new UnityWebFileRequester();
|
||||||
|
_downloader1.SendRequest(url, savePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloader1.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader1.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader1.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.UnpackManifestFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader1.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.UnpackManifestFile)
|
||||||
|
{
|
||||||
|
if (_downloader2 == null)
|
||||||
|
{
|
||||||
|
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||||
|
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
|
||||||
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
|
_downloader2 = new UnityWebFileRequester();
|
||||||
|
_downloader2.SendRequest(url, savePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloader2.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader2.HasError())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloader2.GetError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
_downloader2.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a7685e67b0e948439ffba34513b78c0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal abstract class VerifyPackageOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
public List<VerifyInfo> VerifySuccessList { protected set; get; }
|
||||||
|
public List<VerifyInfo> VerifyFailList { protected set; get; }
|
||||||
|
|
||||||
|
public static VerifyPackageOperation CreateOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||||
|
{
|
||||||
|
#if UNITY_WEBGL
|
||||||
|
VerifyPackageOperation operation = new VerifyPackageWithoutThreadOperation(manifest, playModeServices);
|
||||||
|
#else
|
||||||
|
VerifyPackageOperation operation = new VerifyPackageWithThreadOperation(manifest, playModeServices);
|
||||||
|
#endif
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地缓存文件验证(线程版)
|
||||||
|
/// </summary>
|
||||||
|
internal class VerifyPackageWithThreadOperation : VerifyPackageOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
InitVerify,
|
||||||
|
PrepareVerify,
|
||||||
|
UpdateVerify,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PatchManifest _manifest;
|
||||||
|
private readonly IPlayModeServices _playModeServices;
|
||||||
|
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||||
|
private List<VerifyInfo> _waitingList;
|
||||||
|
private List<VerifyInfo> _verifyingList;
|
||||||
|
private int _verifyMaxNum;
|
||||||
|
private int _verifyTotalCount;
|
||||||
|
private float _verifyStartTime;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public VerifyPackageWithThreadOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||||
|
{
|
||||||
|
_manifest = manifest;
|
||||||
|
_playModeServices = playModeServices;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.InitVerify;
|
||||||
|
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.InitVerify)
|
||||||
|
{
|
||||||
|
int bundleCount = _manifest.BundleList.Count;
|
||||||
|
VerifySuccessList = new List<VerifyInfo>(bundleCount);
|
||||||
|
VerifyFailList = new List<VerifyInfo>(bundleCount);
|
||||||
|
|
||||||
|
// 设置同时验证的最大数
|
||||||
|
ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
|
||||||
|
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||||
|
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||||
|
_verifyTotalCount = bundleCount;
|
||||||
|
if (_verifyMaxNum < 1)
|
||||||
|
_verifyMaxNum = 1;
|
||||||
|
|
||||||
|
_waitingList = new List<VerifyInfo>(bundleCount);
|
||||||
|
_verifyingList = new List<VerifyInfo>(_verifyMaxNum);
|
||||||
|
_steps = ESteps.PrepareVerify;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.PrepareVerify)
|
||||||
|
{
|
||||||
|
foreach (var patchBundle in _manifest.BundleList)
|
||||||
|
{
|
||||||
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
|
||||||
|
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
||||||
|
_waitingList.Add(verifyInfo);
|
||||||
|
}
|
||||||
|
_steps = ESteps.UpdateVerify;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.UpdateVerify)
|
||||||
|
{
|
||||||
|
_syncContext.Update();
|
||||||
|
|
||||||
|
Progress = GetVerifierProgress();
|
||||||
|
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||||
|
YooLogger.Log($"Verify elapsed time {costTime:f1} seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (OperationSystem.IsBusy)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (_verifyingList.Count >= _verifyMaxNum)
|
||||||
|
break;
|
||||||
|
|
||||||
|
var verifyIno = _waitingList[i];
|
||||||
|
if (VerifyFileWithThread(verifyIno))
|
||||||
|
{
|
||||||
|
_waitingList.RemoveAt(i);
|
||||||
|
_verifyingList.Add(verifyIno);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
YooLogger.Warning("The thread pool is failed queued.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetVerifierProgress()
|
||||||
|
{
|
||||||
|
if (_verifyTotalCount == 0)
|
||||||
|
return 1f;
|
||||||
|
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
||||||
|
}
|
||||||
|
private bool VerifyFileWithThread(VerifyInfo verifyInfo)
|
||||||
|
{
|
||||||
|
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), verifyInfo);
|
||||||
|
}
|
||||||
|
private void VerifyInThread(object infoObj)
|
||||||
|
{
|
||||||
|
VerifyInfo verifyInfo = (VerifyInfo)infoObj;
|
||||||
|
verifyInfo.Result = CacheSystem.VerifyBundle(verifyInfo.VerifyBundle, CacheSystem.InitVerifyLevel);
|
||||||
|
_syncContext.Post(VerifyCallback, verifyInfo);
|
||||||
|
}
|
||||||
|
private void VerifyCallback(object obj)
|
||||||
|
{
|
||||||
|
VerifyInfo verifyIno = (VerifyInfo)obj;
|
||||||
|
if (verifyIno.Result == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
VerifySuccessList.Add(verifyIno);
|
||||||
|
CacheSystem.CacheBundle(verifyIno.VerifyBundle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VerifyFailList.Add(verifyIno);
|
||||||
|
|
||||||
|
// 删除验证失败的缓存文件
|
||||||
|
if (File.Exists(verifyIno.VerifyBundle.CachedFilePath))
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Delete verify failed bundle file : {verifyIno.VerifyBundle.CachedFilePath}");
|
||||||
|
File.Delete(verifyIno.VerifyBundle.CachedFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_verifyingList.Remove(verifyIno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地缓存文件验证(非线程版)
|
||||||
|
/// </summary>
|
||||||
|
internal class VerifyPackageWithoutThreadOperation : VerifyPackageOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
InitVerify,
|
||||||
|
PrepareVerify,
|
||||||
|
UpdateVerify,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PatchManifest _manifest;
|
||||||
|
private readonly IPlayModeServices _playModeServices;
|
||||||
|
private List<VerifyInfo> _waitingList;
|
||||||
|
private List<VerifyInfo> _verifyingList;
|
||||||
|
private int _verifyMaxNum;
|
||||||
|
private int _verifyTotalCount;
|
||||||
|
private float _verifyStartTime;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
public VerifyPackageWithoutThreadOperation(PatchManifest manifest, IPlayModeServices playModeServices)
|
||||||
|
{
|
||||||
|
_manifest = manifest;
|
||||||
|
_playModeServices = playModeServices;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.InitVerify;
|
||||||
|
_verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.InitVerify)
|
||||||
|
{
|
||||||
|
int bundleCount = _manifest.BundleList.Count;
|
||||||
|
VerifySuccessList = new List<VerifyInfo>(bundleCount);
|
||||||
|
VerifyFailList = new List<VerifyInfo>(bundleCount);
|
||||||
|
|
||||||
|
// 设置同时验证的最大数
|
||||||
|
_verifyMaxNum = bundleCount;
|
||||||
|
_verifyTotalCount = _waitingList.Count;
|
||||||
|
|
||||||
|
_waitingList = new List<VerifyInfo>(bundleCount);
|
||||||
|
_verifyingList = new List<VerifyInfo>(_verifyMaxNum);
|
||||||
|
_steps = ESteps.PrepareVerify;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.PrepareVerify)
|
||||||
|
{
|
||||||
|
foreach (var patchBundle in _manifest.BundleList)
|
||||||
|
{
|
||||||
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
|
||||||
|
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
||||||
|
_waitingList.Add(verifyInfo);
|
||||||
|
}
|
||||||
|
_steps = ESteps.UpdateVerify;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.UpdateVerify)
|
||||||
|
{
|
||||||
|
Progress = GetVerifierProgress();
|
||||||
|
if (_waitingList.Count == 0 && _verifyingList.Count == 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
|
||||||
|
YooLogger.Log($"Verify elapsed time {costTime:f1} seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = _waitingList.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (OperationSystem.IsBusy)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (_verifyingList.Count >= _verifyMaxNum)
|
||||||
|
break;
|
||||||
|
|
||||||
|
var verifyIno = _waitingList[i];
|
||||||
|
VerifyFileWithoutThread(verifyIno);
|
||||||
|
_waitingList.RemoveAt(i);
|
||||||
|
_verifyingList.Add(verifyIno);
|
||||||
|
}
|
||||||
|
|
||||||
|
_verifyingList.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetVerifierProgress()
|
||||||
|
{
|
||||||
|
if (_verifyTotalCount == 0)
|
||||||
|
return 1f;
|
||||||
|
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
|
||||||
|
}
|
||||||
|
private void VerifyFileWithoutThread(VerifyInfo verifyIno)
|
||||||
|
{
|
||||||
|
var verifyResult = CacheSystem.VerifyAndCacheLocalBundleFile(verifyIno.VerifyBundle, CacheSystem.InitVerifyLevel);
|
||||||
|
if (verifyResult == EVerifyResult.Succeed)
|
||||||
|
{
|
||||||
|
VerifySuccessList.Add(verifyIno);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VerifyFailList.Add(verifyIno);
|
||||||
|
|
||||||
|
// 删除验证失败的缓存文件
|
||||||
|
if (File.Exists(verifyIno.VerifyBundle.CachedFilePath))
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Delete verify failed bundle file : {verifyIno.VerifyBundle.CachedFilePath}");
|
||||||
|
File.Delete(verifyIno.VerifyBundle.CachedFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 868188d19436b674b8c403d2d90afeaf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,261 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
public abstract class PreDownloadPackageOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建补丁下载器,用于下载更新指定资源版本所有的资源包文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||||
|
/// <param name="timeout">超时时间</param>
|
||||||
|
public virtual PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建补丁下载器,用于下载更新资源标签指定的资源包文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">资源标签</param>
|
||||||
|
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||||
|
/// <param name="timeout">超时时间</param>
|
||||||
|
public virtual PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建补丁下载器,用于下载更新资源标签指定的资源包文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tags">资源标签列表</param>
|
||||||
|
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||||
|
/// <param name="timeout">超时时间</param>
|
||||||
|
public virtual PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建补丁下载器,用于下载更新指定的资源列表依赖的资源包文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="locations">资源定位列表</param>
|
||||||
|
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
||||||
|
/// <param name="timeout">超时时间</param>
|
||||||
|
public virtual PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EditorPlayModePreDownloadPackageOperation : PreDownloadPackageOperation
|
||||||
|
{
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class OfflinePlayModePreDownloadPackageOperation : PreDownloadPackageOperation
|
||||||
|
{
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class HostPlayModePreDownloadPackageOperation : PreDownloadPackageOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CheckActiveManifest,
|
||||||
|
TryLoadCacheManifest,
|
||||||
|
DownloadManifest,
|
||||||
|
LoadCacheManifest,
|
||||||
|
CheckDeserializeManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly HostPlayModeImpl _impl;
|
||||||
|
private readonly string _packageName;
|
||||||
|
private readonly string _packageVersion;
|
||||||
|
private readonly int _timeout;
|
||||||
|
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||||
|
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||||
|
private DownloadManifestOperation _downloadManifestOp;
|
||||||
|
private PatchManifest _manifest;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal HostPlayModePreDownloadPackageOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
_impl = impl;
|
||||||
|
_packageName = packageName;
|
||||||
|
_packageVersion = packageVersion;
|
||||||
|
_timeout = timeout;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CheckActiveManifest;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckActiveManifest)
|
||||||
|
{
|
||||||
|
// 检测当前激活的清单对象
|
||||||
|
if (_impl.ActiveManifest != null)
|
||||||
|
{
|
||||||
|
if (_impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||||
|
{
|
||||||
|
_manifest = _impl.ActiveManifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_steps = ESteps.TryLoadCacheManifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.TryLoadCacheManifest)
|
||||||
|
{
|
||||||
|
if (_tryLoadCacheManifestOp == null)
|
||||||
|
{
|
||||||
|
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||||
|
OperationSystem.StartOperation(_tryLoadCacheManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_manifest = _tryLoadCacheManifestOp.Manifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.DownloadManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.DownloadManifest)
|
||||||
|
{
|
||||||
|
if (_downloadManifestOp == null)
|
||||||
|
{
|
||||||
|
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
||||||
|
OperationSystem.StartOperation(_downloadManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloadManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadCacheManifest;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _downloadManifestOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadCacheManifest)
|
||||||
|
{
|
||||||
|
if (_loadCacheManifestOp == null)
|
||||||
|
{
|
||||||
|
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||||
|
OperationSystem.StartOperation(_loadCacheManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_manifest = _loadCacheManifestOp.Manifest;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _loadCacheManifestOp.Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
if (Status != EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !");
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
||||||
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
public override PatchDownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
if (Status != EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !");
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
||||||
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
public override PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
if (Status != EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !");
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
||||||
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
public override PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
|
{
|
||||||
|
if (Status != EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"{nameof(PreDownloadPackageOperation)} status is not succeed !");
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||||
|
foreach (var location in locations)
|
||||||
|
{
|
||||||
|
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
|
||||||
|
assetInfos.Add(assetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
|
||||||
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 51f7a5e97aff1a646972c4ea11612947
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -10,10 +9,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
|
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 是否发现了新的补丁清单
|
|
||||||
/// </summary>
|
|
||||||
public bool FoundNewManifest { protected set; get; } = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -21,6 +16,9 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||||
{
|
{
|
||||||
|
public EditorPlayModeUpdatePackageManifestOperation()
|
||||||
|
{
|
||||||
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -35,6 +33,9 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||||
{
|
{
|
||||||
|
public OfflinePlayModeUpdatePackageManifestOperation()
|
||||||
|
{
|
||||||
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -46,36 +47,32 @@ namespace YooAsset
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 联机模式的更新清单操作
|
/// 联机模式的更新清单操作
|
||||||
/// 注意:优先比对沙盒清单哈希值,如果有变化就更新远端清单文件,并保存到本地。
|
/// 注意:优先加载沙盒里缓存的清单文件,如果有变化就更新远端清单文件,并保存到本地。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
TryLoadCacheHash,
|
CheckActiveManifest,
|
||||||
LoadWebHash,
|
TryLoadCacheManifest,
|
||||||
CheckWebHash,
|
DownloadManifest,
|
||||||
LoadCacheManifest,
|
LoadCacheManifest,
|
||||||
LoadWebManifest,
|
CheckDeserializeManifest,
|
||||||
CheckWebManifest,
|
VerifyPackage,
|
||||||
InitVerifyingCache,
|
|
||||||
UpdateVerifyingCache,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int RequestCount = 0;
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly CacheVerifier _cacheVerifier;
|
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequester _downloader1;
|
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||||
private UnityWebDataRequester _downloader2;
|
private LoadCacheManifestOperation _loadCacheManifestOp;
|
||||||
|
private DownloadManifestOperation _downloadManifestOp;
|
||||||
private string _cacheManifestHash;
|
private VerifyPackageOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _verifyTime;
|
|
||||||
|
|
||||||
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
|
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
|
||||||
{
|
{
|
||||||
@@ -83,164 +80,114 @@ namespace YooAsset
|
|||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
|
|
||||||
#if UNITY_WEBGL
|
|
||||||
_cacheVerifier = new CacheVerifierWithoutThread();
|
|
||||||
#else
|
|
||||||
_cacheVerifier = new CacheVerifierWithThread();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
RequestCount++;
|
_steps = ESteps.CheckActiveManifest;
|
||||||
_steps = ESteps.TryLoadCacheHash;
|
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.TryLoadCacheHash)
|
if (_steps == ESteps.CheckActiveManifest)
|
||||||
{
|
{
|
||||||
string filePath = PersistentHelper.GetCacheManifestFilePath(_packageName);
|
// 检测当前激活的清单对象
|
||||||
if (File.Exists(filePath))
|
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||||
{
|
{
|
||||||
_cacheManifestHash = HashUtility.FileMD5(filePath);
|
_steps = ESteps.Done;
|
||||||
_steps = ESteps.LoadWebHash;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.LoadWebManifest;
|
_steps = ESteps.TryLoadCacheManifest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadWebHash)
|
if (_steps == ESteps.TryLoadCacheManifest)
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestHashFileName(_packageName, _packageVersion);
|
if (_tryLoadCacheManifestOp == null)
|
||||||
string webURL = GetPatchManifestRequestURL(fileName);
|
{
|
||||||
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||||
_downloader1 = new UnityWebDataRequester();
|
OperationSystem.StartOperation(_tryLoadCacheManifestOp);
|
||||||
_downloader1.SendRequest(webURL, _timeout);
|
}
|
||||||
_steps = ESteps.CheckWebHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckWebHash)
|
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||||
{
|
|
||||||
if (_downloader1.IsDone() == false)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloader1.HasError())
|
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_impl.ActiveManifest = _tryLoadCacheManifestOp.Manifest;
|
||||||
|
_steps = ESteps.VerifyPackage;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.DownloadManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.DownloadManifest)
|
||||||
|
{
|
||||||
|
if (_downloadManifestOp == null)
|
||||||
|
{
|
||||||
|
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
||||||
|
OperationSystem.StartOperation(_downloadManifestOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_downloadManifestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadCacheManifest;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloader1.GetError();
|
Error = _downloadManifestOp.Error;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
string webManifestHash = _downloader1.GetText();
|
|
||||||
if (_cacheManifestHash == webManifestHash)
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Not found new package : {_packageName}");
|
|
||||||
_steps = ESteps.LoadCacheManifest;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Package {_packageName} is change : {_cacheManifestHash} -> {webManifestHash}");
|
|
||||||
_steps = ESteps.LoadWebManifest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_downloader1.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.LoadCacheManifest)
|
if (_steps == ESteps.LoadCacheManifest)
|
||||||
{
|
{
|
||||||
try
|
if (_loadCacheManifestOp == null)
|
||||||
{
|
{
|
||||||
var manifest = PersistentHelper.LoadCacheManifestFile(_packageName);
|
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
OperationSystem.StartOperation(_loadCacheManifestOp);
|
||||||
_steps = ESteps.InitVerifyingCache;
|
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
|
||||||
{
|
|
||||||
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,我们主动把损坏的文件删除。
|
|
||||||
YooLogger.Warning($"Failed to load cache manifest file : {e.Message}");
|
|
||||||
PersistentHelper.DeleteCacheManifestFile(_packageName);
|
|
||||||
_steps = ESteps.LoadWebManifest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.LoadWebManifest)
|
if (_loadCacheManifestOp.IsDone == false)
|
||||||
{
|
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestFileName(_packageName, _packageVersion);
|
|
||||||
string webURL = GetPatchManifestRequestURL(fileName);
|
|
||||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
|
||||||
_downloader2 = new UnityWebDataRequester();
|
|
||||||
_downloader2.SendRequest(webURL, _timeout);
|
|
||||||
_steps = ESteps.CheckWebManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckWebManifest)
|
|
||||||
{
|
|
||||||
if (_downloader2.IsDone() == false)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloader2.HasError())
|
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
|
||||||
Status = EOperationStatus.Failed;
|
_steps = ESteps.VerifyPackage;
|
||||||
Error = _downloader2.GetError();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
_steps = ESteps.Done;
|
||||||
{
|
Status = EOperationStatus.Failed;
|
||||||
string content = _downloader2.GetText();
|
Error = _loadCacheManifestOp.Error;
|
||||||
var manifest = PersistentHelper.SaveCacheManifestFile(_packageName, content);
|
|
||||||
_impl.SetLocalPatchManifest(manifest);
|
|
||||||
FoundNewManifest = true;
|
|
||||||
_steps = ESteps.InitVerifyingCache;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = e.Message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_downloader2.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.VerifyPackage)
|
||||||
{
|
{
|
||||||
var verifyInfos = _impl.GetVerifyInfoList(false);
|
if (_verifyOperation == null)
|
||||||
_cacheVerifier.InitVerifier(verifyInfos);
|
{
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl);
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
OperationSystem.StartOperation(_verifyOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
Progress = _verifyOperation.Progress;
|
||||||
{
|
if (_verifyOperation.IsDone)
|
||||||
Progress = _cacheVerifier.GetVerifierProgress();
|
|
||||||
if (_cacheVerifier.UpdateVerifier())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
|
||||||
YooLogger.Log($"Verify result : Success {_cacheVerifier.VerifySuccessList.Count}, Fail {_cacheVerifier.VerifyFailList.Count}, Elapsed time {costTime} seconds");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取补丁清单请求地址
|
|
||||||
/// </summary>
|
|
||||||
private string GetPatchManifestRequestURL(string fileName)
|
|
||||||
{
|
|
||||||
// 轮流返回请求地址
|
|
||||||
if (RequestCount % 2 == 0)
|
|
||||||
return _impl.GetPatchDownloadFallbackURL(fileName);
|
|
||||||
else
|
|
||||||
return _impl.GetPatchDownloadMainURL(fileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,87 +51,57 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadStaticVersion,
|
QueryRemotePackageVersion,
|
||||||
CheckStaticVersion,
|
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int RequestCount = 0;
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
|
private readonly bool _appendTimeTicks;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
|
private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebDataRequester _downloader;
|
|
||||||
|
|
||||||
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, int timeout)
|
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout)
|
||||||
{
|
{
|
||||||
_impl = impl;
|
_impl = impl;
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
|
_appendTimeTicks = appendTimeTicks;
|
||||||
_timeout = timeout;
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void Start()
|
internal override void Start()
|
||||||
{
|
{
|
||||||
RequestCount++;
|
_steps = ESteps.QueryRemotePackageVersion;
|
||||||
_steps = ESteps.LoadStaticVersion;
|
|
||||||
}
|
}
|
||||||
internal override void Update()
|
internal override void Update()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.LoadStaticVersion)
|
if (_steps == ESteps.QueryRemotePackageVersion)
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(_packageName);
|
if (_queryRemotePackageVersionOp == null)
|
||||||
string webURL = GetStaticVersionRequestURL(fileName);
|
{
|
||||||
YooLogger.Log($"Beginning to request static version : {webURL}");
|
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout);
|
||||||
_downloader = new UnityWebDataRequester();
|
OperationSystem.StartOperation(_queryRemotePackageVersionOp);
|
||||||
_downloader.SendRequest(webURL, _timeout);
|
}
|
||||||
_steps = ESteps.CheckStaticVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_steps == ESteps.CheckStaticVersion)
|
if (_queryRemotePackageVersionOp.IsDone == false)
|
||||||
{
|
|
||||||
Progress = _downloader.Progress();
|
|
||||||
if (_downloader.IsDone() == false)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloader.HasError())
|
if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
|
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Succeed;
|
||||||
Error = _downloader.GetError();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PackageVersion = _downloader.GetText();
|
_steps = ESteps.Done;
|
||||||
if (string.IsNullOrEmpty(PackageVersion))
|
Status = EOperationStatus.Failed;
|
||||||
{
|
Error = _queryRemotePackageVersionOp.Error;
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"Static package version is empty : {_downloader.URL}";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_downloader.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetStaticVersionRequestURL(string fileName)
|
|
||||||
{
|
|
||||||
string url;
|
|
||||||
|
|
||||||
// 轮流返回请求地址
|
|
||||||
if (RequestCount % 2 == 0)
|
|
||||||
url = _impl.GetPatchDownloadFallbackURL(fileName);
|
|
||||||
else
|
|
||||||
url = _impl.GetPatchDownloadMainURL(fileName);
|
|
||||||
|
|
||||||
// 注意:在URL末尾添加时间戳
|
|
||||||
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,15 +109,8 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PatchBundle(string bundleName, string fileHash, string fileCRC, long fileSize, bool isRawFile, byte loadMethod, string[] tags)
|
public PatchBundle()
|
||||||
{
|
{
|
||||||
BundleName = bundleName;
|
|
||||||
FileHash = fileHash;
|
|
||||||
FileCRC = fileCRC;
|
|
||||||
FileSize = fileSize;
|
|
||||||
IsRawFile = isRawFile;
|
|
||||||
LoadMethod = loadMethod;
|
|
||||||
Tags = tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -127,7 +120,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_cacheKey = $"{packageName}-{FileHash}";
|
_cacheKey = $"{packageName}-{FileHash}";
|
||||||
_fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash);
|
_fileName = PatchManifestTools.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -52,19 +52,19 @@ namespace YooAsset
|
|||||||
/// 资源包集合(提供BundleName获取PatchBundle)
|
/// 资源包集合(提供BundleName获取PatchBundle)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchBundle> BundleDic = new Dictionary<string, PatchBundle>();
|
public Dictionary<string, PatchBundle> BundleDic;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchAsset> AssetDic = new Dictionary<string, PatchAsset>();
|
public Dictionary<string, PatchAsset> AssetDic;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径映射集合
|
/// 资源路径映射集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, string> AssetPathMapping = new Dictionary<string, string>();
|
public Dictionary<string, string> AssetPathMapping;
|
||||||
|
|
||||||
// 资源路径映射相关
|
// 资源路径映射相关
|
||||||
private bool _isInitAssetPathMapping = false;
|
private bool _isInitAssetPathMapping = false;
|
||||||
@@ -85,6 +85,7 @@ namespace YooAsset
|
|||||||
if (locationToLower)
|
if (locationToLower)
|
||||||
YooLogger.Error("Addressable not support location to lower !");
|
YooLogger.Error("Addressable not support location to lower !");
|
||||||
|
|
||||||
|
AssetPathMapping = new Dictionary<string, string>(AssetList.Count);
|
||||||
foreach (var patchAsset in AssetList)
|
foreach (var patchAsset in AssetList)
|
||||||
{
|
{
|
||||||
string location = patchAsset.Address;
|
string location = patchAsset.Address;
|
||||||
@@ -97,6 +98,7 @@ namespace YooAsset
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_locationToLower = locationToLower;
|
_locationToLower = locationToLower;
|
||||||
|
AssetPathMapping = new Dictionary<string, string>(AssetList.Count * 2);
|
||||||
foreach (var patchAsset in AssetList)
|
foreach (var patchAsset in AssetList)
|
||||||
{
|
{
|
||||||
string location = patchAsset.AssetPath;
|
string location = patchAsset.AssetPath;
|
||||||
@@ -264,80 +266,50 @@ namespace YooAsset
|
|||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 序列化
|
/// 资源定位地址转换为资源信息类,失败时内部会发出错误日志。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Serialize(string savePath, PatchManifest patchManifest)
|
/// <returns>如果转换失败会返回一个无效的资源信息类</returns>
|
||||||
|
public AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
|
||||||
{
|
{
|
||||||
string json = JsonUtility.ToJson(patchManifest);
|
DebugCheckLocation(location);
|
||||||
FileUtility.CreateFile(savePath, json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
string assetPath = MappingToAssetPath(location);
|
||||||
/// 反序列化
|
if (TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
/// </summary>
|
|
||||||
public static PatchManifest Deserialize(string jsonData)
|
|
||||||
{
|
|
||||||
PatchManifest patchManifest = JsonUtility.FromJson<PatchManifest>(jsonData);
|
|
||||||
if (patchManifest == null)
|
|
||||||
throw new System.Exception($"{nameof(PatchManifest)} deserialize object is null !");
|
|
||||||
|
|
||||||
// 检测文件版本
|
|
||||||
if (patchManifest.FileVersion != YooAssetSettings.PatchManifestFileVersion)
|
|
||||||
throw new Exception($"The manifest file version are not compatible : {patchManifest.FileVersion} != {YooAssetSettings.PatchManifestFileVersion}");
|
|
||||||
|
|
||||||
// BundleList
|
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
|
||||||
{
|
{
|
||||||
patchBundle.ParseBundle(patchManifest.PackageName, patchManifest.OutputNameStyle);
|
AssetInfo assetInfo = new AssetInfo(patchAsset, assetType);
|
||||||
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
|
return assetInfo;
|
||||||
}
|
|
||||||
|
|
||||||
// AssetList
|
|
||||||
foreach (var patchAsset in patchManifest.AssetList)
|
|
||||||
{
|
|
||||||
// 注意:我们不允许原始路径存在重名
|
|
||||||
string assetPath = patchAsset.AssetPath;
|
|
||||||
if (patchManifest.AssetDic.ContainsKey(assetPath))
|
|
||||||
throw new Exception($"AssetPath have existed : {assetPath}");
|
|
||||||
else
|
|
||||||
patchManifest.AssetDic.Add(assetPath, patchAsset);
|
|
||||||
}
|
|
||||||
|
|
||||||
return patchManifest;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 生成Bundle文件的正式名称
|
|
||||||
/// </summary>
|
|
||||||
public static string CreateBundleFileName(int nameStype, string bundleName, string fileHash)
|
|
||||||
{
|
|
||||||
if (nameStype == 1)
|
|
||||||
{
|
|
||||||
return fileHash;
|
|
||||||
}
|
|
||||||
else if (nameStype == 2)
|
|
||||||
{
|
|
||||||
string tempFileExtension = System.IO.Path.GetExtension(bundleName);
|
|
||||||
return $"{fileHash}{tempFileExtension}";
|
|
||||||
}
|
|
||||||
else if (nameStype == 3)
|
|
||||||
{
|
|
||||||
string tempFileExtension = System.IO.Path.GetExtension(bundleName);
|
|
||||||
string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, "");
|
|
||||||
return $"{tempBundleName}_{fileHash}";
|
|
||||||
}
|
|
||||||
else if (nameStype == 4)
|
|
||||||
{
|
|
||||||
string tempFileExtension = System.IO.Path.GetExtension(bundleName);
|
|
||||||
string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, "");
|
|
||||||
return $"{tempBundleName}_{fileHash}{tempFileExtension}";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
string error;
|
||||||
|
if (string.IsNullOrEmpty(location))
|
||||||
|
error = $"The location is null or empty !";
|
||||||
|
else
|
||||||
|
error = $"The location is invalid : {location}";
|
||||||
|
AssetInfo assetInfo = new AssetInfo(error);
|
||||||
|
return assetInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 调试方法
|
||||||
|
[Conditional("DEBUG")]
|
||||||
|
private void DebugCheckLocation(string location)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(location) == false)
|
||||||
|
{
|
||||||
|
// 检查路径末尾是否有空格
|
||||||
|
int index = location.LastIndexOf(" ");
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
if (location.Length == index + 1)
|
||||||
|
YooLogger.Warning($"Found blank character in location : \"{location}\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
|
||||||
|
YooLogger.Warning($"Found illegal character in location : \"{location}\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
188
Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs
Normal file
188
Assets/YooAsset/Runtime/PatchSystem/PatchManifestTools.cs
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal static class PatchManifestTools
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 序列化(JSON文件)
|
||||||
|
/// </summary>
|
||||||
|
public static void SerializeToJson(string savePath, PatchManifest manifest)
|
||||||
|
{
|
||||||
|
string json = JsonUtility.ToJson(manifest, true);
|
||||||
|
FileUtility.CreateFile(savePath, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序列化(二进制文件)
|
||||||
|
/// </summary>
|
||||||
|
public static void SerializeToBinary(string savePath, PatchManifest patchManifest)
|
||||||
|
{
|
||||||
|
using (FileStream fs = new FileStream(savePath, FileMode.Create))
|
||||||
|
{
|
||||||
|
// 创建缓存器
|
||||||
|
BufferWriter buffer = new BufferWriter(YooAssetSettings.PatchManifestFileMaxSize);
|
||||||
|
|
||||||
|
// 写入文件标记
|
||||||
|
buffer.WriteUInt32(YooAssetSettings.PatchManifestFileSign);
|
||||||
|
|
||||||
|
// 写入文件版本
|
||||||
|
buffer.WriteUTF8(patchManifest.FileVersion);
|
||||||
|
|
||||||
|
// 写入文件头信息
|
||||||
|
buffer.WriteBool(patchManifest.EnableAddressable);
|
||||||
|
buffer.WriteInt32(patchManifest.OutputNameStyle);
|
||||||
|
buffer.WriteUTF8(patchManifest.PackageName);
|
||||||
|
buffer.WriteUTF8(patchManifest.PackageVersion);
|
||||||
|
|
||||||
|
// 写入资源列表
|
||||||
|
buffer.WriteInt32(patchManifest.AssetList.Count);
|
||||||
|
for (int i = 0; i < patchManifest.AssetList.Count; i++)
|
||||||
|
{
|
||||||
|
var patchAsset = patchManifest.AssetList[i];
|
||||||
|
buffer.WriteUTF8(patchAsset.Address);
|
||||||
|
buffer.WriteUTF8(patchAsset.AssetPath);
|
||||||
|
buffer.WriteUTF8Array(patchAsset.AssetTags);
|
||||||
|
buffer.WriteInt32(patchAsset.BundleID);
|
||||||
|
buffer.WriteInt32Array(patchAsset.DependIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入资源包列表
|
||||||
|
buffer.WriteInt32(patchManifest.BundleList.Count);
|
||||||
|
for (int i = 0; i < patchManifest.BundleList.Count; i++)
|
||||||
|
{
|
||||||
|
var patchBundle = patchManifest.BundleList[i];
|
||||||
|
buffer.WriteUTF8(patchBundle.BundleName);
|
||||||
|
buffer.WriteUTF8(patchBundle.FileHash);
|
||||||
|
buffer.WriteUTF8(patchBundle.FileCRC);
|
||||||
|
buffer.WriteInt64(patchBundle.FileSize);
|
||||||
|
buffer.WriteBool(patchBundle.IsRawFile);
|
||||||
|
buffer.WriteByte(patchBundle.LoadMethod);
|
||||||
|
buffer.WriteUTF8Array(patchBundle.Tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入文件流
|
||||||
|
buffer.WriteToStream(fs);
|
||||||
|
fs.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 反序列化(二进制文件)
|
||||||
|
/// </summary>
|
||||||
|
public static PatchManifest DeserializeFromBinary(byte[] binaryData)
|
||||||
|
{
|
||||||
|
// 创建缓存器
|
||||||
|
BufferReader buffer = new BufferReader(binaryData);
|
||||||
|
|
||||||
|
// 读取文件标记
|
||||||
|
uint fileSign = buffer.ReadUInt32();
|
||||||
|
if (fileSign != YooAssetSettings.PatchManifestFileSign)
|
||||||
|
throw new Exception("Invalid manifest file !");
|
||||||
|
|
||||||
|
// 读取文件版本
|
||||||
|
string fileVersion = buffer.ReadUTF8();
|
||||||
|
if (fileVersion != YooAssetSettings.PatchManifestFileVersion)
|
||||||
|
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {YooAssetSettings.PatchManifestFileVersion}");
|
||||||
|
|
||||||
|
PatchManifest manifest = new PatchManifest();
|
||||||
|
{
|
||||||
|
// 读取文件头信息
|
||||||
|
manifest.FileVersion = fileVersion;
|
||||||
|
manifest.EnableAddressable = buffer.ReadBool();
|
||||||
|
manifest.OutputNameStyle = buffer.ReadInt32();
|
||||||
|
manifest.PackageName = buffer.ReadUTF8();
|
||||||
|
manifest.PackageVersion = buffer.ReadUTF8();
|
||||||
|
|
||||||
|
// 读取资源列表
|
||||||
|
int patchAssetCount = buffer.ReadInt32();
|
||||||
|
manifest.AssetList = new List<PatchAsset>(patchAssetCount);
|
||||||
|
for (int i = 0; i < patchAssetCount; i++)
|
||||||
|
{
|
||||||
|
var patchAsset = new PatchAsset();
|
||||||
|
patchAsset.Address = buffer.ReadUTF8();
|
||||||
|
patchAsset.AssetPath = buffer.ReadUTF8();
|
||||||
|
patchAsset.AssetTags = buffer.ReadUTF8Array();
|
||||||
|
patchAsset.BundleID = buffer.ReadInt32();
|
||||||
|
patchAsset.DependIDs = buffer.ReadInt32Array();
|
||||||
|
manifest.AssetList.Add(patchAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取资源包列表
|
||||||
|
int patchBundleCount = buffer.ReadInt32();
|
||||||
|
manifest.BundleList = new List<PatchBundle>(patchBundleCount);
|
||||||
|
for (int i = 0; i < patchBundleCount; i++)
|
||||||
|
{
|
||||||
|
var patchBundle = new PatchBundle();
|
||||||
|
patchBundle.BundleName = buffer.ReadUTF8();
|
||||||
|
patchBundle.FileHash = buffer.ReadUTF8();
|
||||||
|
patchBundle.FileCRC = buffer.ReadUTF8();
|
||||||
|
patchBundle.FileSize = buffer.ReadInt64();
|
||||||
|
patchBundle.IsRawFile = buffer.ReadBool();
|
||||||
|
patchBundle.LoadMethod = buffer.ReadByte();
|
||||||
|
patchBundle.Tags = buffer.ReadUTF8Array();
|
||||||
|
manifest.BundleList.Add(patchBundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BundleDic
|
||||||
|
manifest.BundleDic = new Dictionary<string, PatchBundle>(manifest.BundleList.Count);
|
||||||
|
foreach (var patchBundle in manifest.BundleList)
|
||||||
|
{
|
||||||
|
patchBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle);
|
||||||
|
manifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDic
|
||||||
|
manifest.AssetDic = new Dictionary<string, PatchAsset>(manifest.AssetList.Count);
|
||||||
|
foreach (var patchAsset in manifest.AssetList)
|
||||||
|
{
|
||||||
|
// 注意:我们不允许原始路径存在重名
|
||||||
|
string assetPath = patchAsset.AssetPath;
|
||||||
|
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||||
|
throw new Exception($"AssetPath have existed : {assetPath}");
|
||||||
|
else
|
||||||
|
manifest.AssetDic.Add(assetPath, patchAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成Bundle文件的正式名称
|
||||||
|
/// </summary>
|
||||||
|
public static string CreateBundleFileName(int nameStyle, string bundleName, string fileHash, bool isRawFile)
|
||||||
|
{
|
||||||
|
if (nameStyle == 1) //HashName
|
||||||
|
{
|
||||||
|
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||||
|
return StringUtility.Format("{0}.{1}", fileHash, fileExtension);
|
||||||
|
}
|
||||||
|
else if (nameStyle == 4) //BundleName_HashName
|
||||||
|
{
|
||||||
|
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
|
||||||
|
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
|
||||||
|
return StringUtility.Format("{0}_{1}.{2}", fileName, fileHash, fileExtension);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException($"Invalid name style : {nameStyle}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解压BundleInfo
|
||||||
|
/// </summary>
|
||||||
|
public static BundleInfo GetUnpackInfo(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
// 注意:我们把流加载路径指定为远端下载地址
|
||||||
|
string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath);
|
||||||
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
|
||||||
|
return bundleInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1014f7c3c05ebab4d8023b27f97a2119
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4,9 +4,9 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class EditorSimulateModeImpl : IBundleServices
|
internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices
|
||||||
{
|
{
|
||||||
private PatchManifest _simulatePatchManifest;
|
private PatchManifest _activeManifest;
|
||||||
private bool _locationToLower;
|
private bool _locationToLower;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -20,21 +20,71 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#region IPlayModeServices接口
|
||||||
/// 获取包裹的版本信息
|
public PatchManifest ActiveManifest
|
||||||
/// </summary>
|
|
||||||
public string GetPackageVersion()
|
|
||||||
{
|
{
|
||||||
if (_simulatePatchManifest == null)
|
set
|
||||||
return string.Empty;
|
{
|
||||||
return _simulatePatchManifest.PackageVersion;
|
_activeManifest = value;
|
||||||
|
_activeManifest.InitAssetPathMapping(_locationToLower);
|
||||||
|
}
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _activeManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetSimulatePatchManifest(PatchManifest patchManifest)
|
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||||
{
|
{
|
||||||
_simulatePatchManifest = patchManifest;
|
var operation = new EditorPlayModeUpdatePackageVersionOperation();
|
||||||
_simulatePatchManifest.InitAssetPathMapping(_locationToLower);
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
}
|
}
|
||||||
|
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new EditorPlayModeUpdatePackageManifestOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new EditorPlayModePreDownloadPackageOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||||
|
{
|
||||||
|
var operation = new EditorSimulateModeCheckPackageContentsOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
@@ -43,7 +93,7 @@ namespace YooAsset
|
|||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var patchBundle = _simulatePatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
@@ -51,32 +101,9 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
bool IBundleServices.IsServicesValid()
|
||||||
{
|
{
|
||||||
return _simulatePatchManifest.GetAssetsInfoByTags(tags);
|
return _activeManifest != null;
|
||||||
}
|
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
|
||||||
{
|
|
||||||
if (_simulatePatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
|
||||||
return patchAsset;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string IBundleServices.MappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return _simulatePatchManifest.MappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.TryMappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return _simulatePatchManifest.TryMappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.GetPackageName()
|
|
||||||
{
|
|
||||||
return _simulatePatchManifest.PackageName;
|
|
||||||
}
|
|
||||||
bool IBundleServices.IsIncludeBundleFile(string fileName)
|
|
||||||
{
|
|
||||||
return _simulatePatchManifest.IsIncludeBundleFile(fileName);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class HostPlayModeImpl : IBundleServices
|
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices
|
||||||
{
|
{
|
||||||
// 补丁清单
|
private PatchManifest _activeManifest;
|
||||||
internal PatchManifest LocalPatchManifest { private set; get; }
|
|
||||||
|
|
||||||
// 参数相关
|
// 参数相关
|
||||||
|
private string _packageName;
|
||||||
private bool _locationToLower;
|
private bool _locationToLower;
|
||||||
private string _defaultHostServer;
|
private string _defaultHostServer;
|
||||||
private string _fallbackHostServer;
|
private string _fallbackHostServer;
|
||||||
@@ -19,8 +18,9 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public InitializationOperation InitializeAsync(bool locationToLower, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices, string packageName)
|
public InitializationOperation InitializeAsync(string packageName, bool locationToLower, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices)
|
||||||
{
|
{
|
||||||
|
_packageName = packageName;
|
||||||
_locationToLower = locationToLower;
|
_locationToLower = locationToLower;
|
||||||
_defaultHostServer = defaultHostServer;
|
_defaultHostServer = defaultHostServer;
|
||||||
_fallbackHostServer = fallbackHostServer;
|
_fallbackHostServer = fallbackHostServer;
|
||||||
@@ -31,70 +31,106 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// 下载相关
|
||||||
/// 获取包裹的版本信息
|
private List<BundleInfo> ConvertToDownloadList(List<PatchBundle> downloadList)
|
||||||
/// </summary>
|
|
||||||
public string GetPackageVersion()
|
|
||||||
{
|
{
|
||||||
if (LocalPatchManifest == null)
|
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
|
||||||
return string.Empty;
|
foreach (var patchBundle in downloadList)
|
||||||
return LocalPatchManifest.PackageVersion;
|
{
|
||||||
|
var bundleInfo = ConvertToDownloadInfo(patchBundle);
|
||||||
|
result.Add(bundleInfo);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
string remoteMainURL = GetRemoteMainURL(patchBundle.FileName);
|
||||||
|
string remoteFallbackURL = GetRemoteFallbackURL(patchBundle.FileName);
|
||||||
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||||
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// 解压相关
|
||||||
/// 异步更新资源版本号
|
private List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
|
||||||
/// </summary>
|
|
||||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(string packageName, int timeout)
|
|
||||||
{
|
{
|
||||||
var operation = new HostPlayModeUpdatePackageVersionOperation(this, packageName, timeout);
|
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
|
||||||
|
foreach (var patchBundle in unpackList)
|
||||||
|
{
|
||||||
|
var bundleInfo = ConvertToUnpackInfo(patchBundle);
|
||||||
|
result.Add(bundleInfo);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
return PatchManifestTools.GetUnpackInfo(patchBundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IRemoteServices接口
|
||||||
|
public string GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_defaultHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
public string GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_fallbackHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IPlayModeServices接口
|
||||||
|
public PatchManifest ActiveManifest
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_activeManifest = value;
|
||||||
|
_activeManifest.InitAssetPathMapping(_locationToLower);
|
||||||
|
PersistentHelper.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
|
||||||
|
}
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _activeManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModeUpdatePackageManifestOperation(this, _packageName, packageVersion, timeout);
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModePreDownloadPackageOperation(this, _packageName, packageVersion, timeout);
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModeCheckPackageContentsOperation(this, _packageName, packageVersion);
|
||||||
OperationSystem.StartOperation(operation);
|
OperationSystem.StartOperation(operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
/// 异步更新补丁清单
|
|
||||||
/// </summary>
|
|
||||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageName, string packageVersion, int timeout)
|
|
||||||
{
|
{
|
||||||
var operation = new HostPlayModeUpdatePackageManifestOperation(this, packageName, packageVersion, timeout);
|
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
|
||||||
OperationSystem.StartOperation(operation);
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
public List<BundleInfo> GetDownloadListByAll(PatchManifest patchManifest)
|
||||||
/// <summary>
|
|
||||||
/// 检查本地包裹内容的完整性
|
|
||||||
/// </summary>
|
|
||||||
public CheckPackageContentsOperation CheckPackageContentsAsync(string packageName)
|
|
||||||
{
|
|
||||||
var operation = new HostPlayModeCheckPackageContentsOperation(this, packageName);
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步更新资源包裹
|
|
||||||
/// </summary>
|
|
||||||
public DownloadPackageOperation DownloadPackageAsync(string packageName, string packageVersion, int timeout)
|
|
||||||
{
|
|
||||||
var operation = new HostPlayModeDownloadPackageOperation(this, packageName, packageVersion, timeout);
|
|
||||||
OperationSystem.StartOperation(operation);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建下载器
|
|
||||||
/// </summary>
|
|
||||||
public PatchDownloaderOperation CreatePatchDownloaderByAll(int fileLoadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
|
|
||||||
List<BundleInfo> downloadList = GetDownloadListByAll();
|
|
||||||
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
private List<BundleInfo> GetDownloadListByAll()
|
|
||||||
{
|
{
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
// 忽略缓存文件
|
// 忽略缓存文件
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
@@ -110,20 +146,16 @@ namespace YooAsset
|
|||||||
return ConvertToDownloadList(downloadList);
|
return ConvertToDownloadList(downloadList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
/// 创建下载器
|
|
||||||
/// </summary>
|
|
||||||
public PatchDownloaderOperation CreatePatchDownloaderByTags(string[] tags, int fileLoadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
|
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
|
||||||
List<BundleInfo> downloadList = GetDownloadListByTags(tags);
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
private List<BundleInfo> GetDownloadListByTags(string[] tags)
|
public List<BundleInfo> GetDownloadListByTags(PatchManifest patchManifest, string[] tags)
|
||||||
{
|
{
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
// 忽略缓存文件
|
// 忽略缓存文件
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
@@ -151,17 +183,13 @@ namespace YooAsset
|
|||||||
return ConvertToDownloadList(downloadList);
|
return ConvertToDownloadList(downloadList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
/// 创建下载器
|
|
||||||
/// </summary>
|
|
||||||
public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Create patch downloader : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
|
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
|
||||||
List<BundleInfo> downloadList = GetDownloadListByPaths(assetInfos);
|
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
private List<BundleInfo> GetDownloadListByPaths(AssetInfo[] assetInfos)
|
public List<BundleInfo> GetDownloadListByPaths(PatchManifest patchManifest, AssetInfo[] assetInfos)
|
||||||
{
|
{
|
||||||
// 获取资源对象的资源包和所有依赖资源包
|
// 获取资源对象的资源包和所有依赖资源包
|
||||||
List<PatchBundle> checkList = new List<PatchBundle>();
|
List<PatchBundle> checkList = new List<PatchBundle>();
|
||||||
@@ -174,12 +202,12 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
PatchBundle mainBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
PatchBundle mainBundle = patchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
if (checkList.Contains(mainBundle) == false)
|
if (checkList.Contains(mainBundle) == false)
|
||||||
checkList.Add(mainBundle);
|
checkList.Add(mainBundle);
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
PatchBundle[] dependBundles = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
PatchBundle[] dependBundles = patchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
foreach (var dependBundle in dependBundles)
|
foreach (var dependBundle in dependBundles)
|
||||||
{
|
{
|
||||||
if (checkList.Contains(dependBundle) == false)
|
if (checkList.Contains(dependBundle) == false)
|
||||||
@@ -204,20 +232,40 @@ namespace YooAsset
|
|||||||
return ConvertToDownloadList(downloadList);
|
return ConvertToDownloadList(downloadList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
/// 创建解压器
|
|
||||||
/// </summary>
|
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Create patch unpacker : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
|
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByTags(tags);
|
var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
private List<BundleInfo> GetUnpackListByTags(string[] tags)
|
private List<BundleInfo> GetUnpackListByAll(PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
|
{
|
||||||
|
// 忽略缓存文件
|
||||||
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (IsBuildinPatchBundle(patchBundle))
|
||||||
|
{
|
||||||
|
downloadList.Add(patchBundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertToUnpackList(downloadList);
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
|
||||||
|
var operation = new PatchUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
private List<BundleInfo> GetUnpackListByTags(PatchManifest patchManifest, string[] tags)
|
||||||
|
{
|
||||||
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
// 忽略缓存文件
|
// 忽略缓存文件
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
if (CacheSystem.IsCached(patchBundle))
|
||||||
@@ -235,124 +283,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
return ConvertToUnpackList(downloadList);
|
return ConvertToUnpackList(downloadList);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
/// <summary>
|
|
||||||
/// 创建解压器
|
|
||||||
/// </summary>
|
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain, int timeout)
|
|
||||||
{
|
|
||||||
YooLogger.Log($"Create patch unpacker : {LocalPatchManifest.PackageName} {LocalPatchManifest.PackageVersion}");
|
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByAll();
|
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain, timeout);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
private List<BundleInfo> GetUnpackListByAll()
|
|
||||||
{
|
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 忽略缓存文件
|
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (IsBuildinPatchBundle(patchBundle))
|
|
||||||
{
|
|
||||||
downloadList.Add(patchBundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConvertToUnpackList(downloadList);
|
|
||||||
}
|
|
||||||
|
|
||||||
// WEB相关
|
|
||||||
public string GetPatchDownloadMainURL(string fileName)
|
|
||||||
{
|
|
||||||
return $"{_defaultHostServer}/{fileName}";
|
|
||||||
}
|
|
||||||
public string GetPatchDownloadFallbackURL(string fileName)
|
|
||||||
{
|
|
||||||
return $"{_fallbackHostServer}/{fileName}";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载相关
|
|
||||||
public List<BundleInfo> ConvertToDownloadList(List<PatchBundle> downloadList)
|
|
||||||
{
|
|
||||||
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
|
|
||||||
foreach (var patchBundle in downloadList)
|
|
||||||
{
|
|
||||||
var bundleInfo = ConvertToDownloadInfo(patchBundle);
|
|
||||||
result.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
|
|
||||||
{
|
|
||||||
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName);
|
|
||||||
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName);
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解压相关
|
|
||||||
public List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
|
|
||||||
{
|
|
||||||
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
|
|
||||||
foreach (var patchBundle in unpackList)
|
|
||||||
{
|
|
||||||
var bundleInfo = ConvertToUnpackInfo(patchBundle);
|
|
||||||
result.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
public static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
|
||||||
{
|
|
||||||
// 注意:我们把流加载路径指定为远端下载地址
|
|
||||||
string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath);
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
|
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal List<VerifyInfo> GetVerifyInfoList(bool weaklyUpdateMode)
|
|
||||||
{
|
|
||||||
List<VerifyInfo> result = new List<VerifyInfo>(LocalPatchManifest.BundleList.Count);
|
|
||||||
|
|
||||||
// 遍历所有文件然后验证并缓存合法文件
|
|
||||||
foreach (var patchBundle in LocalPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 忽略缓存文件
|
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
|
|
||||||
if (weaklyUpdateMode)
|
|
||||||
{
|
|
||||||
bool isBuildinFile = IsBuildinPatchBundle(patchBundle);
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string filePath = patchBundle.CachedFilePath;
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
{
|
|
||||||
bool isBuildinFile = IsBuildinPatchBundle(patchBundle);
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
internal void SetLocalPatchManifest(PatchManifest patchManifest)
|
|
||||||
{
|
|
||||||
LocalPatchManifest = patchManifest;
|
|
||||||
LocalPatchManifest.InitAssetPathMapping(_locationToLower);
|
|
||||||
}
|
|
||||||
internal bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
|
||||||
{
|
|
||||||
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
@@ -383,7 +314,7 @@ namespace YooAsset
|
|||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var patchBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
return CreateBundleInfo(patchBundle);
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
@@ -392,7 +323,7 @@ namespace YooAsset
|
|||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var patchBundle in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
@@ -401,32 +332,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
bool IBundleServices.IsServicesValid()
|
||||||
{
|
{
|
||||||
return LocalPatchManifest.GetAssetsInfoByTags(tags);
|
return _activeManifest != null;
|
||||||
}
|
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
|
||||||
{
|
|
||||||
if (LocalPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
|
||||||
return patchAsset;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string IBundleServices.MappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return LocalPatchManifest.MappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.TryMappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return LocalPatchManifest.TryMappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.GetPackageName()
|
|
||||||
{
|
|
||||||
return LocalPatchManifest.PackageName;
|
|
||||||
}
|
|
||||||
bool IBundleServices.IsIncludeBundleFile(string fileName)
|
|
||||||
{
|
|
||||||
return LocalPatchManifest.IsIncludeBundleFile(fileName);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class OfflinePlayModeImpl : IBundleServices
|
internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices
|
||||||
{
|
{
|
||||||
private PatchManifest _appPatchManifest;
|
private PatchManifest _activeManifest;
|
||||||
private bool _locationToLower;
|
private bool _locationToLower;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public InitializationOperation InitializeAsync(bool locationToLower, string packageName)
|
public InitializationOperation InitializeAsync(string packageName, bool locationToLower)
|
||||||
{
|
{
|
||||||
_locationToLower = locationToLower;
|
_locationToLower = locationToLower;
|
||||||
var operation = new OfflinePlayModeInitializationOperation(this, packageName);
|
var operation = new OfflinePlayModeInitializationOperation(this, packageName);
|
||||||
@@ -21,44 +20,72 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
#region IPlayModeServices接口
|
||||||
/// 获取包裹的版本信息
|
public PatchManifest ActiveManifest
|
||||||
/// </summary>
|
|
||||||
public string GetPackageVersion()
|
|
||||||
{
|
{
|
||||||
if (_appPatchManifest == null)
|
set
|
||||||
return string.Empty;
|
|
||||||
return _appPatchManifest.PackageVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal List<VerifyInfo> GetVerifyInfoList()
|
|
||||||
{
|
|
||||||
List<VerifyInfo> result = new List<VerifyInfo>(_appPatchManifest.BundleList.Count);
|
|
||||||
|
|
||||||
// 遍历所有文件然后验证并缓存合法文件
|
|
||||||
foreach (var patchBundle in _appPatchManifest.BundleList)
|
|
||||||
{
|
{
|
||||||
// 忽略缓存文件
|
_activeManifest = value;
|
||||||
if (CacheSystem.IsCached(patchBundle))
|
_activeManifest.InitAssetPathMapping(_locationToLower);
|
||||||
continue;
|
}
|
||||||
|
get
|
||||||
string filePath = patchBundle.CachedFilePath;
|
{
|
||||||
if (File.Exists(filePath))
|
return _activeManifest;
|
||||||
{
|
|
||||||
bool isBuildinFile = true;
|
|
||||||
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
|
|
||||||
result.Add(verifyInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
public bool IsBuildinPatchBundle(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
_appPatchManifest = patchManifest;
|
return true;
|
||||||
_appPatchManifest.InitAssetPathMapping(_locationToLower);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModePreDownloadPackageOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModeCheckPackageContentsOperation();
|
||||||
|
OperationSystem.StartOperation(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchDownloaderOperation IPlayModeServices.CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
PatchUnpackerOperation IPlayModeServices.CreatePatchUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
{
|
||||||
|
return PatchUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
@@ -84,7 +111,7 @@ namespace YooAsset
|
|||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var patchBundle = _appPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
var patchBundle = _activeManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
return CreateBundleInfo(patchBundle);
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
@@ -93,7 +120,7 @@ namespace YooAsset
|
|||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var patchBundle in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
@@ -102,32 +129,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
|
bool IBundleServices.IsServicesValid()
|
||||||
{
|
{
|
||||||
return _appPatchManifest.GetAssetsInfoByTags(tags);
|
return _activeManifest != null;
|
||||||
}
|
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
|
||||||
{
|
|
||||||
if (_appPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
|
||||||
return patchAsset;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string IBundleServices.MappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return _appPatchManifest.MappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.TryMappingToAssetPath(string location)
|
|
||||||
{
|
|
||||||
return _appPatchManifest.TryMappingToAssetPath(location);
|
|
||||||
}
|
|
||||||
string IBundleServices.GetPackageName()
|
|
||||||
{
|
|
||||||
return _appPatchManifest.PackageName;
|
|
||||||
}
|
|
||||||
bool IBundleServices.IsIncludeBundleFile(string fileName)
|
|
||||||
{
|
|
||||||
return _appPatchManifest.IsIncludeBundleFile(fileName);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal interface IBundleServices
|
internal interface IBundleServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源包信息
|
/// 获取资源包信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -14,33 +14,8 @@ namespace YooAsset
|
|||||||
BundleInfo[] GetAllDependBundleInfos(AssetInfo assetPath);
|
BundleInfo[] GetAllDependBundleInfos(AssetInfo assetPath);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源信息列表
|
/// 服务接口是否有效
|
||||||
/// </summary>
|
/// </summary>
|
||||||
AssetInfo[] GetAssetInfos(string[] tags);
|
bool IsServicesValid();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 尝试获取补丁资源
|
|
||||||
/// </summary>
|
|
||||||
PatchAsset TryGetPatchAsset(string assetPath);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 映射为资源路径
|
|
||||||
/// </summary>
|
|
||||||
string MappingToAssetPath(string location);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 尝试映射为资源路径
|
|
||||||
/// </summary>
|
|
||||||
string TryMappingToAssetPath(string location);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所属的包裹名
|
|
||||||
/// </summary>
|
|
||||||
string GetPackageName();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否包含资源文件
|
|
||||||
/// </summary>
|
|
||||||
bool IsIncludeBundleFile(string fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user