update
This commit is contained in:
parent
f2c6c14db4
commit
9c0d5f99d6
61
CHANGELOG.md
61
CHANGELOG.md
@ -2,6 +2,67 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.3.17] - 2025-10-30
|
||||
|
||||
**非常重要**:修复了#627优化导致的资源清单CRC值为空的问题。
|
||||
|
||||
该问题会导致下载的损坏文件验证通过。
|
||||
|
||||
影响范围:v2.3.15版本,v2.3.16版本。
|
||||
|
||||
**非常重要**:(#661) 修复了Package销毁过程中,遇到正在加载的AssetBundle会导致无法卸载的问题。
|
||||
|
||||
该问题是偶现,引擎会提示AssetBundle已经加载,无法加载新的文件,导致资源对象加载失败!
|
||||
|
||||
影响范围:所有版本!
|
||||
|
||||
### Improvements
|
||||
|
||||
- 重构并统一了资源清单的反序列化逻辑。
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#645) 修复了着色器变种收集工具,在极端情况下变种收集不完整的问题。
|
||||
- (#646) 修复了EditorSimulateMode模式下开启模拟下载tag不生效的问题。
|
||||
- (#667) 修复了所有编辑器窗口针对中文IME的输入问题。
|
||||
- (#670) 修复了Catalog文件生成过程中白名单未考虑自定义清单前缀名。
|
||||
|
||||
### Improvements
|
||||
|
||||
- (#650) 解决互相依赖的资源包无法卸载的问题。需要开启宏定义:YOOASSET_EXPERIMENTAL
|
||||
- (#655) 优化了初始化的时候,缓存文件搜索效率。安卓平台性能提升1倍,IOS平台性能提升3倍。
|
||||
|
||||
### Added
|
||||
|
||||
- (#643) 新增构建参数,可以节省资源清单运行时内存
|
||||
|
||||
```csharp
|
||||
class ScriptableBuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
}
|
||||
```
|
||||
|
||||
- (#648) 新增初始化参数,可以自动释放引用计数为零的资源包
|
||||
|
||||
```csharp
|
||||
class InitializeParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 当资源引用计数为零的时候自动释放资源包
|
||||
/// </summary>
|
||||
public bool AutoUnloadBundleWhenUnused = false;
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 程序集宏定义代码转移到扩展工程。参考MacroSupport文件夹。
|
||||
|
||||
## [2.3.16] - 2025-09-17
|
||||
|
||||
### Improvements
|
||||
|
||||
@ -32,17 +32,10 @@ namespace YooAsset.Editor
|
||||
|
||||
// 开始扫描工作
|
||||
ScanReport report = scanner.RunScanner();
|
||||
|
||||
// 检测报告合法性
|
||||
report.CheckError();
|
||||
|
||||
// 保存扫描结果
|
||||
string saveDirectory = scanner.SaveDirectory;
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{scanner.ScannerName}_{scanner.ScannerDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, report);
|
||||
return new ScannerResult(filePath, report);
|
||||
// 返回扫描结果
|
||||
return new ScannerResult(report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -3,11 +3,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class ScannerResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成的报告文件路径
|
||||
/// </summary>
|
||||
public string ReprotFilePath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 报告对象
|
||||
/// </summary>
|
||||
@ -43,11 +38,9 @@ namespace YooAsset.Editor
|
||||
ErrorInfo = error;
|
||||
ErrorStack = stack;
|
||||
}
|
||||
public ScannerResult(string filePath, ScanReport report)
|
||||
public ScannerResult(ScanReport report)
|
||||
{
|
||||
ReprotFilePath = filePath;
|
||||
Report = report;
|
||||
ErrorInfo = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -61,5 +54,19 @@ namespace YooAsset.Editor
|
||||
reproterWindow.ImportSingleReprotFile(Report);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存报告文件
|
||||
/// </summary>
|
||||
public void SaveReportFile(string saveDirectory)
|
||||
{
|
||||
if (Report == null)
|
||||
throw new System.Exception("Scan report is invalid !");
|
||||
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{Report.ReportName}_{Report.ReportDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, Report);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,27 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetPaths()
|
||||
{
|
||||
return AllPackAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.AssetInfo.AssetPath);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的资源可寻址列表
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetAddress()
|
||||
{
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.Address);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -153,13 +173,15 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建AssetBundleBuild类
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild(bool replaceAssetPathWithAddress)
|
||||
{
|
||||
// 注意:我们不再支持AssetBundle的变种机制
|
||||
AssetBundleBuild build = new AssetBundleBuild();
|
||||
build.assetBundleName = BundleName;
|
||||
build.assetBundleVariant = string.Empty;
|
||||
build.assetNames = GetAllPackAssetPaths();
|
||||
if (replaceAssetPathWithAddress)
|
||||
build.addressableNames = GetAllPackAssetAddress();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
@ -96,12 +96,12 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取构建管线里需要的数据
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds(bool replaceAssetPathWithAddres)
|
||||
{
|
||||
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
|
||||
foreach (var bundleInfo in _bundleInfoDic.Values)
|
||||
{
|
||||
builds.Add(bundleInfo.CreatePipelineBuild());
|
||||
builds.Add(bundleInfo.CreatePipelineBuild(replaceAssetPathWithAddres));
|
||||
}
|
||||
return builds.ToArray();
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建补丁清单文件到输出目录
|
||||
/// </summary>
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, BuildContext context)
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, bool replaceAssetPathWithAddress, BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
@ -36,6 +36,7 @@ namespace YooAsset.Editor
|
||||
manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
manifest.ReplaceAssetPathWithAddress = replaceAssetPathWithAddress;
|
||||
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
|
||||
manifest.BuildBundleType = buildParameters.BuildBundleType;
|
||||
manifest.BuildPipeline = buildParameters.BuildPipeline;
|
||||
@ -58,7 +59,13 @@ namespace YooAsset.Editor
|
||||
|
||||
// 4. 处理内置资源包
|
||||
if (processBundleDepends)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
manifest.Initialize();
|
||||
|
||||
ProcessBuiltinBundleDependency(context, manifest);
|
||||
}
|
||||
|
||||
|
||||
// 创建资源清单文本文件
|
||||
{
|
||||
@ -302,9 +309,6 @@ namespace YooAsset.Editor
|
||||
#region YOOASSET_LEGACY_DEPENDENCY
|
||||
private void ProcessBuiltinBundleDependency(BuildContext context, PackageManifest manifest)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
ManifestTools.InitManifest(manifest);
|
||||
|
||||
// 注意:如果是可编程构建管线,需要补充内置资源包
|
||||
// 注意:该步骤依赖前面的操作!
|
||||
var buildResultContext = context.TryGetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
|
||||
@ -54,6 +54,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
}
|
||||
else if (buildParameters is ScriptableBuildParameters)
|
||||
{
|
||||
@ -61,6 +62,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
buildReport.Summary.WriteLinkXML = scriptableBuildParameters.WriteLinkXML;
|
||||
buildReport.Summary.CacheServerHost = scriptableBuildParameters.CacheServerHost;
|
||||
buildReport.Summary.CacheServerPort = scriptableBuildParameters.CacheServerPort;
|
||||
|
||||
@ -23,7 +23,8 @@ namespace YooAsset.Editor
|
||||
// 开始构建
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions();
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(builtinBuildParameters.ReplaceAssetPathWithAddress);
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, bundleBuilds, buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
if (unityManifest == null)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, "UnityEngine build failed !");
|
||||
|
||||
@ -11,7 +11,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
|
||||
bool replaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@ -27,6 +27,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置构建管线的构建选项
|
||||
|
||||
@ -7,7 +7,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, false, context);
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@ -9,7 +9,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, true, context);
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@ -24,7 +24,8 @@ namespace YooAsset.Editor
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 构建内容
|
||||
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(scriptableBuildParameters.ReplaceAssetPathWithAddress);
|
||||
var buildContent = new BundleBuildContent(bundleBuilds);
|
||||
|
||||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
|
||||
@ -13,7 +13,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
bool replaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@ -29,6 +29,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自动建立资源对象对图集的依赖关系
|
||||
/// </summary>
|
||||
|
||||
@ -236,6 +236,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 包裹名称
|
||||
_packageNameTxt = root.Q<TextField>("PackageName");
|
||||
_packageNameTxt.isDelayed = true;
|
||||
_packageNameTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@ -249,6 +250,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 包裹备注
|
||||
_packageDescTxt = root.Q<TextField>("PackageDesc");
|
||||
_packageDescTxt.isDelayed = true;
|
||||
_packageDescTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@ -286,6 +288,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组名称
|
||||
_groupNameTxt = root.Q<TextField>("GroupName");
|
||||
_groupNameTxt.isDelayed = true;
|
||||
_groupNameTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@ -300,6 +303,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组备注
|
||||
_groupDescTxt = root.Q<TextField>("GroupDesc");
|
||||
_groupDescTxt.isDelayed = true;
|
||||
_groupDescTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@ -314,6 +318,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组的资源标签
|
||||
_groupTagsTxt = root.Q<TextField>("GroupTags");
|
||||
_groupTagsTxt.isDelayed = true;
|
||||
_groupTagsTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@ -817,6 +822,7 @@ namespace YooAsset.Editor
|
||||
var textField = new TextField();
|
||||
textField.name = "TextField0";
|
||||
textField.label = "User Data";
|
||||
textField.isDelayed = true;
|
||||
textField.style.width = 200;
|
||||
elementBottom.Add(textField);
|
||||
var label = textField.Q<Label>();
|
||||
@ -826,6 +832,7 @@ namespace YooAsset.Editor
|
||||
var textField = new TextField();
|
||||
textField.name = "TextField1";
|
||||
textField.label = "Asset Tags";
|
||||
textField.isDelayed = true;
|
||||
textField.style.width = 100;
|
||||
textField.style.marginLeft = 20;
|
||||
textField.style.flexGrow = 1;
|
||||
|
||||
@ -81,6 +81,7 @@ namespace YooAsset.Editor
|
||||
public ECompressOption CompressOption;
|
||||
public bool DisableWriteTypeTree;
|
||||
public bool IgnoreTypeTreeChanges;
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
public bool WriteLinkXML = true;
|
||||
public string CacheServerHost;
|
||||
public int CacheServerPort;
|
||||
|
||||
@ -74,6 +74,7 @@ namespace YooAsset.Editor
|
||||
BindListViewItem("CompressOption", $"{buildReport.Summary.CompressOption}");
|
||||
BindListViewItem("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}");
|
||||
BindListViewItem("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}");
|
||||
BindListViewItem("ReplaceAssetPathWithAddress", $"{buildReport.Summary.ReplaceAssetPathWithAddress}");
|
||||
BindListViewItem(string.Empty, string.Empty);
|
||||
|
||||
BindListViewHeader("Build Results");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bbcb90032364234abe49c81b95714e1
|
||||
guid: bf6b81dffd4995e42a500ffc0025ec18
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if YOO_ASSET_EXPERIMENT
|
||||
#if YOO_MACRO_SUPPORT
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class MacroDefine
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using UnityEditor;
|
||||
|
||||
#if YOO_ASSET_EXPERIMENT
|
||||
#if YOO_MACRO_SUPPORT
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
@ -6,7 +6,7 @@ using System.Xml;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#if YOO_ASSET_EXPERIMENT
|
||||
#if YOO_MACRO_SUPPORT
|
||||
namespace YooAsset.Editor.Experiment
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
@ -106,6 +106,9 @@ public static class ShaderVariantCollector
|
||||
|
||||
if (_steps == ESteps.CollectSleeping)
|
||||
{
|
||||
if (ShaderUtil.anythingCompiling)
|
||||
return;
|
||||
|
||||
if (_elapsedTime.ElapsedMilliseconds > SleepMilliseconds)
|
||||
{
|
||||
DestroyAllSpheres();
|
||||
|
||||
@ -63,14 +63,19 @@ namespace YooAsset
|
||||
{
|
||||
"link.xml",
|
||||
"buildlogtep.json",
|
||||
$"{packageName}.version",
|
||||
$"{packageName}_{packageVersion}.bytes",
|
||||
$"{packageName}_{packageVersion}.hash",
|
||||
$"{packageName}_{packageVersion}.json",
|
||||
$"{packageName}_{packageVersion}.report",
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName,
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName
|
||||
};
|
||||
string packageVersionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
string packageHashFileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
string manifestBinaryFIleName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
string manifestJsonFIleName = YooAssetSettingsData.GetManifestJsonFileName(packageName, packageVersion);
|
||||
string reportFileName = YooAssetSettingsData.GetBuildReportFileName(packageName, packageVersion);
|
||||
whiteFileList.Add(packageVersionFileName);
|
||||
whiteFileList.Add(packageHashFileName);
|
||||
whiteFileList.Add(manifestBinaryFIleName);
|
||||
whiteFileList.Add(manifestJsonFIleName);
|
||||
whiteFileList.Add(reportFileName);
|
||||
|
||||
// 记录所有内置资源文件
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(packageDirectory);
|
||||
|
||||
@ -90,7 +90,7 @@ namespace YooAsset
|
||||
public string CopyBuildinPackageManifestDestRoot { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@ -100,7 +100,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
@ -57,7 +57,7 @@ namespace YooAsset
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// 自定义参数:远程服务接口的实例类
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; }
|
||||
|
||||
@ -112,7 +112,7 @@ namespace YooAsset
|
||||
public List<long> ResumeDownloadResponseCodes { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@ -122,7 +122,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
@ -11,6 +11,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
AbortDownload,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
@ -63,6 +64,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
// 中断下载
|
||||
if (AbortDownloadFile)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.AbortOperation();
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
@ -94,6 +106,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
_downloadFileOp.UpdateOperation();
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
@ -251,6 +280,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
AbortDownload,
|
||||
LoadCacheRawBundle,
|
||||
Done,
|
||||
}
|
||||
@ -310,6 +340,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
// 中断下载
|
||||
if (AbortDownloadFile)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.AbortOperation();
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
@ -341,6 +382,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
_downloadFileOp.UpdateOperation();
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
|
||||
|
||||
@ -16,7 +16,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private IEnumerator<DirectoryInfo> _filesEnumerator = null;
|
||||
private IEnumerator<string> _filesEnumerator = null;
|
||||
private float _verifyStartTime;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@ -42,11 +42,11 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(_fileSystem.GetCacheBundleFilesRoot());
|
||||
if (rootDirectory.Exists)
|
||||
string rootDirectory = _fileSystem.GetCacheBundleFilesRoot();
|
||||
if (Directory.Exists(rootDirectory))
|
||||
{
|
||||
var directorieInfos = rootDirectory.EnumerateDirectories();
|
||||
_filesEnumerator = directorieInfos.GetEnumerator();
|
||||
var directories = Directory.EnumerateDirectories(rootDirectory);
|
||||
_filesEnumerator = directories.GetEnumerator();
|
||||
}
|
||||
_steps = ESteps.SearchFiles;
|
||||
}
|
||||
@ -76,15 +76,15 @@ namespace YooAsset
|
||||
break;
|
||||
|
||||
var rootFoder = _filesEnumerator.Current;
|
||||
var childDirectories = rootFoder.GetDirectories();
|
||||
var childDirectories = Directory.EnumerateDirectories(rootFoder);
|
||||
foreach (var chidDirectory in childDirectories)
|
||||
{
|
||||
string bundleGUID = chidDirectory.Name;
|
||||
string bundleGUID = Path.GetFileName(chidDirectory);
|
||||
if (_fileSystem.IsRecordBundleFile(bundleGUID))
|
||||
continue;
|
||||
|
||||
// 创建验证元素类
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string fileRootPath = chidDirectory;
|
||||
string dataFilePath = $"{fileRootPath}/{DefaultCacheFileSystemDefine.BundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{DefaultCacheFileSystemDefine.BundleInfoFileName}";
|
||||
|
||||
@ -108,18 +108,16 @@ namespace YooAsset
|
||||
|
||||
return isFindItem;
|
||||
}
|
||||
private string FindDataFileExtension(DirectoryInfo directoryInfo)
|
||||
private string FindDataFileExtension(string directory)
|
||||
{
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = directoryInfo.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
string searchPattern = DefaultCacheFileSystemDefine.BundleDataFileName + "*";
|
||||
var dataFiles = Directory.EnumerateFiles(directory, searchPattern);
|
||||
foreach (var filePath in dataFiles)
|
||||
{
|
||||
if (fileInfo.Name.StartsWith(DefaultCacheFileSystemDefine.BundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
dataFileExtension = Path.GetExtension(filePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dataFileExtension;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
AbortDownload,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
@ -48,6 +49,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
// 中断下载
|
||||
if (AbortDownloadFile)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.AbortOperation();
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
@ -79,6 +91,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
_downloadFileOp.UpdateOperation();
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
|
||||
@ -44,12 +44,12 @@ namespace YooAsset
|
||||
public bool DisableUnityWebCache { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:跨域下载服务接口
|
||||
/// 自定义参数:远程服务接口的实例类(支持跨域下载)
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ namespace YooAsset
|
||||
public bool DisableUnityWebCache { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
|
||||
@ -17,6 +17,11 @@ namespace YooAsset
|
||||
/// 下载大小
|
||||
/// </summary>
|
||||
public long DownloadedBytes { protected set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 终止下载文件
|
||||
/// </summary>
|
||||
public bool AbortDownloadFile = false;
|
||||
}
|
||||
|
||||
internal sealed class FSLoadBundleCompleteOperation : FSLoadBundleOperation
|
||||
|
||||
@ -43,6 +43,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public int BundleLoadingMaxConcurrency = int.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// 当资源引用计数为零的时候自动释放资源包
|
||||
/// </summary>
|
||||
public bool AutoUnloadBundleWhenUnused = false;
|
||||
|
||||
/// <summary>
|
||||
/// WebGL平台强制同步加载资源对象
|
||||
/// </summary>
|
||||
|
||||
@ -36,6 +36,9 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_watch == null)
|
||||
return false;
|
||||
|
||||
// NOTE : 单次调用开销约1微秒
|
||||
return _watch.ElapsedMilliseconds - _frameTime >= MaxTimeSlice;
|
||||
}
|
||||
|
||||
@ -23,6 +23,11 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
|
||||
// 主动卸载零引用的资源包
|
||||
if (Provider.RefCount == 0)
|
||||
Provider.TryUnloadBundle();
|
||||
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
|
||||
@ -173,6 +173,13 @@ namespace YooAsset
|
||||
|
||||
if (Result != null)
|
||||
Result.UnloadBundleFile();
|
||||
|
||||
if (IsDone == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Bundle loader destroyed !";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -180,11 +187,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool CanDestroyLoader()
|
||||
{
|
||||
// 注意:正在加载中的任务不可以销毁
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
return false;
|
||||
|
||||
if (RefCount > 0)
|
||||
if (CanReleasableLoader() == false)
|
||||
return false;
|
||||
|
||||
// YOOASSET_LEGACY_DEPENDENCY
|
||||
@ -194,14 +197,34 @@ namespace YooAsset
|
||||
{
|
||||
foreach (var bundleID in LoadBundleInfo.Bundle.ReferenceBundleIDs)
|
||||
{
|
||||
#if YOOASSET_EXPERIMENTAL
|
||||
if (_resManager.CheckBundleReleasable(bundleID) == false)
|
||||
return false;
|
||||
#else
|
||||
if (_resManager.CheckBundleDestroyed(bundleID) == false)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以释放
|
||||
/// </summary>
|
||||
public bool CanReleasableLoader()
|
||||
{
|
||||
// 注意:正在加载中的任务不可以销毁
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
return false;
|
||||
|
||||
if (RefCount > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加附属的资源提供者
|
||||
/// </summary>
|
||||
@ -240,5 +263,28 @@ namespace YooAsset
|
||||
_removeList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试终止加载器
|
||||
/// </summary>
|
||||
public void TryAbortLoader()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
if (_steps == ESteps.CheckConcurrency)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort bundle loader !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
// 注意:终止下载器
|
||||
if (_loadBundleOp != null)
|
||||
_loadBundleOp.AbortDownloadFile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckOptions,
|
||||
ReleaseAll,
|
||||
AbortDownload,
|
||||
TryAbortLoader,
|
||||
CheckLoading,
|
||||
DestroyAll,
|
||||
Done,
|
||||
@ -78,15 +78,16 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.AbortDownload;
|
||||
_steps = ESteps.TryAbortLoader;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
if (_steps == ESteps.TryAbortLoader)
|
||||
{
|
||||
// 注意:终止所有下载任务
|
||||
// 尝试终止所有加载任务
|
||||
// 注意:正在加载AssetBundle的任务无法终止
|
||||
foreach (var loader in _resManager.LoaderDic.Values)
|
||||
{
|
||||
loader.AbortOperation();
|
||||
loader.TryAbortLoader();
|
||||
}
|
||||
_steps = ESteps.CheckLoading;
|
||||
}
|
||||
|
||||
@ -308,6 +308,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试卸载资源包
|
||||
/// </summary>
|
||||
public void TryUnloadBundle()
|
||||
{
|
||||
if (_resManager.AutoUnloadBundleWhenUnused)
|
||||
{
|
||||
_resManager.TryUnloadUnusedAsset(MainAssetInfo, 10);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结束流程
|
||||
/// </summary>
|
||||
|
||||
@ -17,6 +17,7 @@ namespace YooAsset
|
||||
private int _bundleLoadingMaxConcurrency;
|
||||
|
||||
// 开发者配置选项
|
||||
public bool AutoUnloadBundleWhenUnused { private set; get; }
|
||||
public bool WebGLForceSyncLoadAsset { private set; get; }
|
||||
public bool UseWeakReferenceHandle { private set; get; }
|
||||
|
||||
@ -47,6 +48,7 @@ namespace YooAsset
|
||||
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
|
||||
{
|
||||
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
|
||||
AutoUnloadBundleWhenUnused = parameters.AutoUnloadBundleWhenUnused;
|
||||
WebGLForceSyncLoadAsset = parameters.WebGLForceSyncLoadAsset;
|
||||
UseWeakReferenceHandle = parameters.UseWeakReferenceHandle;
|
||||
_bundleQuery = bundleServices;
|
||||
@ -327,6 +329,14 @@ namespace YooAsset
|
||||
return true;
|
||||
return bundleFileLoader.IsDestroyed;
|
||||
}
|
||||
internal bool CheckBundleReleasable(int bundleID)
|
||||
{
|
||||
string bundleName = _bundleQuery.GetMainBundleName(bundleID);
|
||||
var bundleFileLoader = TryGetBundleFileLoader(bundleName);
|
||||
if (bundleFileLoader == null)
|
||||
return true;
|
||||
return bundleFileLoader.CanReleasableLoader();
|
||||
}
|
||||
internal bool HasAnyLoader()
|
||||
{
|
||||
return LoaderDic.Count > 0;
|
||||
|
||||
@ -16,6 +16,13 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 文件格式版本
|
||||
/// </summary>
|
||||
public const string FileVersion = "2025.8.28";
|
||||
public const string FileVersion = "2025.9.30";
|
||||
public const string VERSION_2025_8_28 = "2025.8.28";
|
||||
public const string VERSION_2025_9_30 = "2025.9.30";
|
||||
|
||||
/// <summary>
|
||||
/// 版本兼容
|
||||
/// </summary>
|
||||
public const bool BackwardCompatible = true;
|
||||
}
|
||||
}
|
||||
@ -62,6 +62,7 @@ namespace YooAsset
|
||||
buffer.WriteBool(manifest.SupportExtensionless);
|
||||
buffer.WriteBool(manifest.LocationToLower);
|
||||
buffer.WriteBool(manifest.IncludeAssetGUID);
|
||||
buffer.WriteBool(manifest.ReplaceAssetPathWithAddress);
|
||||
buffer.WriteInt32(manifest.OutputNameStyle);
|
||||
buffer.WriteInt32(manifest.BuildBundleType);
|
||||
buffer.WriteUTF8(manifest.BuildPipeline);
|
||||
@ -119,7 +120,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static PackageManifest DeserializeFromJson(string jsonContent)
|
||||
{
|
||||
return JsonUtility.FromJson<PackageManifest>(jsonContent);
|
||||
var manifest = JsonUtility.FromJson<PackageManifest>(jsonContent);
|
||||
|
||||
// 初始化资源包
|
||||
for (int i = 0; i < manifest.BundleList.Count; i++)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[i];
|
||||
packageBundle.InitBundle(manifest);
|
||||
}
|
||||
|
||||
// 初始化资源清单
|
||||
manifest.Initialize();
|
||||
return manifest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -127,217 +139,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static PackageManifest DeserializeFromBinary(byte[] binaryData, IManifestRestoreServices services)
|
||||
{
|
||||
// 创建缓存器
|
||||
BufferReader buffer;
|
||||
if (services != null)
|
||||
{
|
||||
var resultBytes = services.RestoreManifest(binaryData);
|
||||
buffer = new BufferReader(resultBytes);
|
||||
DeserializeManifestOperation operation = new DeserializeManifestOperation(services, binaryData);
|
||||
operation.StartOperation();
|
||||
operation.WaitForAsyncComplete();
|
||||
return operation.Manifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = new BufferReader(binaryData);
|
||||
}
|
||||
|
||||
// 读取文件标记
|
||||
uint fileSign = buffer.ReadUInt32();
|
||||
if (fileSign != ManifestDefine.FileSign)
|
||||
throw new Exception("Invalid manifest file !");
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = buffer.ReadUTF8();
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
throw new Exception($"The manifest file version are not compatible : {fileVersion} != {ManifestDefine.FileVersion}");
|
||||
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
{
|
||||
// 读取文件头信息
|
||||
manifest.FileVersion = fileVersion;
|
||||
manifest.EnableAddressable = buffer.ReadBool();
|
||||
manifest.SupportExtensionless = buffer.ReadBool();
|
||||
manifest.LocationToLower = buffer.ReadBool();
|
||||
manifest.IncludeAssetGUID = buffer.ReadBool();
|
||||
manifest.OutputNameStyle = buffer.ReadInt32();
|
||||
manifest.BuildBundleType = buffer.ReadInt32();
|
||||
manifest.BuildPipeline = buffer.ReadUTF8();
|
||||
manifest.PackageName = buffer.ReadUTF8();
|
||||
manifest.PackageVersion = buffer.ReadUTF8();
|
||||
manifest.PackageNote = buffer.ReadUTF8();
|
||||
|
||||
// 检测配置
|
||||
if (manifest.EnableAddressable && manifest.LocationToLower)
|
||||
throw new Exception("Addressable not support location to lower !");
|
||||
|
||||
// 读取资源列表
|
||||
int packageAssetCount = buffer.ReadInt32();
|
||||
CreateAssetCollection(manifest, packageAssetCount);
|
||||
for (int i = 0; i < packageAssetCount; i++)
|
||||
{
|
||||
var packageAsset = new PackageAsset();
|
||||
packageAsset.Address = buffer.ReadUTF8();
|
||||
packageAsset.AssetPath = buffer.ReadUTF8();
|
||||
packageAsset.AssetGUID = buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = buffer.ReadInt32();
|
||||
packageAsset.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillAssetCollection(manifest, packageAsset);
|
||||
}
|
||||
|
||||
// 读取资源包列表
|
||||
int packageBundleCount = buffer.ReadInt32();
|
||||
CreateBundleCollection(manifest, packageBundleCount);
|
||||
for (int i = 0; i < packageBundleCount; i++)
|
||||
{
|
||||
var packageBundle = new PackageBundle();
|
||||
packageBundle.BundleName = buffer.ReadUTF8();
|
||||
packageBundle.UnityCRC = buffer.ReadUInt32();
|
||||
packageBundle.FileHash = buffer.ReadUTF8();
|
||||
packageBundle.FileCRC = buffer.ReadUInt32();
|
||||
packageBundle.FileSize = buffer.ReadInt64();
|
||||
packageBundle.Encrypted = buffer.ReadBool();
|
||||
packageBundle.Tags = buffer.ReadUTF8Array();
|
||||
packageBundle.DependBundleIDs = buffer.ReadInt32Array();
|
||||
FillBundleCollection(manifest, packageBundle);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化资源清单
|
||||
InitManifest(manifest);
|
||||
return manifest;
|
||||
}
|
||||
|
||||
|
||||
#region 解析资源清单辅助方法
|
||||
public static void InitManifest(PackageManifest manifest)
|
||||
{
|
||||
// 填充资源包内包含的主资源列表
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < manifest.BundleList.Count)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[bundleID];
|
||||
packageBundle.IncludeMainAssets.Add(packageAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 填充资源包引用关系
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
var sourceBundle = manifest.BundleList[index];
|
||||
foreach (int dependIndex in sourceBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = manifest.BundleList[dependIndex];
|
||||
dependBundle.AddReferenceBundleID(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateAssetCollection(PackageManifest manifest, int assetCount)
|
||||
{
|
||||
manifest.AssetList = new List<PackageAsset>(assetCount);
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (manifest.LocationToLower)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
}
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
else
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
}
|
||||
public static void FillAssetCollection(PackageManifest manifest, PackageAsset packageAsset)
|
||||
{
|
||||
// 添加到列表集合
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (manifest.SupportExtensionless)
|
||||
{
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加可寻址地址
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateBundleCollection(PackageManifest manifest, int bundleCount)
|
||||
{
|
||||
manifest.BundleList = new List<PackageBundle>(bundleCount);
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic3 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
}
|
||||
public static void FillBundleCollection(PackageManifest manifest, PackageBundle packageBundle)
|
||||
{
|
||||
// 初始化资源包
|
||||
packageBundle.InitBundle(manifest);
|
||||
|
||||
// 添加到列表集合
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源文件的后缀名
|
||||
|
||||
@ -13,13 +13,15 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _resourcePackage;
|
||||
private readonly UnloadAllAssetsOptions _options;
|
||||
private UnloadAllAssetsOperation _unloadAllAssetsOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DestroyOperation(ResourcePackage resourcePackage)
|
||||
public DestroyOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
|
||||
{
|
||||
_resourcePackage = resourcePackage;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
internal override void InternalStart()
|
||||
@ -64,7 +66,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_unloadAllAssetsOp == null)
|
||||
{
|
||||
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync();
|
||||
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync(_options);
|
||||
_unloadAllAssetsOp.StartOperation();
|
||||
AddChildOperation(_unloadAllAssetsOp);
|
||||
}
|
||||
|
||||
@ -84,7 +84,10 @@ namespace YooAsset
|
||||
|
||||
// 读取文件版本
|
||||
string fileVersion = _buffer.ReadUTF8();
|
||||
if (fileVersion != ManifestDefine.FileVersion)
|
||||
Version fileVer = new Version(fileVersion);
|
||||
Version ver2025_8_28 = new Version(ManifestDefine.VERSION_2025_8_28);
|
||||
Version ver2025_9_30 = new Version(ManifestDefine.VERSION_2025_9_30);
|
||||
if (fileVer < ver2025_8_28)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@ -99,6 +102,10 @@ namespace YooAsset
|
||||
Manifest.SupportExtensionless = _buffer.ReadBool();
|
||||
Manifest.LocationToLower = _buffer.ReadBool();
|
||||
Manifest.IncludeAssetGUID = _buffer.ReadBool();
|
||||
if (fileVer >= ver2025_9_30)
|
||||
Manifest.ReplaceAssetPathWithAddress = _buffer.ReadBool();
|
||||
else
|
||||
Manifest.ReplaceAssetPathWithAddress = false;
|
||||
Manifest.OutputNameStyle = _buffer.ReadInt32();
|
||||
Manifest.BuildBundleType = _buffer.ReadInt32();
|
||||
Manifest.BuildPipeline = _buffer.ReadUTF8();
|
||||
@ -109,6 +116,8 @@ namespace YooAsset
|
||||
// 检测配置
|
||||
if (Manifest.EnableAddressable && Manifest.LocationToLower)
|
||||
throw new System.Exception("Addressable not support location to lower !");
|
||||
if (Manifest.EnableAddressable == false && Manifest.ReplaceAssetPathWithAddress)
|
||||
throw new System.Exception("Replace asset path with address need enable Addressable !");
|
||||
|
||||
_steps = ESteps.PrepareAssetList;
|
||||
}
|
||||
@ -117,27 +126,45 @@ namespace YooAsset
|
||||
{
|
||||
_packageAssetCount = _buffer.ReadInt32();
|
||||
_progressTotalValue = _packageAssetCount;
|
||||
ManifestTools.CreateAssetCollection(Manifest, _packageAssetCount);
|
||||
CreateAssetCollection(Manifest, _packageAssetCount);
|
||||
_steps = ESteps.DeserializeAssetList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeAssetList)
|
||||
{
|
||||
bool replaceAssetPath = false;
|
||||
if (UnityEngine.Application.isPlaying)
|
||||
{
|
||||
if (Manifest.EnableAddressable && Manifest.ReplaceAssetPathWithAddress)
|
||||
replaceAssetPath = true;
|
||||
}
|
||||
|
||||
while (_packageAssetCount > 0)
|
||||
{
|
||||
var packageAsset = new PackageAsset();
|
||||
packageAsset.Address = _buffer.ReadUTF8();
|
||||
if (replaceAssetPath)
|
||||
{
|
||||
packageAsset.AssetPath = packageAsset.Address;
|
||||
_buffer.SkipUTF8(); //跳过解析AssetPath
|
||||
}
|
||||
else
|
||||
{
|
||||
packageAsset.AssetPath = _buffer.ReadUTF8();
|
||||
}
|
||||
packageAsset.AssetGUID = _buffer.ReadUTF8();
|
||||
packageAsset.AssetTags = _buffer.ReadUTF8Array();
|
||||
packageAsset.BundleID = _buffer.ReadInt32();
|
||||
packageAsset.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillAssetCollection(Manifest, packageAsset);
|
||||
FillAssetCollection(Manifest, packageAsset, replaceAssetPath);
|
||||
|
||||
_packageAssetCount--;
|
||||
Progress = 1f - _packageAssetCount / _progressTotalValue;
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_packageAssetCount <= 0)
|
||||
{
|
||||
@ -149,7 +176,7 @@ namespace YooAsset
|
||||
{
|
||||
_packageBundleCount = _buffer.ReadInt32();
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
ManifestTools.CreateBundleCollection(Manifest, _packageBundleCount);
|
||||
CreateBundleCollection(Manifest, _packageBundleCount);
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
if (_steps == ESteps.DeserializeBundleList)
|
||||
@ -165,13 +192,16 @@ namespace YooAsset
|
||||
packageBundle.Encrypted = _buffer.ReadBool();
|
||||
packageBundle.Tags = _buffer.ReadUTF8Array();
|
||||
packageBundle.DependBundleIDs = _buffer.ReadInt32Array();
|
||||
ManifestTools.FillBundleCollection(Manifest, packageBundle);
|
||||
FillBundleCollection(Manifest, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
{
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_packageBundleCount <= 0)
|
||||
{
|
||||
@ -181,7 +211,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.InitManifest)
|
||||
{
|
||||
ManifestTools.InitManifest(Manifest);
|
||||
Manifest.Initialize();
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
@ -194,5 +224,117 @@ namespace YooAsset
|
||||
Error = e.Message;
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateAssetCollection(PackageManifest manifest, int assetCount)
|
||||
{
|
||||
manifest.AssetList = new List<PackageAsset>(assetCount);
|
||||
manifest.AssetDic = new Dictionary<string, PackageAsset>(assetCount);
|
||||
|
||||
if (manifest.EnableAddressable)
|
||||
{
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (manifest.LocationToLower)
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2, StringComparer.OrdinalIgnoreCase);
|
||||
else
|
||||
manifest.AssetPathMapping1 = new Dictionary<string, string>(assetCount * 2);
|
||||
}
|
||||
|
||||
if (manifest.IncludeAssetGUID)
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>(assetCount);
|
||||
else
|
||||
manifest.AssetPathMapping2 = new Dictionary<string, string>();
|
||||
}
|
||||
private void FillAssetCollection(PackageManifest manifest, PackageAsset packageAsset, bool replaceAssetPath)
|
||||
{
|
||||
// 添加到列表集合
|
||||
manifest.AssetList.Add(packageAsset);
|
||||
|
||||
// 注意:我们不允许原始路径存在重名
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
if (manifest.AssetDic.ContainsKey(assetPath))
|
||||
throw new System.Exception($"AssetPath have existed : {assetPath}");
|
||||
else
|
||||
manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (manifest.SupportExtensionless)
|
||||
{
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (manifest.IncludeAssetGUID)
|
||||
{
|
||||
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
|
||||
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
|
||||
else
|
||||
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
|
||||
}
|
||||
|
||||
// 添加可寻址地址
|
||||
if (manifest.EnableAddressable && replaceAssetPath == false)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (string.IsNullOrEmpty(location) == false)
|
||||
{
|
||||
if (manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateBundleCollection(PackageManifest manifest, int bundleCount)
|
||||
{
|
||||
manifest.BundleList = new List<PackageBundle>(bundleCount);
|
||||
manifest.BundleDic1 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
manifest.BundleDic3 = new Dictionary<string, PackageBundle>(bundleCount);
|
||||
}
|
||||
private void FillBundleCollection(PackageManifest manifest, PackageBundle packageBundle)
|
||||
{
|
||||
// 初始化资源包
|
||||
packageBundle.InitBundle(manifest);
|
||||
|
||||
// 添加到列表集合
|
||||
manifest.BundleList.Add(packageBundle);
|
||||
|
||||
manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称样式
|
||||
/// </summary>
|
||||
|
||||
@ -36,6 +36,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名称样式
|
||||
/// </summary>
|
||||
@ -113,6 +118,38 @@ namespace YooAsset
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源清单
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
// 填充资源包内包含的主资源列表
|
||||
foreach (var packageAsset in AssetList)
|
||||
{
|
||||
int bundleID = packageAsset.BundleID;
|
||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||
{
|
||||
var packageBundle = BundleList[bundleID];
|
||||
packageBundle.IncludeMainAssets.Add(packageAsset);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 填充资源包引用关系
|
||||
for (int index = 0; index < BundleList.Count; index++)
|
||||
{
|
||||
var sourceBundle = BundleList[index];
|
||||
foreach (int dependIndex in sourceBundle.DependBundleIDs)
|
||||
{
|
||||
var dependBundle = BundleList[dependIndex];
|
||||
dependBundle.AddReferenceBundleID(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的详细信息
|
||||
/// </summary>
|
||||
@ -124,6 +161,7 @@ namespace YooAsset
|
||||
details.SupportExtensionless = SupportExtensionless;
|
||||
details.LocationToLower = LocationToLower;
|
||||
details.IncludeAssetGUID = IncludeAssetGUID;
|
||||
details.ReplaceAssetPathWithAddress = ReplaceAssetPathWithAddress;
|
||||
details.OutputNameStyle = OutputNameStyle;
|
||||
details.BuildBundleType = BuildBundleType;
|
||||
details.BuildPipeline = BuildPipeline;
|
||||
|
||||
@ -209,7 +209,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public DestroyOperation DestroyAsync()
|
||||
{
|
||||
var operation = new DestroyOperation(this);
|
||||
var options = new UnloadAllAssetsOptions();
|
||||
options.ReleaseAllHandles = true;
|
||||
options.LockLoadOperation = true;
|
||||
var operation = new DestroyOperation(this, options);
|
||||
OperationSystem.StartOperation(null, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@ -120,6 +120,15 @@ namespace YooAsset
|
||||
return (ulong)ReadInt64();
|
||||
}
|
||||
|
||||
public void SkipUTF8()
|
||||
{
|
||||
ushort count = ReadUInt16();
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
CheckReaderIndex(count);
|
||||
_index += count;
|
||||
}
|
||||
public string ReadUTF8()
|
||||
{
|
||||
ushort count = ReadUInt16();
|
||||
|
||||
@ -76,13 +76,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// Gets the computed hash value.
|
||||
/// </summary>
|
||||
public uint CRCValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return _currentCrc;
|
||||
}
|
||||
}
|
||||
public uint CRCValue { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CRC32Algorithm"/> class.
|
||||
@ -115,6 +109,8 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
CRCValue = _currentCrc;
|
||||
|
||||
if (BitConverter.IsLittleEndian)
|
||||
return new[] { (byte)_currentCrc, (byte)(_currentCrc >> 8), (byte)(_currentCrc >> 16), (byte)(_currentCrc >> 24) };
|
||||
else
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b127fedb48547954b9c54084b6a32a65
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d2280a83472bd14bb033f506647284d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,280 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using AlipaySdk;
|
||||
|
||||
public static class AlipayFileSystemCreater
|
||||
{
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
|
||||
{
|
||||
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
|
||||
{
|
||||
string fileSystemClass = $"{nameof(AlipayFileSystem)},YooAsset.MiniGame";
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付宝小游戏文件系统
|
||||
/// 参考:https://opendocs.alipay.com/mini-game/0ftleg
|
||||
/// </summary>
|
||||
internal class AlipayFileSystem : IFileSystem
|
||||
{
|
||||
private class WebRemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _webPackageRoot;
|
||||
protected readonly Dictionary<string, string> _mapping = new Dictionary<string, string>(10000);
|
||||
|
||||
public WebRemoteServices(string buildinPackRoot)
|
||||
{
|
||||
_webPackageRoot = buildinPackRoot;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return GetFileLoadURL(fileName);
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return GetFileLoadURL(fileName);
|
||||
}
|
||||
|
||||
private string GetFileLoadURL(string fileName)
|
||||
{
|
||||
if (_mapping.TryGetValue(fileName, out string url) == false)
|
||||
{
|
||||
string filePath = PathUtility.Combine(_webPackageRoot, fileName);
|
||||
url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_mapping.Add(fileName, url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, string> _cacheFilePathMapping = new Dictionary<string, string>(10000);
|
||||
private AlipayFSManager _fileSystemMgr;
|
||||
private string _aliCacheRoot = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件根目录
|
||||
/// </summary>
|
||||
public string FileRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return _aliCacheRoot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件数量
|
||||
/// </summary>
|
||||
public int FileCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// </summary>
|
||||
public IWebDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:资源清单服务类
|
||||
/// </summary>
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
#endregion
|
||||
|
||||
|
||||
public AlipayFileSystem()
|
||||
{
|
||||
}
|
||||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||||
{
|
||||
var operation = new APFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new APFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new APFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new FSClearCacheFilesCompleteOperation();
|
||||
return operation;
|
||||
}
|
||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||
{
|
||||
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||
options.SetURL(mainURL, fallbackURL);
|
||||
var operation = new APFSDownloadFileOperation(this, bundle, options);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new APFSLoadBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(AlipayFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
var operation = new FSLoadBundleCompleteOperation(error);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IWebDecryptionServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
|
||||
{
|
||||
ManifestServices = (IManifestRestoreServices)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Invalid parameter : {name}");
|
||||
}
|
||||
}
|
||||
public virtual void OnCreate(string packageName, string rootDirectory)
|
||||
{
|
||||
PackageName = packageName;
|
||||
_aliCacheRoot = rootDirectory;
|
||||
|
||||
if (string.IsNullOrEmpty(_aliCacheRoot))
|
||||
{
|
||||
throw new System.Exception("请配置小游戏的缓存根目录!");
|
||||
}
|
||||
|
||||
// 注意:CDN服务未启用的情况下,使用WEB服务器
|
||||
if (RemoteServices == null)
|
||||
{
|
||||
string webRoot = PathUtility.Combine(Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName, packageName);
|
||||
RemoteServices = new WebRemoteServices(webRoot);
|
||||
}
|
||||
|
||||
_fileSystemMgr = AlipaySDK.API.GetFileSystemManager();
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public virtual bool Exists(PackageBundle bundle)
|
||||
{
|
||||
return CheckCacheFileExist(bundle);
|
||||
}
|
||||
public virtual bool NeedDownload(PackageBundle bundle)
|
||||
{
|
||||
if (Belong(bundle) == false)
|
||||
return false;
|
||||
|
||||
return Exists(bundle) == false;
|
||||
}
|
||||
public virtual bool NeedUnpack(PackageBundle bundle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool NeedImport(PackageBundle bundle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual string GetBundleFilePath(PackageBundle bundle)
|
||||
{
|
||||
return GetCacheFileLoadPath(bundle);
|
||||
}
|
||||
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
|
||||
{
|
||||
if (CheckCacheFileExist(bundle))
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return _fileSystemMgr.ReadFileSync(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
public virtual string ReadBundleFileText(PackageBundle bundle)
|
||||
{
|
||||
if (CheckCacheFileExist(bundle))
|
||||
{
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return _fileSystemMgr.ReadFileSync(filePath, "utf8");
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
public AlipayFSManager GetFileSystemMgr()
|
||||
{
|
||||
return _fileSystemMgr;
|
||||
}
|
||||
public bool CheckCacheFileExist(PackageBundle bundle)
|
||||
{
|
||||
//TODO : 效率极低
|
||||
/*
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
string result = _fileSystemMgr.AccessSync(filePath);
|
||||
return result.Equals("access:ok", StringComparison.Ordinal);
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
private string GetCacheFileLoadPath(PackageBundle bundle)
|
||||
{
|
||||
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)
|
||||
{
|
||||
filePath = PathUtility.Combine(_aliCacheRoot, bundle.FileName);
|
||||
_cacheFilePathMapping.Add(bundle.BundleGUID, filePath);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61be9965c7f7aae468a34b3ed38116b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44b9746ed3270394eb54d85b27a2ef04
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,67 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using AlipaySdk;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class APAssetBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
|
||||
public APAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.APUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1de437726bd89584da56aaddfdb1a07c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18ae5147de9585045ab40941d945696b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,111 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
internal class APFSDownloadFileOperation : FSDownloadFileOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
CheckRequest,
|
||||
TryAgain,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AlipayFileSystem _fileSystem;
|
||||
private readonly DownloadFileOptions _options;
|
||||
private UnityWebCacheRequestOperation _webCacheRequestOp;
|
||||
private int _requestCount = 0;
|
||||
private float _tryAgainTimer;
|
||||
private int _failedTryAgain;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal APFSDownloadFileOperation(AlipayFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
// 创建下载器
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
string url = GetRequestURL();
|
||||
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||
_webCacheRequestOp.StartOperation();
|
||||
AddChildOperation(_webCacheRequestOp);
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
|
||||
// 检测下载结果
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
_webCacheRequestOp.UpdateOperation();
|
||||
Progress = _webCacheRequestOp.Progress;
|
||||
DownloadProgress = _webCacheRequestOp.DownloadProgress;
|
||||
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
|
||||
if (_webCacheRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
//TODO 需要验证插件请求器的下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = Bundle.FileSize;
|
||||
Progress = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webCacheRequestOp.Error;
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重新尝试下载
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||
if (_tryAgainTimer > 1f)
|
||||
{
|
||||
_tryAgainTimer = 0f;
|
||||
_failedTryAgain--;
|
||||
Progress = 0f;
|
||||
DownloadProgress = 0f;
|
||||
DownloadedBytes = 0;
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取网络请求地址
|
||||
/// </summary>
|
||||
private string GetRequestURL()
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
_requestCount++;
|
||||
if (_requestCount % 2 == 0)
|
||||
return _options.FallbackURL;
|
||||
else
|
||||
return _options.MainURL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc47317a416e9f542b7ec6b77485a8b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,20 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal partial class APFSInitializeOperation : FSInitializeFileSystemOperation
|
||||
{
|
||||
private readonly AlipayFileSystem _fileSystem;
|
||||
|
||||
public APFSInitializeOperation(AlipayFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71a99a94d7563fe4a9d56ea0e15aa8d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,88 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class APFSLoadBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssetBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AlipayFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal APFSLoadBundleOperation(AlipayFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_loadWebAssetBundleOp == null)
|
||||
{
|
||||
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
options.SetURL(mainURL, fallbackURL);
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadAlipayAssetBundleOperation(_bundle, options);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
}
|
||||
|
||||
_loadWebAssetBundleOp.UpdateOperation();
|
||||
Progress = _loadWebAssetBundleOp.Progress;
|
||||
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||
if (_loadWebAssetBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||
_steps = ESteps.Done;
|
||||
Result = new APAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadWebAssetBundleOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
if (_steps != ESteps.Done)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "WebGL platform not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f71fc4fc468d41441b00be64938b2fe9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,95 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class APFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageHash,
|
||||
LoadPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AlipayFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private RequestWebPackageHashOperation _requestPackageHashOp;
|
||||
private LoadWebPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public APFSLoadPackageManifestOperation(AlipayFileSystem fileSystem, string packageVersion, int timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageHash;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageHash)
|
||||
{
|
||||
if (_requestPackageHashOp == null)
|
||||
{
|
||||
_requestPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _packageVersion, _timeout);
|
||||
_requestPackageHashOp.StartOperation();
|
||||
AddChildOperation(_requestPackageHashOp);
|
||||
}
|
||||
|
||||
_requestPackageHashOp.UpdateOperation();
|
||||
if (_requestPackageHashOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestPackageHashOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestPackageHashOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
string packageHash = _requestPackageHashOp.PackageHash;
|
||||
string packageName = _fileSystem.PackageName;
|
||||
var manifestServices = _fileSystem.ManifestServices;
|
||||
var remoteServices = _fileSystem.RemoteServices;
|
||||
_loadPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, packageName, _packageVersion, packageHash, _timeout);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
|
||||
_loadPackageManifestOp.UpdateOperation();
|
||||
Progress = _loadPackageManifestOp.Progress;
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Manifest = _loadPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 335885fb4e1977a4ca5c26263eda03d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,64 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class APFSRequestPackageVersionOperation : FSRequestPackageVersionOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AlipayFileSystem _fileSystem;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private RequestWebPackageVersionOperation _requestWebPackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal APFSRequestPackageVersionOperation(AlipayFileSystem fileSystem, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_requestWebPackageVersionOp == null)
|
||||
{
|
||||
_requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _appendTimeTicks, _timeout);
|
||||
_requestWebPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestWebPackageVersionOp);
|
||||
}
|
||||
|
||||
_requestWebPackageVersionOp.UpdateOperation();
|
||||
Progress = _requestWebPackageVersionOp.Progress;
|
||||
if (_requestWebPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
PackageVersion = _requestWebPackageVersionOp.PackageVersion;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestWebPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a879fd6a506b37345b4b9ea6c5de20bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b94d7bcfa19151046a1f0ed8e089a474
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,115 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using UnityEngine;
|
||||
using AlipaySdk;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadAlipayAssetBundleOperation : LoadWebAssetBundleOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
CheckRequest,
|
||||
TryAgain,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _bundle;
|
||||
private readonly DownloadFileOptions _options;
|
||||
private UnityAlipayAssetBundleRequestOperation _unityAssetBundleRequestOp;
|
||||
|
||||
private int _requestCount = 0;
|
||||
private float _tryAgainTimer;
|
||||
private int _failedTryAgain;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal LoadAlipayAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
|
||||
{
|
||||
_bundle = bundle;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 创建下载器
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
string url = GetRequestURL();
|
||||
_unityAssetBundleRequestOp = new UnityAlipayAssetBundleRequestOperation(_bundle, url);
|
||||
_unityAssetBundleRequestOp.StartOperation();
|
||||
AddChildOperation(_unityAssetBundleRequestOp);
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
|
||||
// 检测下载结果
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
_unityAssetBundleRequestOp.UpdateOperation();
|
||||
Progress = _unityAssetBundleRequestOp.Progress;
|
||||
DownloadProgress = _unityAssetBundleRequestOp.DownloadProgress;
|
||||
DownloadedBytes = _unityAssetBundleRequestOp.DownloadedBytes;
|
||||
if (_unityAssetBundleRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_unityAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
Result = _unityAssetBundleRequestOp.Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _unityAssetBundleRequestOp.Error;
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重新尝试下载
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||
if (_tryAgainTimer > 1f)
|
||||
{
|
||||
_tryAgainTimer = 0f;
|
||||
_failedTryAgain--;
|
||||
Progress = 0f;
|
||||
DownloadProgress = 0f;
|
||||
DownloadedBytes = 0;
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取网络请求地址
|
||||
/// </summary>
|
||||
private string GetRequestURL()
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
_requestCount++;
|
||||
if (_requestCount % 2 == 0)
|
||||
return _options.FallbackURL;
|
||||
else
|
||||
return _options.MainURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62249d32580e2ef48a33afb58515312a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,95 +0,0 @@
|
||||
#if UNITY_WEBGL && UNITY_ALIMINIGAME
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
using AlipaySdk;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class UnityAlipayAssetBundleRequestOperation : UnityWebRequestOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
Download,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private UnityWebRequestAsyncOperation _requestOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 请求结果
|
||||
/// </summary>
|
||||
public AssetBundle Result { private set; get; }
|
||||
|
||||
internal UnityAlipayAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
|
||||
{
|
||||
_packageBundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
CreateWebRequest();
|
||||
_steps = ESteps.Download;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
Progress = _requestOperation.progress;
|
||||
if (_requestOperation.isDone == false)
|
||||
return;
|
||||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
var downloadHanlder = (DownloadHandlerAPAssetBundle)_webRequest.downloadHandler;
|
||||
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
||||
if (assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = assetBundle;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
//TODO 需要验证插件请求器的下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _packageBundle.FileSize;
|
||||
Progress = 1f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
|
||||
// 注意:最终释放请求器
|
||||
DisposeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
_webRequest = APAssetBundle.GetAssetBundle(_requestURL);
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
_requestOperation = _webRequest.SendWebRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2e7a4e37ac067f4ba0a43ebea0aa3f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d27136885efd6ab4fae1a1fea23b0010
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,42 +0,0 @@
|
||||
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
public static class GooglePlayFileSystemCreater
|
||||
{
|
||||
public static FileSystemParameters CreateFileSystemParameters(string packageRoot)
|
||||
{
|
||||
string fileSystemClass = $"{nameof(GooglePlayFileSystem)},YooAsset.MiniGame";
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||
return fileSystemParams;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容谷歌Play Asset Delivery的文件系统
|
||||
/// </summary>
|
||||
internal class GooglePlayFileSystem : DefaultBuildinFileSystem
|
||||
{
|
||||
public GooglePlayFileSystem()
|
||||
{
|
||||
}
|
||||
|
||||
public override FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||
{
|
||||
var operation = new GPFSLoadAssetBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(GooglePlayFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
var operation = new FSLoadBundleCompleteOperation(error);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a09145cd500f3f42b2a17524f0dd3f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 055e7cf3bb9567f43bf15964d43c632f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,85 +0,0 @@
|
||||
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Google.Play.AssetDelivery;
|
||||
|
||||
internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly GooglePlayFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private PlayAssetBundleRequest _bundleRequest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal GPFSLoadAssetBundleOperation(GooglePlayFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The {nameof(GooglePlayFileSystem)} not support bundle encrypted !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(_bundle.FileName);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_bundleRequest.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_bundleRequest.Error != AssetDeliveryErrorCode.NoError)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load delivery asset bundle file : {_bundle.BundleName} Error : {_bundleRequest.Error}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
Result = new AssetBundleResult(_fileSystem, _bundle, _bundleRequest.AssetBundle, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
if (_steps != ESteps.Done)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(GooglePlayFileSystem)} not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aeb57dcd2a7a8841bb161f5f343a25e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc739bb54706c347b7ee54cbe51b69c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,98 +0,0 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class FileSystemTester
|
||||
{
|
||||
public IEnumerator RunTester(IFileSystem fileSystem, string testLocation)
|
||||
{
|
||||
string packageName = fileSystem.PackageName;
|
||||
|
||||
// 初始化小游戏文件系统
|
||||
Debug.Log("初始化小游戏文件系统!");
|
||||
var initializeFileSystemOp = fileSystem.InitializeFileSystemAsync();
|
||||
OperationSystem.StartOperation(packageName, initializeFileSystemOp);
|
||||
yield return initializeFileSystemOp;
|
||||
if (initializeFileSystemOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogError($"初始化小游戏文件系统失败!{initializeFileSystemOp.Error}");
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 请求资源版本
|
||||
Debug.Log("请求资源版本信息!");
|
||||
var requestPackageVersionOp = fileSystem.RequestPackageVersionAsync(true, 60);
|
||||
OperationSystem.StartOperation(packageName, requestPackageVersionOp);
|
||||
yield return requestPackageVersionOp;
|
||||
if (requestPackageVersionOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogError($"请求资源版本信息失败!{requestPackageVersionOp.Error}");
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 请求资源清单
|
||||
string packageVersion = requestPackageVersionOp.PackageVersion;
|
||||
Debug.Log($"加载资源清单文件!{packageVersion}");
|
||||
var loadPackageManifestOp = fileSystem.LoadPackageManifestAsync(packageVersion, 60);
|
||||
OperationSystem.StartOperation(packageName, loadPackageManifestOp);
|
||||
yield return loadPackageManifestOp;
|
||||
if (loadPackageManifestOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogError($"加载资源清单文件失败!{loadPackageManifestOp.Error}");
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 预下载资源包
|
||||
Debug.Log("预下载资源包!");
|
||||
{
|
||||
var manifest = loadPackageManifestOp.Manifest;
|
||||
var packageBundle = GetPackageBundle(manifest, testLocation);
|
||||
var options = new DownloadFileOptions(1);
|
||||
var downloadFileOp = fileSystem.DownloadFileAsync(packageBundle, options);
|
||||
OperationSystem.StartOperation(packageName, downloadFileOp);
|
||||
yield return downloadFileOp;
|
||||
if (downloadFileOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogError($"预下载资源包失败!{downloadFileOp.Error}");
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("预下载资源包成功!");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载资源包
|
||||
Debug.Log("加载资源包!");
|
||||
{
|
||||
var manifest = loadPackageManifestOp.Manifest;
|
||||
var packageBundle = GetPackageBundle(manifest, testLocation);
|
||||
var loadBundleFileOp = fileSystem.LoadBundleFile(packageBundle);
|
||||
OperationSystem.StartOperation(packageName, loadBundleFileOp);
|
||||
yield return loadBundleFileOp;
|
||||
if (loadBundleFileOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
Debug.LogError($"加载资源包失败!{loadBundleFileOp.Error}");
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("加载资源包成功!");
|
||||
}
|
||||
|
||||
// 卸载资源包
|
||||
loadBundleFileOp.Result.UnloadBundleFile();
|
||||
}
|
||||
|
||||
Debug.Log("完整测试成功!");
|
||||
}
|
||||
|
||||
private PackageBundle GetPackageBundle(PackageManifest manifest, string location)
|
||||
{
|
||||
var assetInfo = manifest.ConvertLocationToAssetInfo(location, typeof(GameObject));
|
||||
var packageBundle = manifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
return packageBundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19ed2b81fece5b84fa771a5eeb108572
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,49 +0,0 @@
|
||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class TiktokFileSystemTest : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
YooAssets.Initialize();
|
||||
}
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
string packageName = "DefaultPackage";
|
||||
string testLocation = "asteroid01";
|
||||
string hostServer = "http://127.0.0.1/CDN/WebGL/yoo";
|
||||
string packageRoot = $"{StarkSDKSpace.StarkFileSystemManager.USER_DATA_PATH}/__GAME_FILE_CACHE";
|
||||
|
||||
IRemoteServices remoteServices = new RemoteServices(hostServer);
|
||||
TiktokFileSystem fileSystem = new TiktokFileSystem();
|
||||
fileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystem.OnCreate(packageName, packageRoot);
|
||||
|
||||
FileSystemTester tester = new FileSystemTester();
|
||||
yield return tester.RunTester(fileSystem, testLocation);
|
||||
}
|
||||
|
||||
private class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _hostServer;
|
||||
|
||||
public RemoteServices(string hostServer)
|
||||
{
|
||||
_hostServer = hostServer;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_hostServer}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_hostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec9d17e765ccd4642aa3aa9ca0580799
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,49 +0,0 @@
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class WechatFileSystemTest : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
YooAssets.Initialize();
|
||||
}
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
string packageName = "DefaultPackage";
|
||||
string testLocation = "asteroid01";
|
||||
string hostServer = "http://127.0.0.1/CDN/WebGL/yoo";
|
||||
string packageRoot = $"{WeChatWASM.WX.env.USER_DATA_PATH}/__GAME_FILE_CACHE";
|
||||
|
||||
IRemoteServices remoteServices = new RemoteServices(hostServer);
|
||||
WechatFileSystem fileSystem = new WechatFileSystem();
|
||||
fileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
fileSystem.OnCreate(packageName, packageRoot);
|
||||
|
||||
FileSystemTester tester = new FileSystemTester();
|
||||
yield return tester.RunTester(fileSystem, testLocation);
|
||||
}
|
||||
|
||||
private class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _hostServer;
|
||||
|
||||
public RemoteServices(string hostServer)
|
||||
{
|
||||
_hostServer = hostServer;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_hostServer}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_hostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3036392c24e1a3b49b7628fbf6cc24d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6835d091fc4e4e438770512ec53c05c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff9085fca05646b4e9f6dfec5f9cd5ab
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,67 +0,0 @@
|
||||
#if UNITY_WEBGL && TAPMINIGAME
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TapTapMiniGame;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class TPAssetBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
|
||||
public TPAssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
if (_packageBundle.Encrypted)
|
||||
_assetBundle.Unload(true);
|
||||
else
|
||||
_assetBundle.TapUnload(true);
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e914b1b35e8a6ae48bdfe71a0614ab0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbbb8f216603c4042b3c29cdde607705
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,111 +0,0 @@
|
||||
#if UNITY_WEBGL && TAPMINIGAME
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
internal class TPFSDownloadFileOperation : FSDownloadFileOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
CheckRequest,
|
||||
TryAgain,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly TaptapFileSystem _fileSystem;
|
||||
private readonly DownloadFileOptions _options;
|
||||
private UnityWebCacheRequestOperation _webCacheRequestOp;
|
||||
private int _requestCount = 0;
|
||||
private float _tryAgainTimer;
|
||||
private int _failedTryAgain;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal TPFSDownloadFileOperation(TaptapFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
// 创建下载器
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
string url = GetRequestURL();
|
||||
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||
_webCacheRequestOp.StartOperation();
|
||||
AddChildOperation(_webCacheRequestOp);
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
|
||||
// 检测下载结果
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
_webCacheRequestOp.UpdateOperation();
|
||||
Progress = _webCacheRequestOp.Progress;
|
||||
DownloadProgress = _webCacheRequestOp.DownloadProgress;
|
||||
DownloadedBytes = _webCacheRequestOp.DownloadedBytes;
|
||||
if (_webCacheRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
|
||||
//TODO 需要验证插件请求器的下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = Bundle.FileSize;
|
||||
Progress = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_failedTryAgain > 0)
|
||||
{
|
||||
_steps = ESteps.TryAgain;
|
||||
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webCacheRequestOp.Error;
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重新尝试下载
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||
if (_tryAgainTimer > 1f)
|
||||
{
|
||||
_tryAgainTimer = 0f;
|
||||
_failedTryAgain--;
|
||||
Progress = 0f;
|
||||
DownloadProgress = 0f;
|
||||
DownloadedBytes = 0;
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取网络请求地址
|
||||
/// </summary>
|
||||
private string GetRequestURL()
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
_requestCount++;
|
||||
if (_requestCount % 2 == 0)
|
||||
return _options.FallbackURL;
|
||||
else
|
||||
return _options.MainURL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0d44d1a88d041a4cb6240d30d96fdf2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,20 +0,0 @@
|
||||
#if UNITY_WEBGL && TAPMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal partial class TPFSInitializeOperation : FSInitializeFileSystemOperation
|
||||
{
|
||||
private readonly TaptapFileSystem _fileSystem;
|
||||
|
||||
public TPFSInitializeOperation(TaptapFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 017c1f2fbc59ff8418cc781c5e66efef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,88 +0,0 @@
|
||||
#if UNITY_WEBGL && TAPMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class TPFSLoadBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssetBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly TaptapFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal TPFSLoadBundleOperation(TaptapFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_bundle = bundle;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_loadWebAssetBundleOp == null)
|
||||
{
|
||||
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||
options.SetURL(mainURL, fallbackURL);
|
||||
|
||||
if (_bundle.Encrypted)
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadWebAssetBundleOp = new LoadTaptapAssetBundleOperation(_bundle, options);
|
||||
_loadWebAssetBundleOp.StartOperation();
|
||||
AddChildOperation(_loadWebAssetBundleOp);
|
||||
}
|
||||
}
|
||||
|
||||
_loadWebAssetBundleOp.UpdateOperation();
|
||||
Progress = _loadWebAssetBundleOp.Progress;
|
||||
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||
if (_loadWebAssetBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||
_steps = ESteps.Done;
|
||||
Result = new TPAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadWebAssetBundleOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
if (_steps != ESteps.Done)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "WebGL platform not support sync load method !";
|
||||
UnityEngine.Debug.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01680b24db924794b8adc1e0e6697865
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,95 +0,0 @@
|
||||
#if UNITY_WEBGL && TAPMINIGAME
|
||||
using YooAsset;
|
||||
|
||||
internal class TPFSLoadPackageManifestOperation : FSLoadPackageManifestOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageHash,
|
||||
LoadPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly TaptapFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private RequestWebPackageHashOperation _requestPackageHashOp;
|
||||
private LoadWebPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public TPFSLoadPackageManifestOperation(TaptapFileSystem fileSystem, string packageVersion, int timeout)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageHash;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageHash)
|
||||
{
|
||||
if (_requestPackageHashOp == null)
|
||||
{
|
||||
_requestPackageHashOp = new RequestWebPackageHashOperation(_fileSystem.RemoteServices, _fileSystem.PackageName, _packageVersion, _timeout);
|
||||
_requestPackageHashOp.StartOperation();
|
||||
AddChildOperation(_requestPackageHashOp);
|
||||
}
|
||||
|
||||
_requestPackageHashOp.UpdateOperation();
|
||||
if (_requestPackageHashOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestPackageHashOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestPackageHashOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
string packageHash = _requestPackageHashOp.PackageHash;
|
||||
string packageName = _fileSystem.PackageName;
|
||||
var manifestServices = _fileSystem.ManifestServices;
|
||||
var remoteServices = _fileSystem.RemoteServices;
|
||||
_loadPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, packageName, _packageVersion, packageHash, _timeout);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
|
||||
_loadPackageManifestOp.UpdateOperation();
|
||||
Progress = _loadPackageManifestOp.Progress;
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Manifest = _loadPackageManifestOp.Manifest;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9900531297a5a140806316f844fa0a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user