mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-15 12:10:09 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3d15fc59f | ||
|
|
8a3358c990 | ||
|
|
8eadba3aa6 | ||
|
|
b0917623b6 | ||
|
|
a7d9a4ecbc | ||
|
|
2643ab81ed | ||
|
|
c5314c72f0 | ||
|
|
fbb48ba330 | ||
|
|
4e6879e34f | ||
|
|
09c3d4e479 | ||
|
|
1e88bad73e | ||
|
|
9a2ed64b4e | ||
|
|
60e93f9809 | ||
|
|
f5c72e913f |
@@ -2,6 +2,119 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [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
|
||||
|
||||
### Changed
|
||||
@@ -25,8 +138,6 @@ All notable changes to this package will be documented in this file.
|
||||
|
||||
- IShareAssetPackRule 重命名为 ISharedPackRule
|
||||
|
||||
-
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了ResourcePackage.LoadAllAssetsAsync方法
|
||||
|
||||
@@ -13,29 +13,20 @@ namespace YooAsset.Editor
|
||||
private readonly BuildContext _buildContext = new BuildContext();
|
||||
|
||||
/// <summary>
|
||||
/// 开始构建
|
||||
/// 构建资源包
|
||||
/// </summary>
|
||||
public BuildResult Run(BuildParameters buildParameters)
|
||||
public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline)
|
||||
{
|
||||
// 清空旧数据
|
||||
_buildContext.ClearAllContext();
|
||||
|
||||
// 检测构建参数是否为空
|
||||
if (buildParameters == null)
|
||||
throw new Exception($"{nameof(buildParameters)} is null !");
|
||||
|
||||
// 检测可编程构建管线参数
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
if (buildParameters.SBPParameters == null)
|
||||
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
|
||||
// 检测构建参数是否为空
|
||||
if (buildPipeline.Count == 0)
|
||||
throw new Exception($"Build pipeline is empty !");
|
||||
|
||||
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 !");
|
||||
}
|
||||
// 清空旧数据
|
||||
_buildContext.ClearAllContext();
|
||||
|
||||
// 构建参数
|
||||
var buildParametersContext = new BuildParametersContext(buildParameters);
|
||||
@@ -45,8 +36,7 @@ namespace YooAsset.Editor
|
||||
BuildLogger.InitLogger(buildParameters.EnableLog);
|
||||
|
||||
// 执行构建流程
|
||||
var pipeline = GetBuildTasks(buildParameters.BuildPipeline);
|
||||
var buildResult = BuildRunner.Run(pipeline, _buildContext);
|
||||
var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
@@ -62,13 +52,23 @@ namespace YooAsset.Editor
|
||||
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)
|
||||
{
|
||||
/*
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
@@ -83,23 +83,10 @@ namespace YooAsset.Editor
|
||||
new TaskCreatePackage(), //制作包裹
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
return pipeline;
|
||||
}
|
||||
else if (buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
/*
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
@@ -114,42 +101,12 @@ namespace YooAsset.Editor
|
||||
new TaskCreatePackage(), //制作补丁包
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
return pipeline;
|
||||
}
|
||||
else
|
||||
{
|
||||
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>
|
||||
public static string GetDefaultOutputRoot()
|
||||
public static string GetDefaultBuildOutputRoot()
|
||||
{
|
||||
string projectPath = EditorTools.GetProjectPath();
|
||||
return $"{projectPath}/Bundles";
|
||||
@@ -20,43 +20,9 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取流文件夹路径
|
||||
/// </summary>
|
||||
public static string GetStreamingAssetsFolderPath()
|
||||
public static string GetDefaultStreamingAssetsRoot()
|
||||
{
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.StreamingAssetsBuildinFolder}/";
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.DefaultYooFolderName}/";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace YooAsset.Editor
|
||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.Name).ToList();
|
||||
|
||||
// 输出目录
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
_buildOutputField = root.Q<TextField>("BuildOutput");
|
||||
_buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
|
||||
_buildOutputField.SetEnabled(false);
|
||||
@@ -266,9 +266,9 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private void ExecuteBuild()
|
||||
{
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildTarget = _buildTarget;
|
||||
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
|
||||
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace YooAsset.Editor
|
||||
public static string SimulateBuild(string packageName)
|
||||
{
|
||||
Debug.Log($"Begin to create simulate package : {packageName}");
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.StreamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.PackageName = packageName;
|
||||
|
||||
@@ -37,9 +37,14 @@ namespace YooAsset.Editor
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 输出的根目录
|
||||
/// 内置资源的根目录
|
||||
/// </summary>
|
||||
public string OutputRoot;
|
||||
public string StreamingAssetsRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出的根目录
|
||||
/// </summary>
|
||||
public string BuildOutputRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的平台
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
private string _pipelineOutputDirectory = string.Empty;
|
||||
private string _packageOutputDirectory = string.Empty;
|
||||
private string _packageRootDirectory = string.Empty;
|
||||
private string _streamingAssetsDirectory = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 构建参数
|
||||
@@ -29,23 +31,47 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
||||
{
|
||||
_pipelineOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
|
||||
_pipelineOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{YooAssetSettings.OutputFolderName}";
|
||||
}
|
||||
return _pipelineOutputDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本次构建的补丁目录
|
||||
/// 获取本次构建的补丁输出目录
|
||||
/// </summary>
|
||||
public string GetPackageOutputDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
||||
{
|
||||
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
|
||||
_packageOutputDirectory = $"{Parameters.BuildOutputRoot}/{Parameters.BuildTarget}/{Parameters.PackageName}/{Parameters.PackageVersion}";
|
||||
}
|
||||
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>
|
||||
|
||||
@@ -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)]
|
||||
public class TaskAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务所属的构建流水线
|
||||
/// </summary>
|
||||
public ETaskPipeline Pipeline;
|
||||
|
||||
/// <summary>
|
||||
/// 执行顺序
|
||||
/// </summary>
|
||||
public int TaskOrder;
|
||||
|
||||
/// <summary>
|
||||
/// 任务说明
|
||||
/// </summary>
|
||||
public string TaskDesc;
|
||||
|
||||
// 关联的任务类
|
||||
public Type ClassType { set; get; }
|
||||
|
||||
public TaskAttribute(ETaskPipeline pipeline, int taskOrder, string taskDesc)
|
||||
public TaskAttribute(string taskDesc)
|
||||
{
|
||||
Pipeline = pipeline;
|
||||
TaskOrder = taskOrder;
|
||||
TaskDesc = taskDesc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 300, "资源构建内容打包")]
|
||||
[TaskAttribute("资源构建内容打包")]
|
||||
public class TaskBuilding : IBuildTask
|
||||
{
|
||||
public class BuildResultContext : IContextObject
|
||||
|
||||
@@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Tasks;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 300, "资源构建内容打包")]
|
||||
[TaskAttribute("资源构建内容打包")]
|
||||
public class TaskBuilding_SBP : IBuildTask
|
||||
{
|
||||
public class BuildResultContext : IContextObject
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1100, "拷贝内置文件到流目录")]
|
||||
[TaskAttribute("拷贝内置文件到流目录")]
|
||||
public class TaskCopyBuildinFiles : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
string streamingAssetsDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
|
||||
string streamingAssetsDirectory = buildParametersContext.GetStreamingAssetsDirectory();
|
||||
string buildPackageName = buildParametersContext.Parameters.PackageName;
|
||||
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace YooAsset.Editor
|
||||
// 清空流目录
|
||||
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
|
||||
{
|
||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||
EditorTools.ClearFolder(streamingAssetsDirectory);
|
||||
}
|
||||
|
||||
// 拷贝补丁清单文件
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 400, "拷贝原生文件")]
|
||||
[TaskAttribute("拷贝原生文件")]
|
||||
public class TaskCopyRawFile : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
||||
internal PackageManifest Manifest;
|
||||
}
|
||||
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 800, "创建清单文件")]
|
||||
[TaskAttribute("创建清单文件")]
|
||||
public class TaskCreateManifest : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1000, "制作包裹")]
|
||||
[TaskAttribute("制作包裹")]
|
||||
public class TaskCreatePackage : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 900, "创建构建报告文件")]
|
||||
[TaskAttribute("创建构建报告文件")]
|
||||
public class TaskCreateReport : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 600, "资源包加密")]
|
||||
[TaskAttribute("资源包加密")]
|
||||
public class TaskEncryption : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -7,7 +7,7 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 200, "获取资源构建内容")]
|
||||
[TaskAttribute("获取资源构建内容")]
|
||||
public class TaskGetBuildMap : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
@@ -147,17 +147,17 @@ namespace YooAsset.Editor
|
||||
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
|
||||
{
|
||||
// 1. 检测是否任何存在依赖资源
|
||||
bool hasAnyDependAsset = false;
|
||||
bool hasAnyDependCollector = false;
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
{
|
||||
var collectorType = collectAssetInfo.CollectorType;
|
||||
if (collectorType == ECollectorType.DependAssetCollector)
|
||||
{
|
||||
hasAnyDependAsset = true;
|
||||
hasAnyDependCollector = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasAnyDependAsset == false)
|
||||
if (hasAnyDependCollector == false)
|
||||
return;
|
||||
|
||||
// 2. 获取所有主资源的依赖资源集合
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 100, "资源构建准备工作")]
|
||||
[TaskAttribute("资源构建准备工作")]
|
||||
public class TaskPrepare : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
@@ -16,11 +16,27 @@ namespace YooAsset.Editor
|
||||
|
||||
// 检测构建参数合法性
|
||||
if (buildParameters.BuildTarget == BuildTarget.NoTarget)
|
||||
throw new Exception("请选择目标平台");
|
||||
throw new Exception("请选择目标平台!");
|
||||
if (string.IsNullOrEmpty(buildParameters.PackageName))
|
||||
throw new Exception("包裹名称不能为空");
|
||||
throw new Exception("包裹名称不能为空!");
|
||||
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)
|
||||
{
|
||||
@@ -72,11 +88,10 @@ namespace YooAsset.Editor
|
||||
|
||||
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
{
|
||||
// 删除总目录
|
||||
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.PackageName}";
|
||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
||||
string packageRootDirectory = buildParametersContext.GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"删除平台总目录:{platformDirectory}");
|
||||
BuildLogger.Log($"删除包裹目录:{packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 700, "更新资源包信息")]
|
||||
[TaskAttribute("更新资源包信息")]
|
||||
public class TaskUpdateBundleInfo : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -8,7 +8,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 500, "验证构建结果")]
|
||||
[TaskAttribute("验证构建结果")]
|
||||
public class TaskVerifyBuildResult : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Interfaces;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 500, "验证构建结果")]
|
||||
[TaskAttribute("验证构建结果")]
|
||||
public class TaskVerifyBuildResult_SBP : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
||||
@@ -168,8 +168,17 @@ namespace YooAsset
|
||||
// 5. 从WEB网站获取AssetBundle文件
|
||||
if (_steps == ESteps.LoadWebFile)
|
||||
{
|
||||
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
|
||||
if (CacheSystem.DisableUnityCacheOnWebGL)
|
||||
{
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
|
||||
}
|
||||
|
||||
DownloadSystem.SetUnityWebRequest(_webRequest);
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckLoadWebFile;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,11 @@ namespace YooAsset
|
||||
{
|
||||
private readonly static Dictionary<string, PackageCache> _cachedDic = new Dictionary<string, PackageCache>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Unity缓存系统在WebGL平台
|
||||
/// </summary>
|
||||
public static bool DisableUnityCacheOnWebGL = false;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化时的验证级别
|
||||
/// </summary>
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
{
|
||||
// BundleFiles
|
||||
{
|
||||
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheBundleFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace YooAsset
|
||||
|
||||
// RawFiles
|
||||
{
|
||||
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
|
||||
string rootPath = PersistentTools.GetPersistent(_packageName).SandboxCacheRawFilesRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
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
|
||||
guid: 32477ef3a448a9144aa1574a052fe54e
|
||||
guid: 62ee5fd2821fe85488efff3f8242b703
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -3,84 +3,31 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal static class PersistentTools
|
||||
internal class PersistentTools
|
||||
{
|
||||
private const string SandboxFolderName = "Sandbox";
|
||||
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;
|
||||
|
||||
private static readonly Dictionary<string, Persistent> _persitentDic = new Dictionary<string, Persistent>(100);
|
||||
|
||||
/// <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>
|
||||
public static string GetPersistentRootPath()
|
||||
public static Persistent GetOrCreatePersistent(string packageName)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
if (_persitentDic.ContainsKey(packageName) == false)
|
||||
{
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
_sandboxPath = PathUtility.Combine(projectPath, SandboxFolderName);
|
||||
Persistent persistent = new Persistent(packageName);
|
||||
_persitentDic.Add(packageName, persistent);
|
||||
}
|
||||
#elif UNITY_STANDALONE
|
||||
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);
|
||||
return _persitentDic[packageName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,109 +47,5 @@ namespace YooAsset
|
||||
return path;
|
||||
#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>
|
||||
public static CertificateHandler CertificateHandlerInstance = null;
|
||||
|
||||
/// <summary>
|
||||
/// 网络重定向次数
|
||||
/// </summary>
|
||||
public static int RedirectLimit { set; get; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// 启用断点续传功能文件的最小字节数
|
||||
/// </summary>
|
||||
@@ -128,11 +133,29 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static UnityWebRequest NewRequest(string requestURL)
|
||||
{
|
||||
UnityWebRequest webRequest;
|
||||
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);
|
||||
return request;
|
||||
SetUnityWebRequest(webRequest);
|
||||
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>
|
||||
|
||||
@@ -101,13 +101,6 @@ namespace YooAsset
|
||||
handler.removeFileOnAbort = true;
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
|
||||
if (DownloadSystem.CertificateHandlerInstance != null)
|
||||
{
|
||||
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
||||
_webRequest.disposeCertificateHandlerOnDispose = false;
|
||||
}
|
||||
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
@@ -137,13 +130,6 @@ namespace YooAsset
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
if (fileLength > 0)
|
||||
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
|
||||
|
||||
if (DownloadSystem.CertificateHandlerInstance != null)
|
||||
{
|
||||
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
|
||||
_webRequest.disposeCertificateHandlerOnDispose = false;
|
||||
}
|
||||
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,18 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件的根路径
|
||||
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||
/// </summary>
|
||||
public string BuildinRootDirectory = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 沙盒文件的根路径
|
||||
/// 注意:当参数为空的时候会使用默认的根目录。
|
||||
/// </summary>
|
||||
public string SandboxRootDirectory = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 资源加载每帧处理的最大时间片段
|
||||
/// 注意:默认值为MaxValue
|
||||
|
||||
@@ -217,13 +217,13 @@ namespace YooAsset
|
||||
if (_steps == ESteps.CheckAppFootPrint)
|
||||
{
|
||||
var appFootPrint = new AppFootPrint();
|
||||
appFootPrint.Load();
|
||||
appFootPrint.Load(_packageName);
|
||||
|
||||
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
|
||||
if (appFootPrint.IsDirty())
|
||||
{
|
||||
PersistentTools.DeleteManifestFolder();
|
||||
appFootPrint.Coverage();
|
||||
PersistentTools.GetPersistent(_packageName).DeleteSandboxManifestFilesFolder();
|
||||
appFootPrint.Coverage(_packageName);
|
||||
YooLogger.Log("Delete manifest files when application foot print dirty !");
|
||||
}
|
||||
_steps = ESteps.QueryCachePackageVersion;
|
||||
@@ -374,16 +374,16 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 读取应用程序水印
|
||||
/// </summary>
|
||||
public void Load()
|
||||
public void Load(string packageName)
|
||||
{
|
||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
||||
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
|
||||
if (File.Exists(footPrintFilePath))
|
||||
{
|
||||
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Coverage();
|
||||
Coverage(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,14 +402,14 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 覆盖掉水印
|
||||
/// </summary>
|
||||
public void Coverage()
|
||||
public void Coverage(string packageName)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_footPrint = Application.version;
|
||||
#else
|
||||
_footPrint = Application.buildGUID;
|
||||
#endif
|
||||
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
|
||||
string footPrintFilePath = PersistentTools.GetPersistent(packageName).SandboxAppFootPrintFilePath;
|
||||
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
|
||||
YooLogger.Log($"Save application foot print : {_footPrint}");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download package hash file : {webURL}");
|
||||
@@ -71,7 +71,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string filePath = PersistentTools.GetPersistent(_buildinPackageName).GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileHash)
|
||||
{
|
||||
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
|
||||
_manifestFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
|
||||
if (File.Exists(_manifestFilePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
@@ -131,7 +131,7 @@ namespace YooAsset
|
||||
File.Delete(_manifestFilePath);
|
||||
}
|
||||
|
||||
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string hashFilePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
File.Delete(hashFilePath);
|
||||
|
||||
@@ -37,8 +37,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader == null)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
string filePath = PersistentTools.GetPersistent(_packageName).GetBuildinPackageVersionFilePath();
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(url);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageHashFile)
|
||||
{
|
||||
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
|
||||
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.LoadCachePackageVersionFile)
|
||||
{
|
||||
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
|
||||
string filePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageVersionFilePath();
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -31,13 +31,13 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if(_steps == ESteps.UnpackManifestHashFile)
|
||||
if (_steps == ESteps.UnpackManifestHashFile)
|
||||
{
|
||||
if (_downloader1 == null)
|
||||
{
|
||||
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
|
||||
string savePath = persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
|
||||
string filePath = persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader1 = new UnityWebFileRequester();
|
||||
_downloader1.SendRequest(url, savePath);
|
||||
@@ -64,9 +64,9 @@ namespace YooAsset
|
||||
{
|
||||
if (_downloader2 == null)
|
||||
{
|
||||
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
|
||||
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
|
||||
var persistent = PersistentTools.GetPersistent(_buildinPackageName);
|
||||
string savePath = persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
|
||||
string filePath = persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string url = PersistentTools.ConvertToWWWPath(filePath);
|
||||
_downloader2 = new UnityWebFileRequester();
|
||||
_downloader2.SendRequest(url, savePath);
|
||||
|
||||
@@ -74,13 +74,13 @@ namespace YooAsset
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
|
||||
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||
_cachedDataFilePath += _fileExtension;
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
|
||||
_cachedDataFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleDataFileName);
|
||||
}
|
||||
return _cachedDataFilePath;
|
||||
@@ -101,12 +101,12 @@ namespace YooAsset
|
||||
string folderName = FileHash.Substring(0, 2);
|
||||
if (IsRawFile)
|
||||
{
|
||||
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheRawFilesRoot;
|
||||
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
|
||||
string cacheRoot = PersistentTools.GetPersistent(PackageName).SandboxCacheBundleFilesRoot;
|
||||
_cachedInfoFilePath = PathUtility.Combine(cacheRoot, folderName, CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
|
||||
}
|
||||
return _cachedInfoFilePath;
|
||||
@@ -140,7 +140,8 @@ namespace YooAsset
|
||||
if (string.IsNullOrEmpty(_streamingFilePath) == false)
|
||||
return _streamingFilePath;
|
||||
|
||||
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
|
||||
string root = PersistentTools.GetPersistent(PackageName).BuildinPackageRoot;
|
||||
_streamingFilePath = PathUtility.Combine(root, FileName);
|
||||
return _streamingFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +74,14 @@ namespace YooAsset
|
||||
public void FlushManifestVersionFile()
|
||||
{
|
||||
if (_activeManifest != null)
|
||||
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
|
||||
{
|
||||
PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _queryServices.QueryStreamingAssets(packageBundle.FileName);
|
||||
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||
}
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
|
||||
@@ -79,6 +79,10 @@ namespace YooAsset
|
||||
// 检测初始化参数合法性
|
||||
CheckInitializeParameters(parameters);
|
||||
|
||||
// 重写持久化根目录
|
||||
var persistent = PersistentTools.GetOrCreatePersistent(PackageName);
|
||||
persistent.OverwriteRootDirectory(parameters.BuildinRootDirectory, parameters.SandboxRootDirectory);
|
||||
|
||||
// 初始化资源系统
|
||||
InitializationOperation initializeOperation;
|
||||
_assetSystemImpl = new AssetSystemImpl();
|
||||
@@ -291,6 +295,37 @@ namespace YooAsset
|
||||
_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 资源信息
|
||||
/// <summary>
|
||||
|
||||
@@ -6,6 +6,6 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 查询内置资源
|
||||
/// </summary>
|
||||
bool QueryStreamingAssets(string fileName);
|
||||
bool QueryStreamingAssets(string packageName, string fileName);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,31 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
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>
|
||||
/// 构建输出文件夹名称
|
||||
@@ -47,10 +72,5 @@ namespace YooAsset
|
||||
/// 构建输出的报告文件
|
||||
/// </summary>
|
||||
public const string ReportFileName = "BuildReport";
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源目录名称
|
||||
/// </summary>
|
||||
public const string StreamingAssetsBuildinFolder = "BuildinFiles";
|
||||
}
|
||||
}
|
||||
@@ -217,6 +217,21 @@ namespace YooAsset
|
||||
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>
|
||||
@@ -239,51 +254,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置缓存系统参数,沙盒目录的存储路径
|
||||
/// 设置缓存系统参数,禁用缓存在WebGL平台
|
||||
/// </summary>
|
||||
public static void SetCacheSystemSandboxPath(string sandboxPath)
|
||||
public static void SetCacheSystemDisableCacheOnWebGL()
|
||||
{
|
||||
if (string.IsNullOrEmpty(sandboxPath))
|
||||
{
|
||||
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();
|
||||
CacheSystem.DisableUnityCacheOnWebGL = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
private string _manifestPath = string.Empty;
|
||||
private string _packageName = "DefaultPackage";
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
@@ -39,7 +40,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150)))
|
||||
{
|
||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||
string streamingAssetsRoot = AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot();
|
||||
EditorTools.ClearFolder(streamingAssetsRoot);
|
||||
CopyPackageFiles(_manifestPath);
|
||||
}
|
||||
}
|
||||
@@ -57,18 +59,18 @@ namespace YooAsset.Editor
|
||||
// 拷贝核心文件
|
||||
{
|
||||
string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.bytes";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
{
|
||||
string sourcePath = $"{outputDirectory}/{manifestFileName}.hash";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.hash";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName);
|
||||
string sourcePath = $"{outputDirectory}/{fileName}";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{fileName}";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{fileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
@@ -78,7 +80,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
fileCount++;
|
||||
string sourcePath = $"{outputDirectory}/{packageBundle.FileName}";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{packageBundle.FileName}";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetDefaultStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,20 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class StreamingAssetsDefine
|
||||
{
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string fileName)
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return StreamingAssetsHelper.FileExists(fileName);
|
||||
return StreamingAssetsHelper.FileExists(packageName, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +27,10 @@ public class GameQueryServices : IQueryServices
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
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
|
||||
@@ -55,7 +61,7 @@ public sealed class StreamingAssetsHelper
|
||||
/// <summary>
|
||||
/// 内置文件查询方法
|
||||
/// </summary>
|
||||
public static bool FileExists(string fileName)
|
||||
public static bool FileExists(string packageName, string fileName)
|
||||
{
|
||||
if (_isInit == false)
|
||||
Init();
|
||||
@@ -77,9 +83,9 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/BuildinFiles";
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||
FileInfo[] files = root.GetFiles();
|
||||
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta")
|
||||
@@ -97,7 +103,7 @@ internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"内置资源清单保存成功 : {saveFilePath}");
|
||||
Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -6,15 +6,19 @@ using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/*
|
||||
public class StreamingAssetsDefine
|
||||
{
|
||||
public const string RootFolderName = "yoo";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string fileName)
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
|
||||
return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
|
||||
return StreamingAssetsHelper.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.4.17",
|
||||
"version": "1.5.0",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user