mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-22 16:50:18 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0311d976bb | ||
|
|
120c07cc2e | ||
|
|
ed5ae40cb3 | ||
|
|
5931d91b5f | ||
|
|
472a5ae97a | ||
|
|
829ea66d0e | ||
|
|
ba39291ee7 | ||
|
|
d3d15fc59f | ||
|
|
8a3358c990 | ||
|
|
8eadba3aa6 | ||
|
|
b0917623b6 | ||
|
|
a7d9a4ecbc | ||
|
|
2643ab81ed | ||
|
|
c5314c72f0 | ||
|
|
fbb48ba330 | ||
|
|
4e6879e34f | ||
|
|
09c3d4e479 | ||
|
|
1e88bad73e | ||
|
|
9a2ed64b4e | ||
|
|
60e93f9809 | ||
|
|
f5c72e913f |
@@ -2,6 +2,146 @@
|
|||||||
|
|
||||||
All notable changes to this package will be documented in this file.
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [1.5.1] - 2023-07-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了太空战机DEMO在生成内置文件清单的时候,目录不存在引发的异常。
|
||||||
|
- 修复了在销毁Package时,如果存在正在加载的bundle,会导致后续加载该bundle报错的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 真机上使用错误方法加载原生文件的时候给予正确的错误提示。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增了HostPlayModeParameters.RemoteServices字段
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 远端资源地址查询服务类
|
||||||
|
/// </summary>
|
||||||
|
public IRemoteServices RemoteServices = null;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- 移除了HostPlayModeParameters.DefaultHostServer字段
|
||||||
|
- 移除了HostPlayModeParameters.FallbackHostServer字段
|
||||||
|
|
||||||
|
## [1.5.0] - 2023-07-05
|
||||||
|
|
||||||
|
该版本重构了Persistent类,导致沙盒目录和内置目录的存储结构发生了变化。
|
||||||
|
|
||||||
|
该版本支持按照Package自定义沙盒存储目录和内置存储目录。
|
||||||
|
|
||||||
|
**注意:低版本升级用户,请使用Space Shooter目录下的StreamingAssetsHelper插件覆盖到本地工程!**
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- BuildParameters.OutputRoot重命名为BuildOutputRoot
|
||||||
|
- 变更了IQueryServices.QueryStreamingAssets(string packageName, string fileName)方法
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增了YooAssets.SetCacheSystemDisableCacheOnWebGL()方法
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 设置缓存系统参数,禁用缓存在WebGL平台
|
||||||
|
/// </summary>
|
||||||
|
public static void SetCacheSystemDisableCacheOnWebGL()
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了YooAssets.SetDownloadSystemRedirectLimit()方法
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 设置下载系统参数,网络重定向次数(Unity引擎默认值32)
|
||||||
|
/// 注意:不支持设置为负值
|
||||||
|
/// </summary>
|
||||||
|
public static void SetDownloadSystemRedirectLimit(int redirectLimit)
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了构建流程可扩展的方法。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
public class AssetBundleBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构建资源包
|
||||||
|
/// </summary>
|
||||||
|
public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了BuildParameters.StreamingAssetsRoot字段
|
||||||
|
|
||||||
|
```c#
|
||||||
|
public class BuildParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 内置资源的根目录
|
||||||
|
/// </summary>
|
||||||
|
public string StreamingAssetsRoot;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了InitializeParameters.BuildinRootDirectory字段
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 内置文件的根路径
|
||||||
|
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||||
|
/// </summary>
|
||||||
|
public string BuildinRootDirectory = string.Empty;
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了InitializeParameters.SandboxRootDirectory字段
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 沙盒文件的根路径
|
||||||
|
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||||
|
/// </summary>
|
||||||
|
public string SandboxRootDirectory = string.Empty;
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了ResourcePackage.GetPackageBuildinRootDirectory()方法
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取包裹的内置文件根路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageBuildinRootDirectory()
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了ResourcePackage.GetPackageSandboxRootDirectory()方法
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取包裹的沙盒文件根路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageSandboxRootDirectory()
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增了ResourcePackage.ClearPackageSandbox()方法
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 清空包裹的沙盒目录
|
||||||
|
/// </summary>
|
||||||
|
public void ClearPackageSandbox()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- 移除了资源包构建流程任务节点可扩展功能。
|
||||||
|
- 移除了YooAssets.SetCacheSystemSandboxPath()方法
|
||||||
|
- 移除了YooAssets.GetStreamingAssetBuildinFolderName()方法
|
||||||
|
- 移除了YooAssets.GetSandboxRoot()方法
|
||||||
|
- 移除了YooAssets.ClearSandbox()方法
|
||||||
|
|
||||||
## [1.4.17] - 2023-06-27
|
## [1.4.17] - 2023-06-27
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@@ -25,8 +165,6 @@ All notable changes to this package will be documented in this file.
|
|||||||
|
|
||||||
- IShareAssetPackRule 重命名为 ISharedPackRule
|
- IShareAssetPackRule 重命名为 ISharedPackRule
|
||||||
|
|
||||||
-
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- 新增了ResourcePackage.LoadAllAssetsAsync方法
|
- 新增了ResourcePackage.LoadAllAssetsAsync方法
|
||||||
|
|||||||
@@ -13,29 +13,20 @@ namespace YooAsset.Editor
|
|||||||
private readonly BuildContext _buildContext = new BuildContext();
|
private readonly BuildContext _buildContext = new BuildContext();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 开始构建
|
/// 构建资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildResult Run(BuildParameters buildParameters)
|
public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline)
|
||||||
{
|
{
|
||||||
// 清空旧数据
|
|
||||||
_buildContext.ClearAllContext();
|
|
||||||
|
|
||||||
// 检测构建参数是否为空
|
// 检测构建参数是否为空
|
||||||
if (buildParameters == null)
|
if (buildParameters == null)
|
||||||
throw new Exception($"{nameof(buildParameters)} is null !");
|
throw new Exception($"{nameof(buildParameters)} is null !");
|
||||||
|
|
||||||
// 检测可编程构建管线参数
|
// 检测构建参数是否为空
|
||||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
if (buildPipeline.Count == 0)
|
||||||
{
|
throw new Exception($"Build pipeline is empty !");
|
||||||
if (buildParameters.SBPParameters == null)
|
|
||||||
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
|
|
||||||
|
|
||||||
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
|
// 清空旧数据
|
||||||
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
|
_buildContext.ClearAllContext();
|
||||||
|
|
||||||
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
|
||||||
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
var buildParametersContext = new BuildParametersContext(buildParameters);
|
var buildParametersContext = new BuildParametersContext(buildParameters);
|
||||||
@@ -45,8 +36,7 @@ namespace YooAsset.Editor
|
|||||||
BuildLogger.InitLogger(buildParameters.EnableLog);
|
BuildLogger.InitLogger(buildParameters.EnableLog);
|
||||||
|
|
||||||
// 执行构建流程
|
// 执行构建流程
|
||||||
var pipeline = GetBuildTasks(buildParameters.BuildPipeline);
|
var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
|
||||||
var buildResult = BuildRunner.Run(pipeline, _buildContext);
|
|
||||||
if (buildResult.Success)
|
if (buildResult.Success)
|
||||||
{
|
{
|
||||||
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
|
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||||
@@ -62,13 +52,23 @@ namespace YooAsset.Editor
|
|||||||
return buildResult;
|
return buildResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IBuildTask> GetBuildTasks(EBuildPipeline buildPipeline)
|
/// <summary>
|
||||||
|
/// 构建资源包
|
||||||
|
/// </summary>
|
||||||
|
public BuildResult Run(BuildParameters buildParameters)
|
||||||
|
{
|
||||||
|
var buildPipeline = GetDefaultBuildPipeline(buildParameters.BuildPipeline);
|
||||||
|
return Run(buildParameters, buildPipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取默认的构建流程
|
||||||
|
/// </summary>
|
||||||
|
private List<IBuildTask> GetDefaultBuildPipeline(EBuildPipeline buildPipeline)
|
||||||
{
|
{
|
||||||
// 获取任务节点的属性集合
|
// 获取任务节点的属性集合
|
||||||
List<TaskAttribute> attrList = new List<TaskAttribute>();
|
|
||||||
if (buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
if (buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||||
{
|
{
|
||||||
new TaskPrepare(), //前期准备工作
|
new TaskPrepare(), //前期准备工作
|
||||||
@@ -83,23 +83,10 @@ namespace YooAsset.Editor
|
|||||||
new TaskCreatePackage(), //制作包裹
|
new TaskCreatePackage(), //制作包裹
|
||||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||||
};
|
};
|
||||||
*/
|
return pipeline;
|
||||||
|
|
||||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IBuildTask));
|
|
||||||
foreach (var classType in classTypes)
|
|
||||||
{
|
|
||||||
var attribute = classType.GetCustomAttribute<TaskAttribute>();
|
|
||||||
if (attribute == null)
|
|
||||||
throw new Exception($"Not found {nameof(TaskAttribute)} int type : {classType.FullName}");
|
|
||||||
|
|
||||||
attribute.ClassType = classType;
|
|
||||||
if (attribute.Pipeline == ETaskPipeline.AllPipeline || attribute.Pipeline == ETaskPipeline.BuiltinBuildPipeline)
|
|
||||||
attrList.Add(attribute);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
else if (buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||||
{
|
{
|
||||||
new TaskPrepare(), //前期准备工作
|
new TaskPrepare(), //前期准备工作
|
||||||
@@ -114,42 +101,12 @@ namespace YooAsset.Editor
|
|||||||
new TaskCreatePackage(), //制作补丁包
|
new TaskCreatePackage(), //制作补丁包
|
||||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||||
};
|
};
|
||||||
*/
|
return pipeline;
|
||||||
|
|
||||||
var classTypes = EditorTools.GetAssignableTypes(typeof(IBuildTask));
|
|
||||||
foreach (var classType in classTypes)
|
|
||||||
{
|
|
||||||
var attribute = classType.GetCustomAttribute<TaskAttribute>();
|
|
||||||
if (attribute == null)
|
|
||||||
throw new Exception($"Not found {nameof(TaskAttribute)} int type : {classType.FullName}");
|
|
||||||
|
|
||||||
attribute.ClassType = classType;
|
|
||||||
if (attribute.Pipeline == ETaskPipeline.AllPipeline || attribute.Pipeline == ETaskPipeline.ScriptableBuildPipeline)
|
|
||||||
attrList.Add(attribute);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对任务节点进行排序
|
|
||||||
attrList.Sort((a, b) =>
|
|
||||||
{
|
|
||||||
if (a.TaskOrder > b.TaskOrder) { return 1; }
|
|
||||||
else if (a.TaskOrder < b.TaskOrder) { return -1; }
|
|
||||||
else { return 0; }
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建任务节点实例
|
|
||||||
List<IBuildTask> pipeline = new List<IBuildTask>(attrList.Count);
|
|
||||||
foreach (var taskAttr in attrList)
|
|
||||||
{
|
|
||||||
var task = Activator.CreateInstance(taskAttr.ClassType) as IBuildTask;
|
|
||||||
pipeline.Add(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pipeline;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取默认的输出根路录
|
/// 获取默认的输出根路录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetDefaultOutputRoot()
|
public static string GetDefaultBuildOutputRoot()
|
||||||
{
|
{
|
||||||
string projectPath = EditorTools.GetProjectPath();
|
string projectPath = EditorTools.GetProjectPath();
|
||||||
return $"{projectPath}/Bundles";
|
return $"{projectPath}/Bundles";
|
||||||
@@ -20,43 +20,9 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取流文件夹路径
|
/// 获取流文件夹路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetStreamingAssetsFolderPath()
|
public static string GetDefaultStreamingAssetsRoot()
|
||||||
{
|
{
|
||||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.StreamingAssetsBuildinFolder}/";
|
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.DefaultYooFolderName}/";
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 清空流文件夹
|
|
||||||
/// </summary>
|
|
||||||
public static void ClearStreamingAssetsFolder()
|
|
||||||
{
|
|
||||||
string streamingFolderPath = GetStreamingAssetsFolderPath();
|
|
||||||
EditorTools.ClearFolder(streamingFolderPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除流文件夹内无关的文件
|
|
||||||
/// 删除.manifest文件和.meta文件
|
|
||||||
/// </summary>
|
|
||||||
public static void DeleteStreamingAssetsIgnoreFiles()
|
|
||||||
{
|
|
||||||
string streamingFolderPath = GetStreamingAssetsFolderPath();
|
|
||||||
if (Directory.Exists(streamingFolderPath))
|
|
||||||
{
|
|
||||||
string[] files = Directory.GetFiles(streamingFolderPath, "*.manifest", SearchOption.AllDirectories);
|
|
||||||
foreach (var file in files)
|
|
||||||
{
|
|
||||||
FileInfo info = new FileInfo(file);
|
|
||||||
info.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
files = Directory.GetFiles(streamingFolderPath, "*.meta", SearchOption.AllDirectories);
|
|
||||||
foreach (var item in files)
|
|
||||||
{
|
|
||||||
FileInfo info = new FileInfo(item);
|
|
||||||
info.Delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ namespace YooAsset.Editor
|
|||||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.Name).ToList();
|
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.Name).ToList();
|
||||||
|
|
||||||
// 输出目录
|
// 输出目录
|
||||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||||
_buildOutputField = root.Q<TextField>("BuildOutput");
|
_buildOutputField = root.Q<TextField>("BuildOutput");
|
||||||
_buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
|
_buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
|
||||||
_buildOutputField.SetEnabled(false);
|
_buildOutputField.SetEnabled(false);
|
||||||
@@ -266,9 +266,9 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void ExecuteBuild()
|
private void ExecuteBuild()
|
||||||
{
|
{
|
||||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
|
||||||
BuildParameters buildParameters = new BuildParameters();
|
BuildParameters buildParameters = new BuildParameters();
|
||||||
buildParameters.OutputRoot = defaultOutputRoot;
|
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||||
|
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||||
buildParameters.BuildTarget = _buildTarget;
|
buildParameters.BuildTarget = _buildTarget;
|
||||||
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
|
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
|
||||||
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ namespace YooAsset.Editor
|
|||||||
public static string SimulateBuild(string packageName)
|
public static string SimulateBuild(string packageName)
|
||||||
{
|
{
|
||||||
Debug.Log($"Begin to create simulate package : {packageName}");
|
Debug.Log($"Begin to create simulate package : {packageName}");
|
||||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
|
||||||
BuildParameters buildParameters = new BuildParameters();
|
BuildParameters buildParameters = new BuildParameters();
|
||||||
buildParameters.OutputRoot = defaultOutputRoot;
|
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||||
|
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||||
buildParameters.PackageName = packageName;
|
buildParameters.PackageName = packageName;
|
||||||
|
|||||||
@@ -37,9 +37,14 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输出的根目录
|
/// 内置资源的根目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OutputRoot;
|
public string StreamingAssetsRoot;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建输出的根目录
|
||||||
|
/// </summary>
|
||||||
|
public string BuildOutputRoot;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建的平台
|
/// 构建的平台
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
private string _pipelineOutputDirectory = string.Empty;
|
private string _pipelineOutputDirectory = string.Empty;
|
||||||
private string _packageOutputDirectory = string.Empty;
|
private string _packageOutputDirectory = string.Empty;
|
||||||
|
private string _packageRootDirectory = string.Empty;
|
||||||
|
private string _streamingAssetsDirectory = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建参数
|
/// 构建参数
|
||||||
@@ -29,23 +31,47 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
||||||
{
|
{
|
||||||
_pipelineOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
|
_pipelineOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
|
||||||
}
|
}
|
||||||
return _pipelineOutputDirectory;
|
return _pipelineOutputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取本次构建的补丁目录
|
/// 获取本次构建的补丁输出目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetPackageOutputDirectory()
|
public string GetPackageOutputDirectory()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
||||||
{
|
{
|
||||||
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
|
_packageOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
|
||||||
}
|
}
|
||||||
return _packageOutputDirectory;
|
return _packageOutputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本次构建的补丁根目录
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageRootDirectory()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_packageRootDirectory))
|
||||||
|
{
|
||||||
|
_packageRootDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}";
|
||||||
|
}
|
||||||
|
return _packageRootDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取内置资源的目录
|
||||||
|
/// </summary>
|
||||||
|
public string GetStreamingAssetsDirectory()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_streamingAssetsDirectory))
|
||||||
|
{
|
||||||
|
_streamingAssetsDirectory = $"{Parameters.StreamingAssetsRoot}/{Parameters.PackageName}";
|
||||||
|
}
|
||||||
|
return _streamingAssetsDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取内置构建管线的构建选项
|
/// 获取内置构建管线的构建选项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
|
||||||
{
|
|
||||||
public enum ETaskPipeline
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 所有的构建管线
|
|
||||||
/// </summary>
|
|
||||||
AllPipeline,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内置构建管线
|
|
||||||
/// </summary>
|
|
||||||
BuiltinBuildPipeline,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 可编程构建管线
|
|
||||||
/// </summary>
|
|
||||||
ScriptableBuildPipeline,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,28 +5,13 @@ namespace YooAsset.Editor
|
|||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class TaskAttribute : Attribute
|
public class TaskAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 任务所属的构建流水线
|
|
||||||
/// </summary>
|
|
||||||
public ETaskPipeline Pipeline;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行顺序
|
|
||||||
/// </summary>
|
|
||||||
public int TaskOrder;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 任务说明
|
/// 任务说明
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TaskDesc;
|
public string TaskDesc;
|
||||||
|
|
||||||
// 关联的任务类
|
public TaskAttribute(string taskDesc)
|
||||||
public Type ClassType { set; get; }
|
|
||||||
|
|
||||||
public TaskAttribute(ETaskPipeline pipeline, int taskOrder, string taskDesc)
|
|
||||||
{
|
{
|
||||||
Pipeline = pipeline;
|
|
||||||
TaskOrder = taskOrder;
|
|
||||||
TaskDesc = taskDesc;
|
TaskDesc = taskDesc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 300, "资源构建内容打包")]
|
[TaskAttribute("资源构建内容打包")]
|
||||||
public class TaskBuilding : IBuildTask
|
public class TaskBuilding : IBuildTask
|
||||||
{
|
{
|
||||||
public class BuildResultContext : IContextObject
|
public class BuildResultContext : IContextObject
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Tasks;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 300, "资源构建内容打包")]
|
[TaskAttribute("资源构建内容打包")]
|
||||||
public class TaskBuilding_SBP : IBuildTask
|
public class TaskBuilding_SBP : IBuildTask
|
||||||
{
|
{
|
||||||
public class BuildResultContext : IContextObject
|
public class BuildResultContext : IContextObject
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1100, "拷贝内置文件到流目录")]
|
[TaskAttribute("拷贝内置文件到流目录")]
|
||||||
public class TaskCopyBuildinFiles : IBuildTask
|
public class TaskCopyBuildinFiles : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
|
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
|
||||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||||
string streamingAssetsDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
|
string streamingAssetsDirectory = buildParametersContext.GetStreamingAssetsDirectory();
|
||||||
string buildPackageName = buildParametersContext.Parameters.PackageName;
|
string buildPackageName = buildParametersContext.Parameters.PackageName;
|
||||||
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
|
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ namespace YooAsset.Editor
|
|||||||
// 清空流目录
|
// 清空流目录
|
||||||
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
|
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
|
||||||
{
|
{
|
||||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
EditorTools.ClearFolder(streamingAssetsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝补丁清单文件
|
// 拷贝补丁清单文件
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 400, "拷贝原生文件")]
|
[TaskAttribute("拷贝原生文件")]
|
||||||
public class TaskCopyRawFile : IBuildTask
|
public class TaskCopyRawFile : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
|||||||
internal PackageManifest Manifest;
|
internal PackageManifest Manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 800, "创建清单文件")]
|
[TaskAttribute("创建清单文件")]
|
||||||
public class TaskCreateManifest : IBuildTask
|
public class TaskCreateManifest : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1000, "制作包裹")]
|
[TaskAttribute("制作包裹")]
|
||||||
public class TaskCreatePackage : IBuildTask
|
public class TaskCreatePackage : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 900, "创建构建报告文件")]
|
[TaskAttribute("创建构建报告文件")]
|
||||||
public class TaskCreateReport : IBuildTask
|
public class TaskCreateReport : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 600, "资源包加密")]
|
[TaskAttribute("资源包加密")]
|
||||||
public class TaskEncryption : IBuildTask
|
public class TaskEncryption : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 200, "获取资源构建内容")]
|
[TaskAttribute("获取资源构建内容")]
|
||||||
public class TaskGetBuildMap : IBuildTask
|
public class TaskGetBuildMap : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
@@ -147,17 +147,17 @@ namespace YooAsset.Editor
|
|||||||
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
|
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
|
||||||
{
|
{
|
||||||
// 1. 检测是否任何存在依赖资源
|
// 1. 检测是否任何存在依赖资源
|
||||||
bool hasAnyDependAsset = false;
|
bool hasAnyDependCollector = false;
|
||||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||||
{
|
{
|
||||||
var collectorType = collectAssetInfo.CollectorType;
|
var collectorType = collectAssetInfo.CollectorType;
|
||||||
if (collectorType == ECollectorType.DependAssetCollector)
|
if (collectorType == ECollectorType.DependAssetCollector)
|
||||||
{
|
{
|
||||||
hasAnyDependAsset = true;
|
hasAnyDependCollector = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasAnyDependAsset == false)
|
if (hasAnyDependCollector == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 2. 获取所有主资源的依赖资源集合
|
// 2. 获取所有主资源的依赖资源集合
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 100, "资源构建准备工作")]
|
[TaskAttribute("资源构建准备工作")]
|
||||||
public class TaskPrepare : IBuildTask
|
public class TaskPrepare : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
@@ -16,11 +16,27 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// 检测构建参数合法性
|
// 检测构建参数合法性
|
||||||
if (buildParameters.BuildTarget == BuildTarget.NoTarget)
|
if (buildParameters.BuildTarget == BuildTarget.NoTarget)
|
||||||
throw new Exception("请选择目标平台");
|
throw new Exception("请选择目标平台!");
|
||||||
if (string.IsNullOrEmpty(buildParameters.PackageName))
|
if (string.IsNullOrEmpty(buildParameters.PackageName))
|
||||||
throw new Exception("包裹名称不能为空");
|
throw new Exception("包裹名称不能为空!");
|
||||||
if (string.IsNullOrEmpty(buildParameters.PackageVersion))
|
if (string.IsNullOrEmpty(buildParameters.PackageVersion))
|
||||||
throw new Exception("包裹版本不能为空");
|
throw new Exception("包裹版本不能为空!");
|
||||||
|
if (string.IsNullOrEmpty(buildParameters.BuildOutputRoot))
|
||||||
|
throw new Exception("构建输出的根目录为空!");
|
||||||
|
if (string.IsNullOrEmpty(buildParameters.StreamingAssetsRoot))
|
||||||
|
throw new Exception("内置资源根目录为空!");
|
||||||
|
|
||||||
|
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
|
{
|
||||||
|
if (buildParameters.SBPParameters == null)
|
||||||
|
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
|
||||||
|
|
||||||
|
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
|
||||||
|
|
||||||
|
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
|
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
|
||||||
|
}
|
||||||
|
|
||||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||||
{
|
{
|
||||||
@@ -72,11 +88,10 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
{
|
{
|
||||||
// 删除总目录
|
string packageRootDirectory = buildParametersContext.GetPackageRootDirectory();
|
||||||
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.PackageName}";
|
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
|
||||||
{
|
{
|
||||||
BuildLogger.Log($"删除平台总目录:{platformDirectory}");
|
BuildLogger.Log($"删除包裹目录:{packageRootDirectory}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.AllPipeline, 700, "更新资源包信息")]
|
[TaskAttribute("更新资源包信息")]
|
||||||
public class TaskUpdateBundleInfo : IBuildTask
|
public class TaskUpdateBundleInfo : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 500, "验证构建结果")]
|
[TaskAttribute("验证构建结果")]
|
||||||
public class TaskVerifyBuildResult : IBuildTask
|
public class TaskVerifyBuildResult : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Interfaces;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 500, "验证构建结果")]
|
[TaskAttribute("验证构建结果")]
|
||||||
public class TaskVerifyBuildResult_SBP : IBuildTask
|
public class TaskVerifyBuildResult_SBP : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
|||||||
@@ -79,30 +79,6 @@ namespace YooAsset
|
|||||||
_isUnloadSafe = true;
|
_isUnloadSafe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 销毁
|
|
||||||
/// </summary>
|
|
||||||
public void DestroyAll()
|
|
||||||
{
|
|
||||||
foreach (var provider in _providerList)
|
|
||||||
{
|
|
||||||
provider.Destroy();
|
|
||||||
}
|
|
||||||
_providerList.Clear();
|
|
||||||
_providerDic.Clear();
|
|
||||||
|
|
||||||
foreach (var loader in _loaderList)
|
|
||||||
{
|
|
||||||
loader.Destroy(true);
|
|
||||||
}
|
|
||||||
_loaderList.Clear();
|
|
||||||
_loaderDic.Clear();
|
|
||||||
|
|
||||||
ClearSceneHandle();
|
|
||||||
DecryptionServices = null;
|
|
||||||
BundleServices = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源回收(卸载引用计数为零的资源)
|
/// 资源回收(卸载引用计数为零的资源)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -149,10 +125,12 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
foreach (var provider in _providerList)
|
foreach (var provider in _providerList)
|
||||||
{
|
{
|
||||||
|
provider.WaitForAsyncComplete();
|
||||||
provider.Destroy();
|
provider.Destroy();
|
||||||
}
|
}
|
||||||
foreach (var loader in _loaderList)
|
foreach (var loader in _loaderList)
|
||||||
{
|
{
|
||||||
|
loader.WaitForAsyncComplete();
|
||||||
loader.Destroy(true);
|
loader.Destroy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,9 +73,7 @@ namespace YooAsset
|
|||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return null;
|
return null;
|
||||||
string filePath = Provider.RawFilePath;
|
string filePath = Provider.RawFilePath;
|
||||||
if (File.Exists(filePath) == false)
|
return FileUtility.ReadAllBytes(filePath);
|
||||||
return null;
|
|
||||||
return File.ReadAllBytes(filePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -168,8 +168,17 @@ namespace YooAsset
|
|||||||
// 5. 从WEB网站获取AssetBundle文件
|
// 5. 从WEB网站获取AssetBundle文件
|
||||||
if (_steps == ESteps.LoadWebFile)
|
if (_steps == ESteps.LoadWebFile)
|
||||||
{
|
{
|
||||||
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
|
if (CacheSystem.DisableUnityCacheOnWebGL)
|
||||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
|
{
|
||||||
|
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
|
||||||
|
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadSystem.SetUnityWebRequest(_webRequest);
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
_steps = ESteps.CheckLoadWebFile;
|
_steps = ESteps.CheckLoadWebFile;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ namespace YooAsset
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OwnerBundle.CacheBundle == null)
|
||||||
|
{
|
||||||
|
ProcessCacheBundleException();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Status = EStatus.Loading;
|
Status = EStatus.Loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,12 +55,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (OwnerBundle.CacheBundle == null)
|
if (OwnerBundle.CacheBundle == null)
|
||||||
{
|
{
|
||||||
if (OwnerBundle.IsDestroyed)
|
ProcessCacheBundleException();
|
||||||
throw new System.Exception("Should never get here !");
|
|
||||||
Status = EStatus.Failed;
|
|
||||||
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
|
||||||
YooLogger.Error(LastError);
|
|
||||||
InvokeCompletion();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ namespace YooAsset
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OwnerBundle.CacheBundle == null)
|
||||||
|
{
|
||||||
|
ProcessCacheBundleException();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Status = EStatus.Loading;
|
Status = EStatus.Loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,30 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理特殊异常
|
||||||
|
/// </summary>
|
||||||
|
protected void ProcessCacheBundleException()
|
||||||
|
{
|
||||||
|
if (OwnerBundle.IsDestroyed)
|
||||||
|
throw new System.Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (OwnerBundle.MainBundleInfo.Bundle.IsRawFile)
|
||||||
|
{
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
LastError = $"Cannot load asset bundle file using {nameof(ResourcePackage.LoadRawFileAsync)} method !";
|
||||||
|
YooLogger.Error(LastError);
|
||||||
|
InvokeCompletion();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Status = EStatus.Failed;
|
||||||
|
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
||||||
|
YooLogger.Error(LastError);
|
||||||
|
InvokeCompletion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步操作任务
|
/// 异步操作任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
private readonly static Dictionary<string, PackageCache> _cachedDic = new Dictionary<string, PackageCache>(1000);
|
private readonly static Dictionary<string, PackageCache> _cachedDic = new Dictionary<string, PackageCache>(1000);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 禁用Unity缓存系统在WebGL平台
|
||||||
|
/// </summary>
|
||||||
|
public static bool DisableUnityCacheOnWebGL = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化时的验证级别
|
/// 初始化时的验证级别
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
// BundleFiles
|
// BundleFiles
|
||||||
{
|
{
|
||||||
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
|
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheBundleFilesRoot;
|
||||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||||
if (rootDirectory.Exists)
|
if (rootDirectory.Exists)
|
||||||
{
|
{
|
||||||
@@ -56,7 +56,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// RawFiles
|
// RawFiles
|
||||||
{
|
{
|
||||||
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
|
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheRawFilesRoot;
|
||||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||||
if (rootDirectory.Exists)
|
if (rootDirectory.Exists)
|
||||||
{
|
{
|
||||||
|
|||||||
163
Assets/YooAsset/Runtime/CacheSystem/Persistent.cs
Normal file
163
Assets/YooAsset/Runtime/CacheSystem/Persistent.cs
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class Persistent
|
||||||
|
{
|
||||||
|
private readonly string _packageName;
|
||||||
|
|
||||||
|
public string BuildinRoot { private set; get; }
|
||||||
|
public string BuildinPackageRoot { private set; get; }
|
||||||
|
|
||||||
|
public string SandboxRoot { private set; get; }
|
||||||
|
public string SandboxPackageRoot { private set; get; }
|
||||||
|
public string SandboxCacheBundleFilesRoot { private set; get; }
|
||||||
|
public string SandboxCacheRawFilesRoot { private set; get; }
|
||||||
|
public string SandboxManifestFilesRoot { private set; get; }
|
||||||
|
public string SandboxAppFootPrintFilePath { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public Persistent(string packageName)
|
||||||
|
{
|
||||||
|
_packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重写根路径
|
||||||
|
/// </summary>
|
||||||
|
public void OverwriteRootDirectory(string buildinRoot, string sandboxRoot)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(buildinRoot))
|
||||||
|
BuildinRoot = CreateDefaultBuildinRoot();
|
||||||
|
else
|
||||||
|
BuildinRoot = buildinRoot;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(sandboxRoot))
|
||||||
|
SandboxRoot = CreateDefaultSandboxRoot();
|
||||||
|
else
|
||||||
|
SandboxRoot = sandboxRoot;
|
||||||
|
|
||||||
|
BuildinPackageRoot = PathUtility.Combine(BuildinRoot, _packageName);
|
||||||
|
SandboxPackageRoot = PathUtility.Combine(SandboxRoot, _packageName);
|
||||||
|
SandboxCacheBundleFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedBundleFileFolder);
|
||||||
|
SandboxCacheRawFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CachedRawFileFolder);
|
||||||
|
SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
|
||||||
|
SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
|
||||||
|
}
|
||||||
|
private static string CreateDefaultBuildinRoot()
|
||||||
|
{
|
||||||
|
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName);
|
||||||
|
}
|
||||||
|
private static string CreateDefaultSandboxRoot()
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
|
||||||
|
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||||
|
projectPath = PathUtility.RegularPath(projectPath);
|
||||||
|
return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName);
|
||||||
|
#elif UNITY_STANDALONE
|
||||||
|
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName);
|
||||||
|
#else
|
||||||
|
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除沙盒里的包裹目录
|
||||||
|
/// </summary>
|
||||||
|
public void DeleteSandboxPackageFolder()
|
||||||
|
{
|
||||||
|
if (Directory.Exists(SandboxPackageRoot))
|
||||||
|
Directory.Delete(SandboxPackageRoot, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除沙盒内的缓存文件夹
|
||||||
|
/// </summary>
|
||||||
|
public void DeleteSandboxCacheFilesFolder()
|
||||||
|
{
|
||||||
|
// CacheBundleFiles
|
||||||
|
if (Directory.Exists(SandboxCacheBundleFilesRoot))
|
||||||
|
Directory.Delete(SandboxCacheBundleFilesRoot, true);
|
||||||
|
|
||||||
|
// CacheRawFiles
|
||||||
|
if (Directory.Exists(SandboxCacheRawFilesRoot))
|
||||||
|
Directory.Delete(SandboxCacheRawFilesRoot, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除沙盒内的清单文件夹
|
||||||
|
/// </summary>
|
||||||
|
public void DeleteSandboxManifestFilesFolder()
|
||||||
|
{
|
||||||
|
if (Directory.Exists(SandboxManifestFilesRoot))
|
||||||
|
Directory.Delete(SandboxManifestFilesRoot, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取沙盒内包裹的清单文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetSandboxPackageManifestFilePath(string packageVersion)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
|
||||||
|
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取沙盒内包裹的哈希文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetSandboxPackageHashFilePath(string packageVersion)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
|
||||||
|
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取沙盒内包裹的版本文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetSandboxPackageVersionFilePath()
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||||
|
return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存沙盒内默认的包裹版本
|
||||||
|
/// </summary>
|
||||||
|
public void SaveSandboxPackageVersionFile(string version)
|
||||||
|
{
|
||||||
|
string filePath = GetSandboxPackageVersionFilePath();
|
||||||
|
FileUtility.WriteAllText(filePath, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取APP内包裹的清单文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetBuildinPackageManifestFilePath(string packageVersion)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, packageVersion);
|
||||||
|
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取APP内包裹的哈希文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetBuildinPackageHashFilePath(string packageVersion)
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, packageVersion);
|
||||||
|
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取APP内包裹的版本文件的路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetBuildinPackageVersionFilePath()
|
||||||
|
{
|
||||||
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||||
|
return PathUtility.Combine(BuildinPackageRoot, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 32477ef3a448a9144aa1574a052fe54e
|
guid: 62ee5fd2821fe85488efff3f8242b703
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -3,84 +3,31 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal static class PersistentTools
|
internal class PersistentTools
|
||||||
{
|
{
|
||||||
private const string SandboxFolderName = "Sandbox";
|
private static readonly Dictionary<string, Persistent> _persitentDic = new Dictionary<string, Persistent>(100);
|
||||||
private const string CacheFolderName = "CacheFiles";
|
|
||||||
private const string CachedBundleFileFolder = "BundleFiles";
|
|
||||||
private const string CachedRawFileFolder = "RawFiles";
|
|
||||||
private const string ManifestFolderName = "ManifestFiles";
|
|
||||||
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
|
|
||||||
|
|
||||||
private static string _buildinPath;
|
|
||||||
private static string _sandboxPath;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 重写沙盒跟路径
|
/// 获取包裹的持久化类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void OverwriteSandboxPath(string sandboxPath)
|
public static Persistent GetPersistent(string packageName)
|
||||||
{
|
{
|
||||||
_sandboxPath = sandboxPath;
|
if (_persitentDic.ContainsKey(packageName) == false)
|
||||||
|
throw new System.Exception("Should never get here !");
|
||||||
|
return _persitentDic[packageName];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取沙盒文件夹路径
|
/// 获取或创建包裹的持久化类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetPersistentRootPath()
|
public static Persistent GetOrCreatePersistent(string packageName)
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
if (_persitentDic.ContainsKey(packageName) == false)
|
||||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
|
||||||
if (string.IsNullOrEmpty(_sandboxPath))
|
|
||||||
{
|
{
|
||||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
Persistent persistent = new Persistent(packageName);
|
||||||
projectPath = PathUtility.RegularPath(projectPath);
|
_persitentDic.Add(packageName, persistent);
|
||||||
_sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName);
|
|
||||||
}
|
}
|
||||||
#elif UNITY_STANDALONE
|
return _persitentDic[packageName];
|
||||||
if (string.IsNullOrEmpty(_sandboxPath))
|
|
||||||
{
|
|
||||||
_sandboxPath = PathUtility.Combine(UnityEngine.Application.dataPath, SandboxFolderName);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (string.IsNullOrEmpty(_sandboxPath))
|
|
||||||
{
|
|
||||||
_sandboxPath = PathUtility.Combine(UnityEngine.Application.persistentDataPath, SandboxFolderName);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return _sandboxPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取基于流文件夹的加载路径
|
|
||||||
/// </summary>
|
|
||||||
public static string MakeStreamingLoadPath(string path)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(_buildinPath))
|
|
||||||
{
|
|
||||||
_buildinPath = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder);
|
|
||||||
}
|
|
||||||
return PathUtility.Combine(_buildinPath, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取基于沙盒文件夹的加载路径
|
|
||||||
/// </summary>
|
|
||||||
public static string MakePersistentLoadPath(string path)
|
|
||||||
{
|
|
||||||
string root = GetPersistentRootPath();
|
|
||||||
return PathUtility.Combine(root, path);
|
|
||||||
}
|
|
||||||
public static string MakePersistentLoadPath(string path1, string path2)
|
|
||||||
{
|
|
||||||
string root = GetPersistentRootPath();
|
|
||||||
return PathUtility.Combine(root, path1, path2);
|
|
||||||
}
|
|
||||||
public static string MakePersistentLoadPath(string path1, string path2, string path3)
|
|
||||||
{
|
|
||||||
string root = GetPersistentRootPath();
|
|
||||||
return PathUtility.Combine(root, path1, path2, path3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -100,109 +47,5 @@ namespace YooAsset
|
|||||||
return path;
|
return path;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除沙盒总目录
|
|
||||||
/// </summary>
|
|
||||||
public static void DeleteSandbox()
|
|
||||||
{
|
|
||||||
string directoryPath = GetPersistentRootPath();
|
|
||||||
if (Directory.Exists(directoryPath))
|
|
||||||
Directory.Delete(directoryPath, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除沙盒内的缓存文件夹
|
|
||||||
/// </summary>
|
|
||||||
public static void DeleteCacheFolder()
|
|
||||||
{
|
|
||||||
string root = MakePersistentLoadPath(CacheFolderName);
|
|
||||||
if (Directory.Exists(root))
|
|
||||||
Directory.Delete(root, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除沙盒内的清单文件夹
|
|
||||||
/// </summary>
|
|
||||||
public static void DeleteManifestFolder()
|
|
||||||
{
|
|
||||||
string root = MakePersistentLoadPath(ManifestFolderName);
|
|
||||||
if (Directory.Exists(root))
|
|
||||||
Directory.Delete(root, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取缓存的BundleFile文件夹路径
|
|
||||||
/// </summary>
|
|
||||||
private readonly static Dictionary<string, string> _cachedBundleFileFolder = new Dictionary<string, string>(100);
|
|
||||||
public static string GetCachedBundleFileFolderPath(string packageName)
|
|
||||||
{
|
|
||||||
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
|
|
||||||
{
|
|
||||||
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedBundleFileFolder);
|
|
||||||
_cachedBundleFileFolder.Add(packageName, value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取缓存的RawFile文件夹路径
|
|
||||||
/// </summary>
|
|
||||||
private readonly static Dictionary<string, string> _cachedRawFileFolder = new Dictionary<string, string>(100);
|
|
||||||
public static string GetCachedRawFileFolderPath(string packageName)
|
|
||||||
{
|
|
||||||
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
|
|
||||||
{
|
|
||||||
value = MakePersistentLoadPath(CacheFolderName, packageName, CachedRawFileFolder);
|
|
||||||
_cachedRawFileFolder.Add(packageName, value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取应用程序的水印文件路径
|
|
||||||
/// </summary>
|
|
||||||
public static string GetAppFootPrintFilePath()
|
|
||||||
{
|
|
||||||
return MakePersistentLoadPath(AppFootPrintFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取沙盒内清单文件的路径
|
|
||||||
/// </summary>
|
|
||||||
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
|
|
||||||
{
|
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
|
||||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取沙盒内包裹的哈希文件的路径
|
|
||||||
/// </summary>
|
|
||||||
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
|
|
||||||
{
|
|
||||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
|
||||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取沙盒内包裹的版本文件的路径
|
|
||||||
/// </summary>
|
|
||||||
public static string GetCachePackageVersionFilePath(string packageName)
|
|
||||||
{
|
|
||||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
|
||||||
return MakePersistentLoadPath(ManifestFolderName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 保存默认的包裹版本
|
|
||||||
/// </summary>
|
|
||||||
public static void SaveCachePackageVersionFile(string packageName, string version)
|
|
||||||
{
|
|
||||||
string filePath = GetCachePackageVersionFilePath(packageName);
|
|
||||||
FileUtility.WriteAllText(filePath, version);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,11 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static CertificateHandler CertificateHandlerInstance = null;
|
public static CertificateHandler CertificateHandlerInstance = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 网络重定向次数
|
||||||
|
/// </summary>
|
||||||
|
public static int RedirectLimit { set; get; } = -1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启用断点续传功能文件的最小字节数
|
/// 启用断点续传功能文件的最小字节数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -128,11 +133,29 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static UnityWebRequest NewRequest(string requestURL)
|
public static UnityWebRequest NewRequest(string requestURL)
|
||||||
{
|
{
|
||||||
|
UnityWebRequest webRequest;
|
||||||
if (RequestDelegate != null)
|
if (RequestDelegate != null)
|
||||||
return RequestDelegate.Invoke(requestURL);
|
webRequest = RequestDelegate.Invoke(requestURL);
|
||||||
|
else
|
||||||
|
webRequest = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
|
||||||
|
|
||||||
var request = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
|
SetUnityWebRequest(webRequest);
|
||||||
return request;
|
return webRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置网络请求的自定义参数
|
||||||
|
/// </summary>
|
||||||
|
public static void SetUnityWebRequest(UnityWebRequest webRequest)
|
||||||
|
{
|
||||||
|
if (RedirectLimit >= 0)
|
||||||
|
webRequest.redirectLimit = RedirectLimit;
|
||||||
|
|
||||||
|
if (CertificateHandlerInstance != null)
|
||||||
|
{
|
||||||
|
webRequest.certificateHandler = CertificateHandlerInstance;
|
||||||
|
webRequest.disposeCertificateHandlerOnDispose = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -101,13 +101,6 @@ namespace YooAsset
|
|||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
|
||||||
if (DownloadSystem.CertificateHandlerInstance != null)
|
|
||||||
{
|
|
||||||
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
|
||||||
_webRequest.disposeCertificateHandlerOnDispose = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
_steps = ESteps.CheckDownload;
|
_steps = ESteps.CheckDownload;
|
||||||
}
|
}
|
||||||
@@ -137,13 +130,6 @@ namespace YooAsset
|
|||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
if (fileLength > 0)
|
if (fileLength > 0)
|
||||||
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
|
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
|
||||||
|
|
||||||
if (DownloadSystem.CertificateHandlerInstance != null)
|
|
||||||
{
|
|
||||||
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
|
||||||
_webRequest.disposeCertificateHandlerOnDispose = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
_steps = ESteps.CheckDownload;
|
_steps = ESteps.CheckDownload;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,18 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IDecryptionServices DecryptionServices = null;
|
public IDecryptionServices DecryptionServices = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置文件的根路径
|
||||||
|
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||||
|
/// </summary>
|
||||||
|
public string BuildinRootDirectory = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 沙盒文件的根路径
|
||||||
|
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||||
|
/// </summary>
|
||||||
|
public string SandboxRootDirectory = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源加载每帧处理的最大时间片段
|
/// 资源加载每帧处理的最大时间片段
|
||||||
/// 注意:默认值为MaxValue
|
/// 注意:默认值为MaxValue
|
||||||
@@ -68,19 +80,14 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class HostPlayModeParameters : InitializeParameters
|
public class HostPlayModeParameters : InitializeParameters
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 默认的资源服务器下载地址
|
|
||||||
/// </summary>
|
|
||||||
public string DefaultHostServer = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 备用的资源服务器下载地址
|
|
||||||
/// </summary>
|
|
||||||
public string FallbackHostServer = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置资源查询服务接口
|
/// 内置资源查询服务接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IQueryServices QueryServices = null;
|
public IQueryServices QueryServices = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 远端资源地址查询服务类
|
||||||
|
/// </summary>
|
||||||
|
public IRemoteServices RemoteServices = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,13 +217,13 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.CheckAppFootPrint)
|
if (_steps == ESteps.CheckAppFootPrint)
|
||||||
{
|
{
|
||||||
var appFootPrint = new AppFootPrint();
|
var appFootPrint = new AppFootPrint();
|
||||||
appFootPrint.Load();
|
appFootPrint.Load(_packageName);
|
||||||
|
|
||||||
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
||||||
if (appFootPrint.IsDirty())
|
if (appFootPrint.IsDirty())
|
||||||
{
|
{
|
||||||
PersistentTools.DeleteManifestFolder();
|
PersistentTools.GetPersistent(_packageName).DeleteSandboxManifestFilesFolder();
|
||||||
appFootPrint.Coverage();
|
appFootPrint.Coverage(_packageName);
|
||||||
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
||||||
}
|
}
|
||||||
_steps = ESteps.QueryCachePackageVersion;
|
_steps = ESteps.QueryCachePackageVersion;
|
||||||
@@ -374,16 +374,16 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取应用程序水印
|
/// 读取应用程序水印
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Load()
|
public void Load(string packageName)
|
||||||
{
|
{
|
||||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
|
||||||
if (File.Exists(footPrintFilePath))
|
if (File.Exists(footPrintFilePath))
|
||||||
{
|
{
|
||||||
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Coverage();
|
Coverage(packageName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,14 +402,14 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 覆盖掉水印
|
/// 覆盖掉水印
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Coverage()
|
public void Coverage(string packageName)
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
_footPrint = Application.version;
|
_footPrint = Application.version;
|
||||||
#else
|
#else
|
||||||
_footPrint = Application.buildGUID;
|
_footPrint = Application.buildGUID;
|
||||||
#endif
|
#endif
|
||||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
|
||||||
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
|
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
|
||||||
YooLogger.Log($"Save application foot print : {_footPrint}");
|
YooLogger.Log($"Save application foot print : {_footPrint}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloader1 == null)
|
if (_downloader1 == null)
|
||||||
{
|
{
|
||||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||||
string webURL = GetDownloadRequestURL(fileName);
|
string webURL = GetDownloadRequestURL(fileName);
|
||||||
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
||||||
@@ -71,7 +71,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloader2 == null)
|
if (_downloader2 == null)
|
||||||
{
|
{
|
||||||
string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||||
string webURL = GetDownloadRequestURL(fileName);
|
string webURL = GetDownloadRequestURL(fileName);
|
||||||
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloader == null)
|
if (_downloader == null)
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
string filePath = PersistentTools.GetPersistent(_buildinPackageName).GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
|
||||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||||
_downloader = new UnityWebDataRequester();
|
_downloader = new UnityWebDataRequester();
|
||||||
_downloader.SendRequest(url);
|
_downloader.SendRequest(url);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.VerifyFileHash)
|
if (_steps == ESteps.VerifyFileHash)
|
||||||
{
|
{
|
||||||
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
_manifestFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
|
||||||
if (File.Exists(_manifestFilePath) == false)
|
if (File.Exists(_manifestFilePath) == false)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
@@ -131,7 +131,7 @@ namespace YooAsset
|
|||||||
File.Delete(_manifestFilePath);
|
File.Delete(_manifestFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
string hashFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||||
if (File.Exists(hashFilePath))
|
if (File.Exists(hashFilePath))
|
||||||
{
|
{
|
||||||
File.Delete(hashFilePath);
|
File.Delete(hashFilePath);
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloader == null)
|
if (_downloader == null)
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
string filePath = PersistentTools.GetPersistent(_packageName).GetBuildinPackageVersionFilePath();
|
||||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
|
||||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||||
_downloader = new UnityWebDataRequester();
|
_downloader = new UnityWebDataRequester();
|
||||||
_downloader.SendRequest(url);
|
_downloader.SendRequest(url);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.LoadCachePackageHashFile)
|
if (_steps == ESteps.LoadCachePackageHashFile)
|
||||||
{
|
{
|
||||||
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||||
if (File.Exists(filePath) == false)
|
if (File.Exists(filePath) == false)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.LoadCachePackageVersionFile)
|
if (_steps == ESteps.LoadCachePackageVersionFile)
|
||||||
{
|
{
|
||||||
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
|
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageVersionFilePath();
|
||||||
if (File.Exists(filePath) == false)
|
if (File.Exists(filePath) == false)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(_steps == ESteps.UnpackManifestHashFile)
|
if (_steps == ESteps.UnpackManifestHashFile)
|
||||||
{
|
{
|
||||||
if (_downloader1 == null)
|
if (_downloader1 == null)
|
||||||
{
|
{
|
||||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
|
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
|
||||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
|
string savePath = persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
|
||||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
string filePath = persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||||
_downloader1 = new UnityWebFileRequester();
|
_downloader1 = new UnityWebFileRequester();
|
||||||
_downloader1.SendRequest(url, savePath);
|
_downloader1.SendRequest(url, savePath);
|
||||||
@@ -64,9 +64,9 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloader2 == null)
|
if (_downloader2 == null)
|
||||||
{
|
{
|
||||||
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
|
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
string savePath = persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
|
||||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
string filePath = persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||||
_downloader2 = new UnityWebFileRequester();
|
_downloader2 = new UnityWebFileRequester();
|
||||||
_downloader2.SendRequest(url, savePath);
|
_downloader2.SendRequest(url, savePath);
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloadManifestOp == null)
|
if (_downloadManifestOp == null)
|
||||||
{
|
{
|
||||||
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
_downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
|
||||||
OperationSystem.StartOperation(_downloadManifestOp);
|
OperationSystem.StartOperation(_downloadManifestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloadManifestOp == null)
|
if (_downloadManifestOp == null)
|
||||||
{
|
{
|
||||||
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout);
|
_downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
|
||||||
OperationSystem.StartOperation(_downloadManifestOp);
|
OperationSystem.StartOperation(_downloadManifestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_queryRemotePackageVersionOp == null)
|
if (_queryRemotePackageVersionOp == null)
|
||||||
{
|
{
|
||||||
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout);
|
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _packageName, _appendTimeTicks, _timeout);
|
||||||
OperationSystem.StartOperation(_queryRemotePackageVersionOp);
|
OperationSystem.StartOperation(_queryRemotePackageVersionOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ namespace YooAsset
|
|||||||
string folderName = FileHash.Substring(0, 2);
|
string folderName = FileHash.Substring(0, 2);
|
||||||
if (IsRawFile)
|
if (IsRawFile)
|
||||||
{
|
{
|
||||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
|
||||||
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||||
_cachedDataFilePath += _fileExtension;
|
_cachedDataFilePath += _fileExtension;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
|
||||||
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||||
}
|
}
|
||||||
return _cachedDataFilePath;
|
return _cachedDataFilePath;
|
||||||
@@ -101,12 +101,12 @@ namespace YooAsset
|
|||||||
string folderName = FileHash.Substring(0, 2);
|
string folderName = FileHash.Substring(0, 2);
|
||||||
if (IsRawFile)
|
if (IsRawFile)
|
||||||
{
|
{
|
||||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
|
||||||
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
|
||||||
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||||
}
|
}
|
||||||
return _cachedInfoFilePath;
|
return _cachedInfoFilePath;
|
||||||
@@ -140,7 +140,8 @@ namespace YooAsset
|
|||||||
if (string.IsNullOrEmpty(_streamingFilePath) == false)
|
if (string.IsNullOrEmpty(_streamingFilePath) == false)
|
||||||
return _streamingFilePath;
|
return _streamingFilePath;
|
||||||
|
|
||||||
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
|
string root = PersistentTools.GetPersistent(PackageName).BuildinPackageRoot;
|
||||||
|
_streamingFilePath = PathUtility.Combine(root, FileName);
|
||||||
return _streamingFilePath;
|
return _streamingFilePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,25 +4,28 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices
|
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices
|
||||||
{
|
{
|
||||||
private PackageManifest _activeManifest;
|
private PackageManifest _activeManifest;
|
||||||
|
|
||||||
// 参数相关
|
// 参数相关
|
||||||
private string _packageName;
|
private string _packageName;
|
||||||
private string _defaultHostServer;
|
|
||||||
private string _fallbackHostServer;
|
|
||||||
private IQueryServices _queryServices;
|
private IQueryServices _queryServices;
|
||||||
|
private IRemoteServices _remoteServices;
|
||||||
|
|
||||||
|
public IRemoteServices RemoteServices
|
||||||
|
{
|
||||||
|
get { return _remoteServices; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public InitializationOperation InitializeAsync(string packageName, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices)
|
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices)
|
||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_defaultHostServer = defaultHostServer;
|
|
||||||
_fallbackHostServer = fallbackHostServer;
|
|
||||||
_queryServices = queryServices;
|
_queryServices = queryServices;
|
||||||
|
_remoteServices = remoteServices;
|
||||||
|
|
||||||
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
||||||
OperationSystem.StartOperation(operation);
|
OperationSystem.StartOperation(operation);
|
||||||
@@ -42,23 +45,12 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||||
{
|
{
|
||||||
string remoteMainURL = GetRemoteMainURL(packageBundle.FileName);
|
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||||
string remoteFallbackURL = GetRemoteFallbackURL(packageBundle.FileName);
|
string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
|
||||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IRemoteServices接口
|
|
||||||
public string GetRemoteMainURL(string fileName)
|
|
||||||
{
|
|
||||||
return $"{_defaultHostServer}/{fileName}";
|
|
||||||
}
|
|
||||||
public string GetRemoteFallbackURL(string fileName)
|
|
||||||
{
|
|
||||||
return $"{_fallbackHostServer}/{fileName}";
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IPlayModeServices接口
|
#region IPlayModeServices接口
|
||||||
public PackageManifest ActiveManifest
|
public PackageManifest ActiveManifest
|
||||||
{
|
{
|
||||||
@@ -74,12 +66,14 @@ namespace YooAsset
|
|||||||
public void FlushManifestVersionFile()
|
public void FlushManifestVersionFile()
|
||||||
{
|
{
|
||||||
if (_activeManifest != null)
|
if (_activeManifest != null)
|
||||||
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
|
{
|
||||||
|
PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||||
{
|
{
|
||||||
return _queryServices.QueryStreamingAssets(packageBundle.FileName);
|
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||||
}
|
}
|
||||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_assetSystemImpl != null)
|
if (_assetSystemImpl != null)
|
||||||
{
|
{
|
||||||
_assetSystemImpl.DestroyAll();
|
_assetSystemImpl.ForceUnloadAllAssets();
|
||||||
_assetSystemImpl = null;
|
_assetSystemImpl = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,10 @@ namespace YooAsset
|
|||||||
// 检测初始化参数合法性
|
// 检测初始化参数合法性
|
||||||
CheckInitializeParameters(parameters);
|
CheckInitializeParameters(parameters);
|
||||||
|
|
||||||
|
// 重写持久化根目录
|
||||||
|
var persistent = PersistentTools.GetOrCreatePersistent(PackageName);
|
||||||
|
persistent.OverwriteRootDirectory(parameters.BuildinRootDirectory, parameters.SandboxRootDirectory);
|
||||||
|
|
||||||
// 初始化资源系统
|
// 初始化资源系统
|
||||||
InitializationOperation initializeOperation;
|
InitializationOperation initializeOperation;
|
||||||
_assetSystemImpl = new AssetSystemImpl();
|
_assetSystemImpl = new AssetSystemImpl();
|
||||||
@@ -118,9 +122,8 @@ namespace YooAsset
|
|||||||
var initializeParameters = parameters as HostPlayModeParameters;
|
var initializeParameters = parameters as HostPlayModeParameters;
|
||||||
initializeOperation = hostPlayModeImpl.InitializeAsync(
|
initializeOperation = hostPlayModeImpl.InitializeAsync(
|
||||||
PackageName,
|
PackageName,
|
||||||
initializeParameters.DefaultHostServer,
|
initializeParameters.QueryServices,
|
||||||
initializeParameters.FallbackHostServer,
|
initializeParameters.RemoteServices
|
||||||
initializeParameters.QueryServices
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -168,12 +171,10 @@ namespace YooAsset
|
|||||||
if (parameters is HostPlayModeParameters)
|
if (parameters is HostPlayModeParameters)
|
||||||
{
|
{
|
||||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||||
if (string.IsNullOrEmpty(hostPlayModeParameters.DefaultHostServer))
|
|
||||||
throw new Exception($"${hostPlayModeParameters.DefaultHostServer} is null or empty.");
|
|
||||||
if (string.IsNullOrEmpty(hostPlayModeParameters.FallbackHostServer))
|
|
||||||
throw new Exception($"${hostPlayModeParameters.FallbackHostServer} is null or empty.");
|
|
||||||
if (hostPlayModeParameters.QueryServices == null)
|
if (hostPlayModeParameters.QueryServices == null)
|
||||||
throw new Exception($"{nameof(IQueryServices)} is null.");
|
throw new Exception($"{nameof(IQueryServices)} is null.");
|
||||||
|
if (hostPlayModeParameters.RemoteServices == null)
|
||||||
|
throw new Exception($"{nameof(IRemoteServices)} is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 鉴定运行模式
|
// 鉴定运行模式
|
||||||
@@ -291,6 +292,37 @@ namespace YooAsset
|
|||||||
_assetSystemImpl.ForceUnloadAllAssets();
|
_assetSystemImpl.ForceUnloadAllAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 沙盒相关
|
||||||
|
/// <summary>
|
||||||
|
/// 获取包裹的内置文件根路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageBuildinRootDirectory()
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||||
|
return persistent.BuildinRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取包裹的沙盒文件根路径
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageSandboxRootDirectory()
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||||
|
return persistent.SandboxRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清空包裹的沙盒目录
|
||||||
|
/// </summary>
|
||||||
|
public void ClearPackageSandbox()
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||||
|
persistent.DeleteSandboxPackageFolder();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 资源信息
|
#region 资源信息
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询内置资源
|
/// 查询内置资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool QueryStreamingAssets(string fileName);
|
bool QueryStreamingAssets(string packageName, string fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal interface IRemoteServices
|
public interface IRemoteServices
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取主资源站的资源地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">请求的文件名称</param>
|
||||||
string GetRemoteMainURL(string fileName);
|
string GetRemoteMainURL(string fileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取备用资源站的资源地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">请求的文件名称</param>
|
||||||
string GetRemoteFallbackURL(string fileName);
|
string GetRemoteFallbackURL(string fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,31 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string CacheBundleInfoFileName = "__info";
|
public const string CacheBundleInfoFileName = "__info";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认的YooAsset文件夹名称
|
||||||
|
/// </summary>
|
||||||
|
public const string DefaultYooFolderName = "yoo";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 缓存的资源文件的文件夹名称
|
||||||
|
/// </summary>
|
||||||
|
public const string CachedBundleFileFolder = "CacheBundleFiles";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 缓存的原生文件的文件夹名称
|
||||||
|
/// </summary>
|
||||||
|
public const string CachedRawFileFolder = "CacheRawFiles";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 缓存的清单文件的文件夹名称
|
||||||
|
/// </summary>
|
||||||
|
public const string ManifestFolderName = "ManifestFiles";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 记录应用程序版本的文件名称
|
||||||
|
/// </summary>
|
||||||
|
public const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建输出文件夹名称
|
/// 构建输出文件夹名称
|
||||||
@@ -47,10 +72,5 @@ namespace YooAsset
|
|||||||
/// 构建输出的报告文件
|
/// 构建输出的报告文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string ReportFileName = "BuildReport";
|
public const string ReportFileName = "BuildReport";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 内置资源目录名称
|
|
||||||
/// </summary>
|
|
||||||
public const string StreamingAssetsBuildinFolder = "BuildinFiles";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,6 +217,21 @@ namespace YooAsset
|
|||||||
DownloadSystem.RequestDelegate = requestDelegate;
|
DownloadSystem.RequestDelegate = requestDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置下载系统参数,网络重定向次数(Unity引擎默认值32)
|
||||||
|
/// 注意:不支持设置为负值
|
||||||
|
/// </summary>
|
||||||
|
public static void SetDownloadSystemRedirectLimit(int redirectLimit)
|
||||||
|
{
|
||||||
|
if (redirectLimit < 0)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Invalid param value : {redirectLimit}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadSystem.RedirectLimit = redirectLimit;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -239,51 +254,11 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置缓存系统参数,沙盒目录的存储路径
|
/// 设置缓存系统参数,禁用缓存在WebGL平台
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SetCacheSystemSandboxPath(string sandboxPath)
|
public static void SetCacheSystemDisableCacheOnWebGL()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(sandboxPath))
|
CacheSystem.DisableUnityCacheOnWebGL = true;
|
||||||
{
|
|
||||||
YooLogger.Error($"Sandbox path is null or empty !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:需要确保没有任何资源系统起效之前才可以设置沙盒目录!
|
|
||||||
if (_packages.Count > 0)
|
|
||||||
{
|
|
||||||
YooLogger.Error($"Please call this method {nameof(SetCacheSystemSandboxPath)} before the package is created !");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PersistentTools.OverwriteSandboxPath(sandboxPath);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 沙盒相关
|
|
||||||
/// <summary>
|
|
||||||
/// 获取内置文件夹名称
|
|
||||||
/// </summary>
|
|
||||||
public static string GetStreamingAssetBuildinFolderName()
|
|
||||||
{
|
|
||||||
return YooAssetSettings.StreamingAssetsBuildinFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取沙盒的根路径
|
|
||||||
/// </summary>
|
|
||||||
public static string GetSandboxRoot()
|
|
||||||
{
|
|
||||||
return PersistentTools.GetPersistentRootPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 清空沙盒目录(需要重启APP)
|
|
||||||
/// </summary>
|
|
||||||
public static void ClearSandbox()
|
|
||||||
{
|
|
||||||
YooLogger.Warning("Clear sandbox folder files, Finally, restart the application !");
|
|
||||||
PersistentTools.DeleteSandbox();
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string _manifestPath = string.Empty;
|
private string _manifestPath = string.Empty;
|
||||||
|
private string _packageName = "DefaultPackage";
|
||||||
|
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,8 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150)))
|
if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150)))
|
||||||
{
|
{
|
||||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
string streamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||||
|
EditorTools.ClearFolder(streamingAssetsRoot);
|
||||||
CopyPackageFiles(_manifestPath);
|
CopyPackageFiles(_manifestPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,18 +59,18 @@ namespace YooAsset.Editor
|
|||||||
// 拷贝核心文件
|
// 拷贝核心文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
|
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.bytes";
|
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
string sourcePath = $"{outputDirectory}/{manifestFileName}.hash";
|
string sourcePath = $"{outputDirectory}/{manifestFileName}.hash";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.hash";
|
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName);
|
string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName);
|
||||||
string sourcePath = $"{outputDirectory}/{fileName}";
|
string sourcePath = $"{outputDirectory}/{fileName}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{fileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{fileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
fileCount++;
|
fileCount++;
|
||||||
string sourcePath = $"{outputDirectory}/{packageBundle.FileName}";
|
string sourcePath = $"{outputDirectory}/{packageBundle.FileName}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{packageBundle.FileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,11 +65,12 @@ internal class FsmInitialize : IStateNode
|
|||||||
// 联机运行模式
|
// 联机运行模式
|
||||||
if (playMode == EPlayMode.HostPlayMode)
|
if (playMode == EPlayMode.HostPlayMode)
|
||||||
{
|
{
|
||||||
|
string defaultHostServer = GetHostServerURL();
|
||||||
|
string fallbackHostServer = GetHostServerURL();
|
||||||
var createParameters = new HostPlayModeParameters();
|
var createParameters = new HostPlayModeParameters();
|
||||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||||
createParameters.QueryServices = new GameQueryServices();
|
createParameters.QueryServices = new GameQueryServices();
|
||||||
createParameters.DefaultHostServer = GetHostServerURL();
|
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||||
createParameters.FallbackHostServer = GetHostServerURL();
|
|
||||||
initializationOperation = package.InitializeAsync(createParameters);
|
initializationOperation = package.InitializeAsync(createParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +116,30 @@ internal class FsmInitialize : IStateNode
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 远端资源地址查询服务类
|
||||||
|
/// </summary>
|
||||||
|
private class RemoteServices : IRemoteServices
|
||||||
|
{
|
||||||
|
private readonly string _defaultHostServer;
|
||||||
|
private readonly string _fallbackHostServer;
|
||||||
|
|
||||||
|
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||||
|
{
|
||||||
|
_defaultHostServer = defaultHostServer;
|
||||||
|
_fallbackHostServer = fallbackHostServer;
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_defaultHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_fallbackHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源文件解密服务类
|
/// 资源文件解密服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -3,15 +3,20 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
|
public class StreamingAssetsDefine
|
||||||
|
{
|
||||||
|
public const string RootFolderName = "yoo";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置文件查询服务类
|
/// 内置文件查询服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GameQueryServices : IQueryServices
|
public class GameQueryServices : IQueryServices
|
||||||
{
|
{
|
||||||
public bool QueryStreamingAssets(string fileName)
|
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||||
{
|
{
|
||||||
// 注意:fileName包含文件格式
|
// 注意:fileName包含文件格式
|
||||||
return StreamingAssetsHelper.FileExists(fileName);
|
return StreamingAssetsHelper.FileExists(packageName, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,9 +27,10 @@ public class GameQueryServices : IQueryServices
|
|||||||
public sealed class StreamingAssetsHelper
|
public sealed class StreamingAssetsHelper
|
||||||
{
|
{
|
||||||
public static void Init() { }
|
public static void Init() { }
|
||||||
public static bool FileExists(string fileName)
|
public static bool FileExists(string packageName, string fileName)
|
||||||
{
|
{
|
||||||
return File.Exists(Path.Combine(Application.streamingAssetsPath, "BuildinFiles", fileName));
|
string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName);
|
||||||
|
return File.Exists(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -45,9 +51,12 @@ public sealed class StreamingAssetsHelper
|
|||||||
{
|
{
|
||||||
_isInit = true;
|
_isInit = true;
|
||||||
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
||||||
foreach (string fileName in manifest.BuildinFiles)
|
if (manifest != null)
|
||||||
{
|
{
|
||||||
_cacheData.Add(fileName);
|
foreach (string fileName in manifest.BuildinFiles)
|
||||||
|
{
|
||||||
|
_cacheData.Add(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +64,7 @@ public sealed class StreamingAssetsHelper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置文件查询方法
|
/// 内置文件查询方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool FileExists(string fileName)
|
public static bool FileExists(string packageName, string fileName)
|
||||||
{
|
{
|
||||||
if (_isInit == false)
|
if (_isInit == false)
|
||||||
Init();
|
Init();
|
||||||
@@ -75,11 +84,20 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||||
{
|
{
|
||||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
string saveFilePath = "Assets/Resources/BuildinFileManifest.asset";
|
||||||
|
if (File.Exists(saveFilePath))
|
||||||
|
File.Delete(saveFilePath);
|
||||||
|
|
||||||
string folderPath = $"{Application.dataPath}/StreamingAssets/BuildinFiles";
|
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||||
FileInfo[] files = root.GetFiles();
|
if (root.Exists == false)
|
||||||
|
{
|
||||||
|
Debug.Log($"没有发现YooAsset内置目录 : {folderPath}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||||
|
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||||
foreach (var fileInfo in files)
|
foreach (var fileInfo in files)
|
||||||
{
|
{
|
||||||
if (fileInfo.Extension == ".meta")
|
if (fileInfo.Extension == ".meta")
|
||||||
@@ -89,15 +107,12 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
|||||||
manifest.BuildinFiles.Add(fileInfo.Name);
|
manifest.BuildinFiles.Add(fileInfo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
string saveFilePath = "Assets/Resources/BuildinFileManifest.asset";
|
|
||||||
if (File.Exists(saveFilePath))
|
|
||||||
File.Delete(saveFilePath);
|
|
||||||
if (Directory.Exists("Assets/Resources") == false)
|
if (Directory.Exists("Assets/Resources") == false)
|
||||||
Directory.CreateDirectory("Assets/Resources");
|
Directory.CreateDirectory("Assets/Resources");
|
||||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||||
UnityEditor.AssetDatabase.SaveAssets();
|
UnityEditor.AssetDatabase.SaveAssets();
|
||||||
UnityEditor.AssetDatabase.Refresh();
|
UnityEditor.AssetDatabase.Refresh();
|
||||||
Debug.Log($"内置资源清单保存成功 : {saveFilePath}");
|
Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -6,15 +6,19 @@ using UnityEngine;
|
|||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
public class StreamingAssetsDefine
|
||||||
|
{
|
||||||
|
public const string RootFolderName = "yoo";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置文件查询服务类
|
/// 内置文件查询服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GameQueryServices : IQueryServices
|
public class GameQueryServices : IQueryServices
|
||||||
{
|
{
|
||||||
public bool QueryStreamingAssets(string fileName)
|
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||||
{
|
{
|
||||||
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
|
return StreamingAssetsHelper.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");
|
||||||
return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.tuyoogame.yooasset",
|
"name": "com.tuyoogame.yooasset",
|
||||||
"displayName": "YooAsset",
|
"displayName": "YooAsset",
|
||||||
"version": "1.4.17",
|
"version": "1.5.1",
|
||||||
"unity": "2019.4",
|
"unity": "2019.4",
|
||||||
"description": "unity3d resources management system.",
|
"description": "unity3d resources management system.",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
Reference in New Issue
Block a user