mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-22 00:11:41 +00:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e340af90ed | ||
|
|
7fa7cc4af1 | ||
|
|
ca3c011f34 | ||
|
|
669339d5b4 | ||
|
|
c6567650fe | ||
|
|
3ae70412fa | ||
|
|
d575850f9f | ||
|
|
d1439da54e | ||
|
|
89022d3df4 | ||
|
|
3c38fe6155 | ||
|
|
e68ece6925 | ||
|
|
ea9b8874cc | ||
|
|
475efd90fc | ||
|
|
682605d5c2 | ||
|
|
256844ddf5 | ||
|
|
96f95bbd99 | ||
|
|
4f7bb945e0 | ||
|
|
0d69d779f6 | ||
|
|
5df26908fb | ||
|
|
fb5e289de0 | ||
|
|
b238759f61 | ||
|
|
2bb0d18891 | ||
|
|
7d5b6504f4 | ||
|
|
63f90e1537 | ||
|
|
65b43feb38 | ||
|
|
4f00a19344 | ||
|
|
3bfca7d340 | ||
|
|
8538d0de28 | ||
|
|
5425e17d6f | ||
|
|
bb3065d08d | ||
|
|
1adc3d7ed6 | ||
|
|
556b23b488 | ||
|
|
5b0c189d75 | ||
|
|
161fdff09a | ||
|
|
81b3dd57b1 | ||
|
|
1ab0f447d2 | ||
|
|
9ac07e94d1 | ||
|
|
fee6e8f4dd | ||
|
|
1e39b1af6d | ||
|
|
727d841d47 | ||
|
|
5e0d4d6ee1 | ||
|
|
32ce99949b | ||
|
|
fbb9bff3c7 | ||
|
|
6471b237ce | ||
|
|
d452c610c1 | ||
|
|
009fa88402 | ||
|
|
6d26276352 | ||
|
|
bdca693413 | ||
|
|
a2d30ca99a | ||
|
|
5c02bc2bee | ||
|
|
00ffd55fef | ||
|
|
32148821a1 | ||
|
|
60f6483a86 | ||
|
|
9b80300f19 | ||
|
|
8f02bfa3a6 | ||
|
|
93607ad62a | ||
|
|
3cbf891674 | ||
|
|
00688a65af | ||
|
|
c0099cb90c | ||
|
|
43248408fc | ||
|
|
d535500b9e | ||
|
|
9cea3e1ba9 | ||
|
|
746fa44ab8 | ||
|
|
b23d56f49c | ||
|
|
3693f1ea98 | ||
|
|
14127e8097 | ||
|
|
ad0d47bd68 | ||
|
|
b59fb0d811 | ||
|
|
0b1990f040 | ||
|
|
8deb239450 | ||
|
|
33387e8d26 | ||
|
|
9d4656a1f2 | ||
|
|
9c49d8d54a |
@@ -71,7 +71,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
result.completed = false;
|
result.completed = false;
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
if(progress is not null)
|
if(progress != null)
|
||||||
{
|
{
|
||||||
PlayerLoopHelper.AddAction(timing, result);
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
|
#if UNITY_2020_1_OR_NEWER && ! UNITY_2021
|
||||||
|
#define UNITY_2020_BUG
|
||||||
|
#endif
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using static Cysharp.Threading.Tasks.Internal.Error;
|
using static Cysharp.Threading.Tasks.Internal.Error;
|
||||||
|
|
||||||
|
|
||||||
namespace Cysharp.Threading.Tasks
|
namespace Cysharp.Threading.Tasks
|
||||||
{
|
{
|
||||||
public static class OperationHandleBaseExtensions
|
public static class OperationHandleBaseExtensions
|
||||||
@@ -71,11 +77,29 @@ namespace Cysharp.Threading.Tasks
|
|||||||
result.completed = false;
|
result.completed = false;
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
if(progress is not null)
|
if(progress != null)
|
||||||
{
|
{
|
||||||
PlayerLoopHelper.AddAction(timing, result);
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BUG 在 Unity 2020.3.36 版本测试中, IL2Cpp 会报 如下错误
|
||||||
|
// BUG ArgumentException: Incompatible Delegate Types. First is System.Action`1[[YooAsset.AssetOperationHandle, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] second is System.Action`1[[YooAsset.OperationHandleBase, YooAsset, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
|
||||||
|
// BUG 也可能报的是 Action '1' Action '1' 的 InvalidCastException
|
||||||
|
// BUG 此处不得不这么修改, 如果后续 Unity 修复了这个问题, 可以恢复之前的写法
|
||||||
|
#if UNITY_2020_BUG
|
||||||
|
switch(handle)
|
||||||
|
{
|
||||||
|
case AssetOperationHandle asset_handle:
|
||||||
|
asset_handle.Completed += result.AssetContinuation;
|
||||||
|
break;
|
||||||
|
case SceneOperationHandle scene_handle:
|
||||||
|
scene_handle.Completed += result.SceneContinuation;
|
||||||
|
break;
|
||||||
|
case SubAssetsOperationHandle sub_asset_handle:
|
||||||
|
sub_asset_handle.Completed += result.SubContinuation;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
switch(handle)
|
switch(handle)
|
||||||
{
|
{
|
||||||
case AssetOperationHandle asset_handle:
|
case AssetOperationHandle asset_handle:
|
||||||
@@ -88,11 +112,50 @@ namespace Cysharp.Threading.Tasks
|
|||||||
sub_asset_handle.Completed += result.continuationAction;
|
sub_asset_handle.Completed += result.continuationAction;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
token = result.core.Version;
|
token = result.core.Version;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#if UNITY_2020_BUG
|
||||||
|
private void AssetContinuation(AssetOperationHandle handle)
|
||||||
|
{
|
||||||
|
handle.Completed -= AssetContinuation;
|
||||||
|
BaseContinuation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SceneContinuation(SceneOperationHandle handle)
|
||||||
|
{
|
||||||
|
handle.Completed -= SceneContinuation;
|
||||||
|
BaseContinuation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SubContinuation(SubAssetsOperationHandle handle)
|
||||||
|
{
|
||||||
|
handle.Completed -= SubContinuation;
|
||||||
|
BaseContinuation();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private void BaseContinuation()
|
||||||
|
{
|
||||||
|
if(completed)
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
completed = true;
|
||||||
|
if(handle.Status == EOperationStatus.Failed)
|
||||||
|
{
|
||||||
|
core.TrySetException(new Exception(handle.LastError));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Continuation(OperationHandleBase _)
|
private void Continuation(OperationHandleBase _)
|
||||||
{
|
{
|
||||||
@@ -109,22 +172,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(completed)
|
BaseContinuation();
|
||||||
{
|
|
||||||
TryReturn();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
completed = true;
|
|
||||||
if(handle.Status == EOperationStatus.Failed)
|
|
||||||
{
|
|
||||||
core.TrySetException(new Exception(handle.LastError));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
core.TrySetResult(AsyncUnit.Default);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TryReturn()
|
bool TryReturn()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
[仓库链接](https://github.com/Cysharp/UniTask)
|
[仓库链接](https://github.com/Cysharp/UniTask)
|
||||||
- 请去下载对应的源码,并删除此目录最后的波浪线
|
- 请去下载对应的源码,并删除此目录最后的波浪线
|
||||||
|
- 在项目的 `asmdef` 文件中添加对 `UniTask.YooAsset` 的引用
|
||||||
- 在 UniTask `_InternalVisibleTo.cs` 文件中增加 `[assembly: InternalsVisibleTo("UniTask.YooAsset")]` 后即可使用
|
- 在 UniTask `_InternalVisibleTo.cs` 文件中增加 `[assembly: InternalsVisibleTo("UniTask.YooAsset")]` 后即可使用
|
||||||
|
|
||||||
## 代码示例
|
## 代码示例
|
||||||
|
|||||||
@@ -2,6 +2,126 @@
|
|||||||
|
|
||||||
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.2.0] - 2022-07-18
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了ShaderVariantCollection刷新不及时问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 资源收集忽略了Gizmos资源文件。
|
||||||
|
- 解密服务接口增加解密文件信息参数。
|
||||||
|
- 资源收集窗体增加配置保存按钮。
|
||||||
|
- 资源构建窗体增加配置保存按钮。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 资源构建模块增加了可编程构建管线(SBP)的支持,开发者可以在内置构建管线和可编程构建管线之间自由选择,零修改成本。
|
||||||
|
|
||||||
|
## [1.1.1] - 2022-07-07
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了AssetBundleDebugger窗口,View下拉页签切换无效的问题。
|
||||||
|
- 修复了在Unity2020.3版本下UniTask在真机上的一个IL2CPP相关的错误。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 优化了AssetBundleDebugger窗口,增加了帧数显示以及回放功能。
|
||||||
|
- 优化了AssetBundleBuilder的代码结构。
|
||||||
|
- 增强了YooAssets.GetRawFileAsync()方法的容错。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增了OperationHandleBase.GetAssetInfo()方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源信息
|
||||||
|
/// </summary>
|
||||||
|
public AssetInfo GetAssetInfo();
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增了AssetOperationHandle.GetAssetObjet<TAsset>()方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源对象
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TAsset">资源类型</typeparam>
|
||||||
|
public TAsset GetAssetObjet<TAsset>();
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增了弱联网情况下加载补丁清单方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 弱联网情况下加载补丁清单
|
||||||
|
/// 注意:当指定版本内容验证失败后会返回失败。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resourceVersion">指定的资源版本</param>
|
||||||
|
public static UpdateManifestOperation WeaklyUpdateManifestAsync(int resourceVersion);
|
||||||
|
````
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- 离线运行模式(OfflinePlayMode)下移除了资内置资源解压相关逻辑。
|
||||||
|
- 移除了初始化参数:AutoReleaseGameObjectHandle及相关代码逻辑。
|
||||||
|
|
||||||
|
## [1.1.0] - 2022-06-23
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了AssetBundleCollector窗口,在切换EnableAddressable时未及时刷新界面的问题。
|
||||||
|
- 修复了AssetBundleCollector窗口,资源过滤器CollectSprite无效的问题。
|
||||||
|
- 修复了AssetBundleCollector窗口,无法正常预览StaticAssetCollector的资源列表的问题。
|
||||||
|
- 修复了在离线模式下原生文件每次都从包内加载的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 变更了共享资源打包机制。
|
||||||
|
- AssetBundleCollector窗口增加了分组禁用功能。
|
||||||
|
- AssetBundleDebugger窗口增加了真机远程调试功能。
|
||||||
|
- AssetBundleBuilder窗口在构建成功后自动显示构建文件夹。
|
||||||
|
- DownloaderOperation.OnDownloadFileFailedCallback委托变更为OnDownloadErrorCallback委托。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增UpdateManifestOperation.FoundNewManifest字段。
|
||||||
|
- 新增DownloaderOperation.OnStartDownloadFileCallback委托。
|
||||||
|
- 新增AssetInfo.Address字段。
|
||||||
|
- 新增YooAssets.IsInitialized字段。
|
||||||
|
- 新增YooAssets初始化参数。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 下载文件校验等级
|
||||||
|
/// </summary>
|
||||||
|
public EVerifyLevel VerifyLevel = EVerifyLevel.High;
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增YooAssets获取资源完成路径的方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="location">资源的定位地址</param>
|
||||||
|
/// <returns>如果location地址无效,则返回空字符串</returns>
|
||||||
|
public static string GetAssetPath(string location);
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增YooAssets初始化参数。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 自动释放游戏对象所属资源句柄
|
||||||
|
/// 说明:通过资源句柄实例化的游戏对象在销毁之后,会自动释放所属资源句柄。
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoReleaseGameObjectHandle = false;
|
||||||
|
```
|
||||||
|
|
||||||
## [1.0.10] - 2022-05-22
|
## [1.0.10] - 2022-05-22
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -8,96 +8,6 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public class AssetBundleBuilder
|
public class AssetBundleBuilder
|
||||||
{
|
{
|
||||||
public class BuildParametersContext : IContextObject
|
|
||||||
{
|
|
||||||
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构建参数
|
|
||||||
/// </summary>
|
|
||||||
public BuildParameters Parameters { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构建管线的输出目录
|
|
||||||
/// </summary>
|
|
||||||
public string PipelineOutputDirectory { private set; get; }
|
|
||||||
|
|
||||||
|
|
||||||
public BuildParametersContext(BuildParameters parameters)
|
|
||||||
{
|
|
||||||
Parameters = parameters;
|
|
||||||
|
|
||||||
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
|
||||||
if (parameters.BuildMode == EBuildMode.DryRunBuild)
|
|
||||||
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
|
|
||||||
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
|
|
||||||
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取本次构建的补丁目录
|
|
||||||
/// </summary>
|
|
||||||
public string GetPackageDirectory()
|
|
||||||
{
|
|
||||||
return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取构建选项
|
|
||||||
/// </summary>
|
|
||||||
public BuildAssetBundleOptions GetPipelineBuildOptions()
|
|
||||||
{
|
|
||||||
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
|
|
||||||
// 除非设置ForceRebuildAssetBundle标记,否则会进行增量打包
|
|
||||||
|
|
||||||
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
|
||||||
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
|
||||||
|
|
||||||
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
|
|
||||||
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
|
||||||
{
|
|
||||||
opt |= BuildAssetBundleOptions.DryRunBuild;
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Parameters.CompressOption == ECompressOption.Uncompressed)
|
|
||||||
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
|
|
||||||
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
|
||||||
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
|
||||||
|
|
||||||
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
|
||||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
|
||||||
if (Parameters.DisableWriteTypeTree)
|
|
||||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
|
||||||
if (Parameters.IgnoreTypeTreeChanges)
|
|
||||||
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
|
||||||
|
|
||||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
|
||||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
|
||||||
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取构建的耗时(单位:秒)
|
|
||||||
/// </summary>
|
|
||||||
public float GetBuildingSeconds()
|
|
||||||
{
|
|
||||||
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
|
||||||
return seconds;
|
|
||||||
}
|
|
||||||
public void BeginWatch()
|
|
||||||
{
|
|
||||||
_buildWatch.Start();
|
|
||||||
}
|
|
||||||
public void StopWatch()
|
|
||||||
{
|
|
||||||
_buildWatch.Stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly BuildContext _buildContext = new BuildContext();
|
private readonly BuildContext _buildContext = new BuildContext();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -108,29 +18,65 @@ namespace YooAsset.Editor
|
|||||||
// 清空旧数据
|
// 清空旧数据
|
||||||
_buildContext.ClearAllContext();
|
_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 !");
|
||||||
|
}
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
var buildParametersContext = new BuildParametersContext(buildParameters);
|
var buildParametersContext = new BuildParametersContext(buildParameters);
|
||||||
_buildContext.SetContextObject(buildParametersContext);
|
_buildContext.SetContextObject(buildParametersContext);
|
||||||
|
|
||||||
// 执行构建流程
|
// 是否显示LOG
|
||||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
|
||||||
{
|
|
||||||
new TaskPrepare(), //前期准备工作
|
|
||||||
new TaskGetBuildMap(), //获取构建列表
|
|
||||||
new TaskBuilding(), //开始执行构建
|
|
||||||
new TaskVerifyBuildResult(), //验证构建结果
|
|
||||||
new TaskEncryption(), //加密资源文件
|
|
||||||
new TaskCreatePatchManifest(), //创建清单文件
|
|
||||||
new TaskCreateReport(), //创建报告文件
|
|
||||||
new TaskCreatePatchPackage(), //制作补丁包
|
|
||||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
|
||||||
};
|
|
||||||
|
|
||||||
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
BuildRunner.EnableLog = false;
|
BuildRunner.EnableLog = false;
|
||||||
else
|
else
|
||||||
BuildRunner.EnableLog = true;
|
BuildRunner.EnableLog = true;
|
||||||
|
|
||||||
|
// 创建构建节点
|
||||||
|
List<IBuildTask> pipeline;
|
||||||
|
if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||||
|
{
|
||||||
|
pipeline = new List<IBuildTask>
|
||||||
|
{
|
||||||
|
new TaskPrepare(), //前期准备工作
|
||||||
|
new TaskGetBuildMap(), //获取构建列表
|
||||||
|
new TaskBuilding(), //开始执行构建
|
||||||
|
new TaskVerifyBuildResult(), //验证构建结果
|
||||||
|
new TaskEncryption(), //加密资源文件
|
||||||
|
new TaskCreatePatchManifest(), //创建清单文件
|
||||||
|
new TaskCreateReport(), //创建报告文件
|
||||||
|
new TaskCreatePatchPackage(), //制作补丁包
|
||||||
|
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
|
{
|
||||||
|
pipeline = new List<IBuildTask>
|
||||||
|
{
|
||||||
|
new TaskPrepare(), //前期准备工作
|
||||||
|
new TaskGetBuildMap(), //获取构建列表
|
||||||
|
new TaskBuilding_SBP(), //开始执行构建
|
||||||
|
new TaskVerifyBuildResult_SBP(), //验证构建结果
|
||||||
|
new TaskEncryption(), //加密资源文件
|
||||||
|
new TaskCreatePatchManifest(), //创建清单文件
|
||||||
|
new TaskCreateReport(), //创建报告文件
|
||||||
|
new TaskCreatePatchPackage(), //制作补丁包
|
||||||
|
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行构建流程
|
||||||
bool succeed = BuildRunner.Run(pipeline, _buildContext);
|
bool succeed = BuildRunner.Run(pipeline, _buildContext);
|
||||||
if (succeed)
|
if (succeed)
|
||||||
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
|
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int BuildVersion = 0;
|
public int BuildVersion = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建管线
|
||||||
|
/// </summary>
|
||||||
|
public EBuildPipeline BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建模式
|
/// 构建模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,10 +39,5 @@ namespace YooAsset.Editor
|
|||||||
/// 附加后缀格式
|
/// 附加后缀格式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AppendExtension = false;
|
public bool AppendExtension = false;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 拷贝内置资源文件(首包资源文件)
|
|
||||||
/// </summary>
|
|
||||||
public bool CopyBuildinTagFiles = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,11 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 配置数据是否被修改
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsDirty { set; get; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载配置文件
|
/// 加载配置文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,6 +39,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (Setting != null)
|
if (Setting != null)
|
||||||
{
|
{
|
||||||
|
IsDirty = false;
|
||||||
EditorUtility.SetDirty(Setting);
|
EditorUtility.SetDirty(Setting);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");
|
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");
|
||||||
|
|||||||
@@ -22,15 +22,16 @@ namespace YooAsset.Editor
|
|||||||
private List<Type> _encryptionServicesClassTypes;
|
private List<Type> _encryptionServicesClassTypes;
|
||||||
private List<string> _encryptionServicesClassNames;
|
private List<string> _encryptionServicesClassNames;
|
||||||
|
|
||||||
|
private Button _saveButton;
|
||||||
private TextField _buildOutputField;
|
private TextField _buildOutputField;
|
||||||
private IntegerField _buildVersionField;
|
private IntegerField _buildVersionField;
|
||||||
|
private EnumField _buildPipelineField;
|
||||||
private EnumField _buildModeField;
|
private EnumField _buildModeField;
|
||||||
private TextField _buildinTagsField;
|
private TextField _buildinTagsField;
|
||||||
private PopupField<string> _encryptionField;
|
private PopupField<string> _encryptionField;
|
||||||
private EnumField _compressionField;
|
private EnumField _compressionField;
|
||||||
private Toggle _appendExtensionToggle;
|
private Toggle _appendExtensionToggle;
|
||||||
private Toggle _copyBuildinTagFilesToggle;
|
|
||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -41,10 +42,17 @@ namespace YooAsset.Editor
|
|||||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
|
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
|
||||||
if (visualAsset == null)
|
if (visualAsset == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
visualAsset.CloneTree(root);
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
|
// 配置保存按钮
|
||||||
|
_saveButton = root.Q<Button>("SaveButton");
|
||||||
|
_saveButton.clicked += SaveBtn_clicked;
|
||||||
|
|
||||||
|
// 构建平台
|
||||||
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
|
|
||||||
|
// 加密服务类
|
||||||
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
||||||
|
|
||||||
@@ -60,9 +68,22 @@ namespace YooAsset.Editor
|
|||||||
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
|
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
|
||||||
_buildVersionField.RegisterValueChangedCallback(evt =>
|
_buildVersionField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
|
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 构建管线
|
||||||
|
_buildPipelineField = root.Q<EnumField>("BuildPipeline");
|
||||||
|
_buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline);
|
||||||
|
_buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline);
|
||||||
|
_buildPipelineField.style.width = 300;
|
||||||
|
_buildPipelineField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value;
|
||||||
|
RefreshWindow();
|
||||||
|
});
|
||||||
|
|
||||||
// 构建模式
|
// 构建模式
|
||||||
_buildModeField = root.Q<EnumField>("BuildMode");
|
_buildModeField = root.Q<EnumField>("BuildMode");
|
||||||
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
|
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
|
||||||
@@ -70,6 +91,7 @@ namespace YooAsset.Editor
|
|||||||
_buildModeField.style.width = 300;
|
_buildModeField.style.width = 300;
|
||||||
_buildModeField.RegisterValueChangedCallback(evt =>
|
_buildModeField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
|
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
|
||||||
RefreshWindow();
|
RefreshWindow();
|
||||||
});
|
});
|
||||||
@@ -79,6 +101,7 @@ namespace YooAsset.Editor
|
|||||||
_buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
_buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||||
_buildinTagsField.RegisterValueChangedCallback(evt =>
|
_buildinTagsField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
|
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,6 +115,7 @@ namespace YooAsset.Editor
|
|||||||
_encryptionField.style.width = 300;
|
_encryptionField.style.width = 300;
|
||||||
_encryptionField.RegisterValueChangedCallback(evt =>
|
_encryptionField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
|
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
|
||||||
});
|
});
|
||||||
encryptionContainer.Add(_encryptionField);
|
encryptionContainer.Add(_encryptionField);
|
||||||
@@ -108,9 +132,10 @@ namespace YooAsset.Editor
|
|||||||
_compressionField = root.Q<EnumField>("Compression");
|
_compressionField = root.Q<EnumField>("Compression");
|
||||||
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
_compressionField.style.width = 300;
|
_compressionField.style.width = 300;
|
||||||
_compressionField.RegisterValueChangedCallback(evt =>
|
_compressionField.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -119,17 +144,10 @@ namespace YooAsset.Editor
|
|||||||
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
|
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
|
||||||
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
|
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
|
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 拷贝首包文件
|
|
||||||
_copyBuildinTagFilesToggle = root.Q<Toggle>("CopyBuildinFiles");
|
|
||||||
_copyBuildinTagFilesToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles);
|
|
||||||
_copyBuildinTagFilesToggle.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles = _copyBuildinTagFilesToggle.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 构建按钮
|
// 构建按钮
|
||||||
var buildButton = root.Q<Button>("Build");
|
var buildButton = root.Q<Button>("Build");
|
||||||
buildButton.clicked += BuildButton_clicked; ;
|
buildButton.clicked += BuildButton_clicked; ;
|
||||||
@@ -143,7 +161,24 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
public void OnDestroy()
|
public void OnDestroy()
|
||||||
{
|
{
|
||||||
AssetBundleBuilderSettingData.SaveFile();
|
if(AssetBundleBuilderSettingData.IsDirty)
|
||||||
|
AssetBundleBuilderSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if(_saveButton != null)
|
||||||
|
{
|
||||||
|
if(AssetBundleBuilderSettingData.IsDirty)
|
||||||
|
{
|
||||||
|
if (_saveButton.enabledSelf == false)
|
||||||
|
_saveButton.SetEnabled(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(_saveButton.enabledSelf)
|
||||||
|
_saveButton.SetEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshWindow()
|
private void RefreshWindow()
|
||||||
@@ -154,7 +189,10 @@ namespace YooAsset.Editor
|
|||||||
_encryptionField.SetEnabled(enableElement);
|
_encryptionField.SetEnabled(enableElement);
|
||||||
_compressionField.SetEnabled(enableElement);
|
_compressionField.SetEnabled(enableElement);
|
||||||
_appendExtensionToggle.SetEnabled(enableElement);
|
_appendExtensionToggle.SetEnabled(enableElement);
|
||||||
_copyBuildinTagFilesToggle.SetEnabled(buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild);
|
}
|
||||||
|
private void SaveBtn_clicked()
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.SaveFile();
|
||||||
}
|
}
|
||||||
private void BuildButton_clicked()
|
private void BuildButton_clicked()
|
||||||
{
|
{
|
||||||
@@ -179,18 +217,29 @@ namespace YooAsset.Editor
|
|||||||
BuildParameters buildParameters = new BuildParameters();
|
BuildParameters buildParameters = new BuildParameters();
|
||||||
buildParameters.OutputRoot = defaultOutputRoot;
|
buildParameters.OutputRoot = defaultOutputRoot;
|
||||||
buildParameters.BuildTarget = _buildTarget;
|
buildParameters.BuildTarget = _buildTarget;
|
||||||
buildParameters.BuildMode = (EBuildMode)_buildModeField.value;
|
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
|
||||||
buildParameters.BuildVersion = _buildVersionField.value;
|
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||||
buildParameters.BuildinTags = _buildinTagsField.value;
|
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
|
||||||
|
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
|
||||||
buildParameters.VerifyBuildingResult = true;
|
buildParameters.VerifyBuildingResult = true;
|
||||||
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||||
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
|
buildParameters.AppendFileExtension = AssetBundleBuilderSettingData.Setting.AppendExtension;
|
||||||
buildParameters.CopyBuildinTagFiles = _copyBuildinTagFilesToggle.value;
|
buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
|
||||||
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||||
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
|
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
|
||||||
|
|
||||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
builder.Run(buildParameters);
|
{
|
||||||
|
buildParameters.SBPParameters = new BuildParameters.SBPBuildParameters();
|
||||||
|
buildParameters.SBPParameters.WriteLinkXML = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new AssetBundleBuilder();
|
||||||
|
bool succeed = builder.Run(buildParameters);
|
||||||
|
if (succeed)
|
||||||
|
{
|
||||||
|
EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加密类相关
|
// 加密类相关
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex;" />
|
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||||
|
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="background-color: rgb(56, 147, 58);" />
|
||||||
|
</uie:Toolbar>
|
||||||
<ui:VisualElement name="BuildContainer">
|
<ui:VisualElement name="BuildContainer">
|
||||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||||
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
|
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
|
||||||
|
<uie:EnumField label="Build Pipeline" name="BuildPipeline" />
|
||||||
<uie:EnumField label="Build Mode" name="BuildMode" />
|
<uie:EnumField label="Build Mode" name="BuildMode" />
|
||||||
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
||||||
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
||||||
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" />
|
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" />
|
||||||
<ui:Toggle label="Copy BuildinTag Files" name="CopyBuildinFiles" style="height: 15px;" />
|
|
||||||
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
|
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
|
||||||
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
private string _mainBundleName;
|
private string _mainBundleName;
|
||||||
private string _shareBundleName;
|
private string _shareBundleName;
|
||||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
|
||||||
private bool _isAddAssetTags = false;
|
private bool _isAddAssetTags = false;
|
||||||
|
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 收集器类型
|
/// 收集器类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -68,9 +68,9 @@ namespace YooAsset.Editor
|
|||||||
else
|
else
|
||||||
IsShaderAsset = false;
|
IsShaderAsset = false;
|
||||||
}
|
}
|
||||||
public BuildAssetInfo(ECollectorType collectorType, string assetPath)
|
public BuildAssetInfo(string assetPath)
|
||||||
{
|
{
|
||||||
CollectorType = collectorType;
|
CollectorType = ECollectorType.None;
|
||||||
Address = string.Empty;
|
Address = string.Empty;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
IsRawAsset = false;
|
IsRawAsset = false;
|
||||||
@@ -112,7 +112,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加资源包的分类标签
|
/// 添加资源包的分类标签
|
||||||
/// 说明:传染算法统计到的分类标签
|
/// 说明:传染算法统计到的分类标签
|
||||||
@@ -185,11 +185,9 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
if (_referenceBundleNames.Count > 1)
|
if (_referenceBundleNames.Count > 1)
|
||||||
{
|
{
|
||||||
var bundleNameList = _referenceBundleNames.ToList();
|
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||||
bundleNameList.Sort();
|
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
||||||
string combineName = string.Join("|", bundleNameList);
|
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
var combineNameHash = HashUtility.StringSHA1(combineName);
|
|
||||||
var shareBundleName = $"share_{combineNameHash}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
|
||||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
|
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||||
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
||||||
|
|||||||
@@ -9,6 +9,23 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BuildParameters
|
public class BuildParameters
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// SBP构建参数
|
||||||
|
/// </summary>
|
||||||
|
public class SBPBuildParameters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 生成代码防裁剪配置
|
||||||
|
/// </summary>
|
||||||
|
public bool WriteLinkXML = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可编程构建管线的参数
|
||||||
|
/// </summary>
|
||||||
|
public SBPBuildParameters SBPParameters;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输出的根目录
|
/// 输出的根目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,6 +36,11 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildTarget BuildTarget;
|
public BuildTarget BuildTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建管线
|
||||||
|
/// </summary>
|
||||||
|
public EBuildPipeline BuildPipeline;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建模式
|
/// 构建模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,7 +74,7 @@ namespace YooAsset.Editor
|
|||||||
public bool AppendFileExtension = false;
|
public bool AppendFileExtension = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拷贝内置资源文件(首包资源文件)
|
/// 拷贝内置资源文件到StreamingAssets目录(首包资源文件)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CopyBuildinTagFiles = false;
|
public bool CopyBuildinTagFiles = false;
|
||||||
|
|
||||||
@@ -86,4 +108,6 @@ namespace YooAsset.Editor
|
|||||||
return StringUtility.StringToStringList(BuildinTags, ';');
|
return StringUtility.StringToStringList(BuildinTags, ';');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class BuildParametersContext : IContextObject
|
||||||
|
{
|
||||||
|
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建参数
|
||||||
|
/// </summary>
|
||||||
|
public BuildParameters Parameters { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建管线的输出目录
|
||||||
|
/// </summary>
|
||||||
|
public string PipelineOutputDirectory { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
public BuildParametersContext(BuildParameters parameters)
|
||||||
|
{
|
||||||
|
Parameters = parameters;
|
||||||
|
|
||||||
|
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
||||||
|
if (parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
|
||||||
|
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本次构建的补丁目录
|
||||||
|
/// </summary>
|
||||||
|
public string GetPackageDirectory()
|
||||||
|
{
|
||||||
|
return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取内置构建管线的构建选项
|
||||||
|
/// </summary>
|
||||||
|
public BuildAssetBundleOptions GetPipelineBuildOptions()
|
||||||
|
{
|
||||||
|
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
|
||||||
|
// 除非设置ForceRebuildAssetBundle标记,否则会进行增量打包
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
||||||
|
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
{
|
||||||
|
opt |= BuildAssetBundleOptions.DryRunBuild;
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Parameters.CompressOption == ECompressOption.Uncompressed)
|
||||||
|
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
|
||||||
|
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
||||||
|
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
|
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||||
|
if (Parameters.DisableWriteTypeTree)
|
||||||
|
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||||
|
if (Parameters.IgnoreTypeTreeChanges)
|
||||||
|
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
||||||
|
|
||||||
|
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||||
|
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||||
|
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取可编程构建管线的构建参数
|
||||||
|
/// </summary>
|
||||||
|
public UnityEditor.Build.Pipeline.BundleBuildParameters GetSBPBuildParameters()
|
||||||
|
{
|
||||||
|
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
throw new Exception($"SBP not support {nameof(EBuildMode.DryRunBuild)} build mode !");
|
||||||
|
|
||||||
|
var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget);
|
||||||
|
var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory);
|
||||||
|
|
||||||
|
if (Parameters.CompressOption == ECompressOption.Uncompressed)
|
||||||
|
buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed;
|
||||||
|
else if (Parameters.CompressOption == ECompressOption.LZMA)
|
||||||
|
buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA;
|
||||||
|
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
||||||
|
buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4;
|
||||||
|
else
|
||||||
|
throw new System.NotImplementedException(Parameters.CompressOption.ToString());
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
|
buildParams.UseCache = false;
|
||||||
|
if (Parameters.DisableWriteTypeTree)
|
||||||
|
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
|
||||||
|
|
||||||
|
buildParams.WriteLinkXML = Parameters.SBPParameters.WriteLinkXML;
|
||||||
|
|
||||||
|
return buildParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取构建的耗时(单位:秒)
|
||||||
|
/// </summary>
|
||||||
|
public float GetBuildingSeconds()
|
||||||
|
{
|
||||||
|
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
public void BeginWatch()
|
||||||
|
{
|
||||||
|
_buildWatch.Start();
|
||||||
|
}
|
||||||
|
public void StopWatch()
|
||||||
|
{
|
||||||
|
_buildWatch.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b84510feab7cbe44a9b6d8ef0b3f559c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -8,6 +8,11 @@ namespace YooAsset.Editor
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class ReportSummary
|
public class ReportSummary
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// YooAsset版本
|
||||||
|
/// </summary>
|
||||||
|
public string YooVersion;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引擎版本
|
/// 引擎版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -16,7 +21,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建时间
|
/// 构建时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BuildTime;
|
public string BuildDate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建耗时(单位:秒)
|
/// 构建耗时(单位:秒)
|
||||||
@@ -28,6 +33,11 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildTarget BuildTarget;
|
public BuildTarget BuildTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建管线
|
||||||
|
/// </summary>
|
||||||
|
public EBuildPipeline BuildPipeline;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建模式
|
/// 构建模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@@ -18,7 +17,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
// 模拟构建模式下跳过引擎构建
|
// 模拟构建模式下跳过引擎构建
|
||||||
@@ -46,7 +45,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拷贝原生文件
|
/// 拷贝原生文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CopyRawBundle(BuildMapContext buildMapContext, AssetBundleBuilder.BuildParametersContext buildParametersContext)
|
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
|
||||||
{
|
{
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
using UnityEditor.Build.Pipeline;
|
||||||
|
using UnityEditor.Build.Pipeline.Interfaces;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[TaskAttribute("资源构建内容打包")]
|
||||||
|
public class TaskBuilding_SBP : IBuildTask
|
||||||
|
{
|
||||||
|
public class SBPBuildResultContext : IContextObject
|
||||||
|
{
|
||||||
|
public IBundleBuildResults Results;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
{
|
||||||
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
|
// 模拟构建模式下跳过引擎构建
|
||||||
|
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||||
|
if (buildMode == EBuildMode.SimulateBuild)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 构建内容
|
||||||
|
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
|
||||||
|
|
||||||
|
// 开始构建
|
||||||
|
IBundleBuildResults buildResults;
|
||||||
|
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
||||||
|
var taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction);
|
||||||
|
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
||||||
|
if (exitCode < 0)
|
||||||
|
{
|
||||||
|
throw new Exception($"构建过程中发生错误 : {exitCode}");
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildRunner.Log("Unity引擎打包成功!");
|
||||||
|
SBPBuildResultContext buildResultContext = new SBPBuildResultContext();
|
||||||
|
buildResultContext.Results = buildResults;
|
||||||
|
context.SetContextObject(buildResultContext);
|
||||||
|
|
||||||
|
// 添加Unity内置资源包信息
|
||||||
|
if (buildResults.BundleInfos.Keys.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
|
||||||
|
{
|
||||||
|
BuildBundleInfo builtInBundleInfo = new BuildBundleInfo(YooAssetSettings.UnityBuiltInShadersBundleName);
|
||||||
|
buildMapContext.BundleInfos.Add(builtInBundleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝原生文件
|
||||||
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
|
{
|
||||||
|
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 拷贝原生文件
|
||||||
|
/// </summary>
|
||||||
|
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
|
||||||
|
{
|
||||||
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
|
{
|
||||||
|
if (bundleInfo.IsRawFile)
|
||||||
|
{
|
||||||
|
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||||
|
foreach (var buildAsset in bundleInfo.BuildinAssets)
|
||||||
|
{
|
||||||
|
if (buildAsset.IsRawAsset)
|
||||||
|
EditorTools.CopyFile(buildAsset.AssetPath, dest, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1af5fed7e9f83174d868c12b41c4a79e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
|||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
// 注意:我们只有在强制重建的时候才会拷贝
|
// 注意:我们只有在强制重建的时候才会拷贝
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
if (buildParameters.Parameters.CopyBuildinTagFiles)
|
if (buildParameters.Parameters.CopyBuildinTagFiles)
|
||||||
{
|
{
|
||||||
// 清空流目录
|
// 清空流目录
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.Linq;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using UnityEditor.Build.Pipeline;
|
||||||
|
using UnityEditor.Build.Pipeline.Interfaces;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[TaskAttribute("创建补丁清单文件")]
|
[TaskAttribute("创建补丁清单文件")]
|
||||||
@@ -10,18 +13,17 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
CreatePatchManifestFile(context);
|
||||||
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
|
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
|
||||||
CreatePatchManifestFile(buildParameters, buildMapContext, encryptionContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建补丁清单文件到输出目录
|
/// 创建补丁清单文件到输出目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
|
private void CreatePatchManifestFile(BuildContext context)
|
||||||
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
|
||||||
{
|
{
|
||||||
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
|
||||||
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
|
|
||||||
// 创建新补丁清单
|
// 创建新补丁清单
|
||||||
@@ -32,6 +34,13 @@ namespace YooAsset.Editor
|
|||||||
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
||||||
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
|
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
|
||||||
|
|
||||||
|
// 更新Unity内置资源包的引用关系
|
||||||
|
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
|
{
|
||||||
|
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
|
||||||
|
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建补丁清单文件
|
// 创建补丁清单文件
|
||||||
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
|
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
|
||||||
@@ -53,8 +62,8 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源包列表
|
/// 获取资源包列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters,
|
private List<PatchBundle> GetAllPatchBundle(BuildParametersContext buildParameters, BuildMapContext buildMapContext,
|
||||||
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
TaskEncryption.EncryptionContext encryptionContext)
|
||||||
{
|
{
|
||||||
List<PatchBundle> result = new List<PatchBundle>(1000);
|
List<PatchBundle> result = new List<PatchBundle>(1000);
|
||||||
|
|
||||||
@@ -124,8 +133,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源列表
|
/// 获取资源列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<PatchAsset> GetAllPatchAsset(AssetBundleBuilder.BuildParametersContext buildParameters,
|
private List<PatchAsset> GetAllPatchAsset(BuildParametersContext buildParameters, BuildMapContext buildMapContext, PatchManifest patchManifest)
|
||||||
BuildMapContext buildMapContext, PatchManifest patchManifest)
|
|
||||||
{
|
{
|
||||||
List<PatchAsset> result = new List<PatchAsset>(1000);
|
List<PatchAsset> result = new List<PatchAsset>(1000);
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
@@ -173,5 +181,45 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
throw new Exception($"Not found bundle name : {bundleName}");
|
throw new Exception($"Not found bundle name : {bundleName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新Unity内置资源包的引用关系
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults)
|
||||||
|
{
|
||||||
|
// 获取所有依赖内置资源包的资源包列表
|
||||||
|
List<string> builtInBundleReferenceList = new List<string>();
|
||||||
|
foreach (var valuePair in buildResults.BundleInfos)
|
||||||
|
{
|
||||||
|
if (valuePair.Value.Dependencies.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
|
||||||
|
builtInBundleReferenceList.Add(valuePair.Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测依赖交集并更新依赖ID
|
||||||
|
int builtInBundleId = patchManifest.BundleList.Count - 1;
|
||||||
|
foreach (var patchAsset in patchManifest.AssetList)
|
||||||
|
{
|
||||||
|
List<string> dependBundles = GetPatchAssetAllDependBundles(patchManifest, patchAsset);
|
||||||
|
List<string> conflictAssetPathList = dependBundles.Intersect(builtInBundleReferenceList).ToList();
|
||||||
|
if (conflictAssetPathList.Count > 0)
|
||||||
|
{
|
||||||
|
List<int> newDependIDs = new List<int>(patchAsset.DependIDs);
|
||||||
|
newDependIDs.Add(builtInBundleId);
|
||||||
|
patchAsset.DependIDs = newDependIDs.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private List<string> GetPatchAssetAllDependBundles(PatchManifest patchManifest, PatchAsset patchAsset)
|
||||||
|
{
|
||||||
|
List<string> result = new List<string>();
|
||||||
|
string mainBundle = patchManifest.BundleList[patchAsset.BundleID].BundleName;
|
||||||
|
result.Add(mainBundle);
|
||||||
|
foreach (var dependID in patchAsset.DependIDs)
|
||||||
|
{
|
||||||
|
string dependBundle = patchManifest.BundleList[dependID].BundleName;
|
||||||
|
result.Add(dependBundle);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMode = buildParameters.Parameters.BuildMode;
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拷贝补丁文件到补丁包目录
|
/// 拷贝补丁文件到补丁包目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
|
private void CopyPatchFiles(BuildParametersContext buildParameters)
|
||||||
{
|
{
|
||||||
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
string packageDirectory = buildParameters.GetPackageDirectory();
|
string packageDirectory = buildParameters.GetPackageDirectory();
|
||||||
@@ -54,18 +54,38 @@ namespace YooAsset.Editor
|
|||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝UnityManifest序列化文件
|
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
// 拷贝构建日志
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
{
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json";
|
||||||
}
|
string destPath = $"{packageDirectory}/buildlogtep.json";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
// 拷贝UnityManifest文本文件
|
// 拷贝代码防裁剪配置
|
||||||
|
if (buildParameters.Parameters.SBPParameters.WriteLinkXML)
|
||||||
|
{
|
||||||
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml";
|
||||||
|
string destPath = $"{packageDirectory}/link.xml";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
|
// 拷贝UnityManifest序列化文件
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
|
{
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||||
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝UnityManifest文本文件
|
||||||
|
{
|
||||||
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
|
||||||
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝所有补丁文件
|
// 拷贝所有补丁文件
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
buildParameters.StopWatch();
|
buildParameters.StopWatch();
|
||||||
|
|
||||||
@@ -26,17 +26,23 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
||||||
{
|
{
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
BuildReport buildReport = new BuildReport();
|
BuildReport buildReport = new BuildReport();
|
||||||
|
|
||||||
// 概述信息
|
// 概述信息
|
||||||
{
|
{
|
||||||
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly);
|
||||||
|
if (packageInfo != null)
|
||||||
|
buildReport.Summary.YooVersion = packageInfo.version;
|
||||||
|
#endif
|
||||||
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
||||||
buildReport.Summary.BuildTime = DateTime.Now.ToString();
|
buildReport.Summary.BuildDate = DateTime.Now.ToString();
|
||||||
buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds();
|
buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds();
|
||||||
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
|
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
|
||||||
|
buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline;
|
||||||
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode;
|
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode;
|
||||||
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
|
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
|
||||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
var buildMode = buildParameters.Parameters.BuildMode;
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
@@ -45,7 +45,7 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加密文件
|
/// 加密文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<string> EncryptFiles(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
private List<string> EncryptFiles(BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
||||||
{
|
{
|
||||||
var encryptionServices = buildParameters.Parameters.EncryptionServices;
|
var encryptionServices = buildParameters.Parameters.EncryptionServices;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
|
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
|
||||||
context.SetContextObject(buildMapContext);
|
context.SetContextObject(buildMapContext);
|
||||||
BuildRunner.Log("构建内容准备完毕!");
|
BuildRunner.Log("构建内容准备完毕!");
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
buildParameters.BeginWatch();
|
buildParameters.BeginWatch();
|
||||||
|
|
||||||
// 检测构建平台是否合法
|
// 检测构建平台是否合法
|
||||||
@@ -26,6 +26,17 @@ namespace YooAsset.Editor
|
|||||||
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
|
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
|
||||||
throw new Exception("输出目录不能为空");
|
throw new Exception("输出目录不能为空");
|
||||||
|
|
||||||
|
// 检测当前是否正在构建资源包
|
||||||
|
if (BuildPipeline.isBuildingPlayer)
|
||||||
|
throw new Exception("当前正在构建资源包,请结束后再试");
|
||||||
|
|
||||||
|
// 检测是否有未保存场景
|
||||||
|
if (EditorTools.HasDirtyScenes())
|
||||||
|
throw new Exception("检测到未保存的场景文件");
|
||||||
|
|
||||||
|
// 保存改动的资源
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
|
||||||
// 增量更新时候的必要检测
|
// 增量更新时候的必要检测
|
||||||
var buildMode = buildParameters.Parameters.BuildMode;
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
if (buildMode == EBuildMode.IncrementalBuild)
|
if (buildMode == EBuildMode.IncrementalBuild)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
|
|
||||||
// 模拟构建模式下跳过验证
|
// 模拟构建模式下跳过验证
|
||||||
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
@@ -32,58 +32,26 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
|
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
string[] buildedBundles = unityManifest.GetAllAssetBundles();
|
string[] buildedBundles = unityManifest.GetAllAssetBundles();
|
||||||
|
|
||||||
// 1. 过滤掉原生Bundle
|
// 1. 过滤掉原生Bundle
|
||||||
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length);
|
string[] expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
|
||||||
foreach(var bundleInfo in buildMapContext.BundleInfos)
|
|
||||||
{
|
|
||||||
if (bundleInfo.IsRawFile == false)
|
|
||||||
expectBundles.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证数量
|
// 2. 验证Bundle
|
||||||
if (buildedBundles.Length != expectBundles.Count)
|
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
|
||||||
|
if (intersectBundleList.Count > 0)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"构建过程中可能存在无效的资源,导致和预期构建的Bundle数量不一致!");
|
foreach (var intersectBundle in intersectBundleList)
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 正向验证Bundle
|
|
||||||
foreach (var bundleName in buildedBundles)
|
|
||||||
{
|
|
||||||
if (buildMapContext.IsContainsBundle(bundleName) == false)
|
|
||||||
{
|
{
|
||||||
throw new Exception($"Should never get here !");
|
Debug.LogWarning($"差异资源包: {intersectBundle}");
|
||||||
}
|
}
|
||||||
|
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 反向验证Bundle
|
// 3. 验证Asset
|
||||||
bool isPass = true;
|
bool isPass = true;
|
||||||
foreach (var expectBundle in expectBundles)
|
|
||||||
{
|
|
||||||
bool isMatch = false;
|
|
||||||
foreach (var buildedBundle in buildedBundles)
|
|
||||||
{
|
|
||||||
if (buildedBundle == expectBundle.BundleName)
|
|
||||||
{
|
|
||||||
isMatch = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMatch == false)
|
|
||||||
{
|
|
||||||
isPass = false;
|
|
||||||
Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isPass == false)
|
|
||||||
{
|
|
||||||
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 验证Asset
|
|
||||||
var buildMode = buildParameters.Parameters.BuildMode;
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
{
|
{
|
||||||
@@ -137,7 +105,6 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 卸载所有加载的Bundle
|
|
||||||
BuildRunner.Log("构建结果验证成功!");
|
BuildRunner.Log("构建结果验证成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor.Build.Pipeline.Interfaces;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[TaskAttribute("验证构建结果")]
|
||||||
|
public class TaskVerifyBuildResult_SBP : IBuildTask
|
||||||
|
{
|
||||||
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
{
|
||||||
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
|
|
||||||
|
// 模拟构建模式下跳过验证
|
||||||
|
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 验证构建结果
|
||||||
|
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
||||||
|
{
|
||||||
|
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
|
||||||
|
VerifyingBuildingResult(context, buildResultContext.Results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证构建结果
|
||||||
|
/// </summary>
|
||||||
|
private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
|
||||||
|
{
|
||||||
|
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||||
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
|
// 1. 移除特定Bundle
|
||||||
|
List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
|
||||||
|
buildedBundles.Remove(YooAssetSettings.UnityBuiltInShadersBundleName);
|
||||||
|
|
||||||
|
// 2. 过滤掉原生Bundle
|
||||||
|
List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
|
||||||
|
|
||||||
|
// 3. 验证Bundle
|
||||||
|
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
|
||||||
|
if (intersectBundleList.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var intersectBundle in intersectBundleList)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"差异资源包: {intersectBundle}");
|
||||||
|
}
|
||||||
|
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildRunner.Log("构建结果验证成功!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 16aa7c2c37209a043b4f33d7854047c6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
19
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs
Normal file
19
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构建管线类型
|
||||||
|
/// </summary>
|
||||||
|
public enum EBuildPipeline
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 传统内置构建管线
|
||||||
|
/// </summary>
|
||||||
|
BuiltinBuildPipeline,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可编程构建管线
|
||||||
|
/// </summary>
|
||||||
|
ScriptableBuildPipeline,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e53e56a0f6b01dd4c933249d2bda8d78
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -87,10 +87,10 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取打包收集的资源文件
|
/// 获取打包收集的资源文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleCollectorGroup group)
|
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
// 注意:模拟构建模式下只收集主资源
|
// 注意:模拟构建模式下只收集主资源
|
||||||
if (AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
if (buildMode == EBuildMode.SimulateBuild)
|
||||||
{
|
{
|
||||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||||
return new List<CollectAssetInfo>();
|
return new List<CollectAssetInfo>();
|
||||||
@@ -117,7 +117,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (result.ContainsKey(assetPath) == false)
|
if (result.ContainsKey(assetPath) == false)
|
||||||
{
|
{
|
||||||
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||||
result.Add(assetPath, collectAssetInfo);
|
result.Add(assetPath, collectAssetInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -132,7 +132,7 @@ namespace YooAsset.Editor
|
|||||||
string assetPath = CollectPath;
|
string assetPath = CollectPath;
|
||||||
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
||||||
{
|
{
|
||||||
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||||
result.Add(assetPath, collectAssetInfo);
|
result.Add(assetPath, collectAssetInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -162,19 +162,33 @@ namespace YooAsset.Editor
|
|||||||
return result.Values.ToList();
|
return result.Values.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
private CollectAssetInfo CreateCollectAssetInfo(EBuildMode buildMode, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||||
{
|
{
|
||||||
string address = GetAddress(group, assetPath);
|
string address = GetAddress(group, assetPath);
|
||||||
string bundleName = GetBundleName(group, assetPath);
|
string bundleName = GetBundleName(group, assetPath);
|
||||||
List<string> assetTags = GetAssetTags(group);
|
List<string> assetTags = GetAssetTags(group);
|
||||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
||||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
|
||||||
|
// 注意:模拟构建模式下不需要收集依赖资源
|
||||||
|
if (buildMode == EBuildMode.SimulateBuild)
|
||||||
|
collectAssetInfo.DependAssets = new List<string>();
|
||||||
|
else
|
||||||
|
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||||
|
|
||||||
return collectAssetInfo;
|
return collectAssetInfo;
|
||||||
}
|
}
|
||||||
private bool IsValidateAsset(string assetPath)
|
private bool IsValidateAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (assetPath.Contains("/Gizmos/"))
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogWarning($"Cannot pack gizmos asset : {assetPath}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (AssetDatabase.IsValidFolder(assetPath))
|
if (AssetDatabase.IsValidFolder(assetPath))
|
||||||
return false;
|
return false;
|
||||||
@@ -242,10 +256,6 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
private List<string> GetAllDependencies(string mainAssetPath)
|
private List<string> GetAllDependencies(string mainAssetPath)
|
||||||
{
|
{
|
||||||
// 注意:模拟构建模式下不需要收集依赖资源
|
|
||||||
if(AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
|
||||||
return new List<string>();
|
|
||||||
|
|
||||||
List<string> result = new List<string>();
|
List<string> result = new List<string>();
|
||||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||||
foreach (string assetPath in depends)
|
foreach (string assetPath in depends)
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string AssetTags = string.Empty;
|
public string AssetTags = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分组激活规则
|
||||||
|
/// </summary>
|
||||||
|
public string ActiveRuleName = nameof(EnableGroup);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分组的收集器列表
|
/// 分组的收集器列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,6 +41,9 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void CheckConfigError()
|
public void CheckConfigError()
|
||||||
{
|
{
|
||||||
|
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||||
|
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||||
|
|
||||||
foreach (var collector in Collectors)
|
foreach (var collector in Collectors)
|
||||||
{
|
{
|
||||||
collector.CheckConfigError();
|
collector.CheckConfigError();
|
||||||
@@ -45,14 +53,21 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取打包收集的资源文件
|
/// 获取打包收集的资源文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CollectAssetInfo> GetAllCollectAssets()
|
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
||||||
{
|
{
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||||
|
|
||||||
|
// 检测分组是否激活
|
||||||
|
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||||
|
if (activeRule.IsActiveGroup() == false)
|
||||||
|
{
|
||||||
|
return new List<CollectAssetInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
// 收集打包资源
|
// 收集打包资源
|
||||||
foreach (var collector in Collectors)
|
foreach (var collector in Collectors)
|
||||||
{
|
{
|
||||||
var temper = collector.GetAllCollectAssets(this);
|
var temper = collector.GetAllCollectAssets(buildMode, this);
|
||||||
foreach (var assetInfo in temper)
|
foreach (var assetInfo in temper)
|
||||||
{
|
{
|
||||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public class AssetBundleCollectorSetting : ScriptableObject
|
public class AssetBundleCollectorSetting : ScriptableObject
|
||||||
{
|
{
|
||||||
public static EBuildMode BuildMode;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用可寻址资源定位
|
/// 是否启用可寻址资源定位
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,14 +45,12 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
||||||
{
|
{
|
||||||
BuildMode = buildMode;
|
|
||||||
|
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||||
|
|
||||||
// 收集打包资源
|
// 收集打包资源
|
||||||
foreach (var group in Groups)
|
foreach (var group in Groups)
|
||||||
{
|
{
|
||||||
var temper = group.GetAllCollectAssets();
|
var temper = group.GetAllCollectAssets(buildMode);
|
||||||
foreach (var assetInfo in temper)
|
foreach (var assetInfo in temper)
|
||||||
{
|
{
|
||||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public class AssetBundleCollectorSettingData
|
public class AssetBundleCollectorSettingData
|
||||||
{
|
{
|
||||||
|
private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>();
|
||||||
|
private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>();
|
||||||
|
|
||||||
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
||||||
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
||||||
|
|
||||||
@@ -35,6 +38,18 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<string> GetActiveRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<string> names = new List<string>();
|
||||||
|
foreach (var pair in _cacheActiveRuleTypes)
|
||||||
|
{
|
||||||
|
names.Add(pair.Key);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
public static List<string> GetAddressRuleNames()
|
public static List<string> GetAddressRuleNames()
|
||||||
{
|
{
|
||||||
if (_setting == null)
|
if (_setting == null)
|
||||||
@@ -71,6 +86,15 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
public static bool HasActiveRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
foreach (var pair in _cacheActiveRuleTypes)
|
||||||
|
{
|
||||||
|
if (pair.Key == ruleName)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public static bool HasAddressRuleName(string ruleName)
|
public static bool HasAddressRuleName(string ruleName)
|
||||||
{
|
{
|
||||||
foreach (var pair in _cacheAddressRuleTypes)
|
foreach (var pair in _cacheAddressRuleTypes)
|
||||||
@@ -182,6 +206,29 @@ namespace YooAsset.Editor
|
|||||||
_cacheAddressRuleTypes.Add(type.Name, type);
|
_cacheAddressRuleTypes.Add(type.Name, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IActiveRule
|
||||||
|
{
|
||||||
|
// 清空缓存集合
|
||||||
|
_cacheActiveRuleTypes.Clear();
|
||||||
|
_cacheActiveRuleInstance.Clear();
|
||||||
|
|
||||||
|
// 获取所有类型
|
||||||
|
List<Type> types = new List<Type>(100)
|
||||||
|
{
|
||||||
|
typeof(EnableGroup),
|
||||||
|
typeof(DisableGroup),
|
||||||
|
};
|
||||||
|
|
||||||
|
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
|
||||||
|
types.AddRange(customTypes);
|
||||||
|
for (int i = 0; i < types.Count; i++)
|
||||||
|
{
|
||||||
|
Type type = types[i];
|
||||||
|
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
|
||||||
|
_cacheActiveRuleTypes.Add(type.Name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -210,6 +257,23 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 实例类相关
|
// 实例类相关
|
||||||
|
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||||
|
{
|
||||||
|
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||||
|
return instance;
|
||||||
|
|
||||||
|
// 如果不存在创建类的实例
|
||||||
|
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
|
||||||
|
{
|
||||||
|
instance = (IActiveRule)Activator.CreateInstance(type);
|
||||||
|
_cacheActiveRuleInstance.Add(ruleName, instance);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||||
{
|
{
|
||||||
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
||||||
|
|||||||
@@ -18,12 +18,15 @@ namespace YooAsset.Editor
|
|||||||
window.minSize = new Vector2(800, 600);
|
window.minSize = new Vector2(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Button _saveButton;
|
||||||
private List<string> _collectorTypeList;
|
private List<string> _collectorTypeList;
|
||||||
|
private List<string> _activeRuleList;
|
||||||
private List<string> _addressRuleList;
|
private List<string> _addressRuleList;
|
||||||
private List<string> _packRuleList;
|
private List<string> _packRuleList;
|
||||||
private List<string> _filterRuleList;
|
private List<string> _filterRuleList;
|
||||||
private ListView _groupListView;
|
private ListView _groupListView;
|
||||||
private ScrollView _collectorScrollView;
|
private ScrollView _collectorScrollView;
|
||||||
|
private PopupField<string> _activeRulePopupField;
|
||||||
private Toggle _enableAddressableToogle;
|
private Toggle _enableAddressableToogle;
|
||||||
private Toggle _autoCollectShaderToogle;
|
private Toggle _autoCollectShaderToogle;
|
||||||
private TextField _shaderBundleNameTxt;
|
private TextField _shaderBundleNameTxt;
|
||||||
@@ -47,6 +50,7 @@ namespace YooAsset.Editor
|
|||||||
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
||||||
$"{nameof(ECollectorType.DependAssetCollector)}"
|
$"{nameof(ECollectorType.DependAssetCollector)}"
|
||||||
};
|
};
|
||||||
|
_activeRuleList = AssetBundleCollectorSettingData.GetActiveRuleNames();
|
||||||
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||||
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||||
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||||
@@ -57,7 +61,7 @@ namespace YooAsset.Editor
|
|||||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
|
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
|
||||||
if (visualAsset == null)
|
if (visualAsset == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
visualAsset.CloneTree(root);
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
// 导入导出按钮
|
// 导入导出按钮
|
||||||
@@ -66,11 +70,16 @@ namespace YooAsset.Editor
|
|||||||
var importBtn = root.Q<Button>("ImportButton");
|
var importBtn = root.Q<Button>("ImportButton");
|
||||||
importBtn.clicked += ImportBtn_clicked;
|
importBtn.clicked += ImportBtn_clicked;
|
||||||
|
|
||||||
|
// 配置保存按钮
|
||||||
|
_saveButton = root.Q<Button>("SaveButton");
|
||||||
|
_saveButton.clicked += SaveBtn_clicked;
|
||||||
|
|
||||||
// 公共设置相关
|
// 公共设置相关
|
||||||
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
|
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
|
||||||
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
|
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
|
||||||
{
|
{
|
||||||
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
||||||
|
RefreshWindow();
|
||||||
});
|
});
|
||||||
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
||||||
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
||||||
@@ -154,6 +163,25 @@ namespace YooAsset.Editor
|
|||||||
addBtn.clicked += AddCollectorBtn_clicked;
|
addBtn.clicked += AddCollectorBtn_clicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分组激活规则
|
||||||
|
var activeRuleContainer = root.Q("ActiveRuleContainer");
|
||||||
|
{
|
||||||
|
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
|
||||||
|
_activeRulePopupField.name = "ActiveRuleMaskField";
|
||||||
|
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
|
activeRuleContainer.Add(_activeRulePopupField);
|
||||||
|
_activeRulePopupField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup != null)
|
||||||
|
{
|
||||||
|
selectGroup.ActiveRuleName = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
|
||||||
|
FillGroupViewData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 刷新窗体
|
// 刷新窗体
|
||||||
RefreshWindow();
|
RefreshWindow();
|
||||||
}
|
}
|
||||||
@@ -170,6 +198,22 @@ namespace YooAsset.Editor
|
|||||||
if (AssetBundleCollectorSettingData.IsDirty)
|
if (AssetBundleCollectorSettingData.IsDirty)
|
||||||
AssetBundleCollectorSettingData.SaveFile();
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
}
|
}
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (_saveButton != null)
|
||||||
|
{
|
||||||
|
if (AssetBundleCollectorSettingData.IsDirty)
|
||||||
|
{
|
||||||
|
if (_saveButton.enabledSelf == false)
|
||||||
|
_saveButton.SetEnabled(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_saveButton.enabledSelf)
|
||||||
|
_saveButton.SetEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RefreshWindow()
|
private void RefreshWindow()
|
||||||
{
|
{
|
||||||
@@ -198,6 +242,10 @@ namespace YooAsset.Editor
|
|||||||
RefreshWindow();
|
RefreshWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void SaveBtn_clicked()
|
||||||
|
{
|
||||||
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
// 分组列表相关
|
// 分组列表相关
|
||||||
private void FillGroupViewData()
|
private void FillGroupViewData()
|
||||||
@@ -242,6 +290,11 @@ namespace YooAsset.Editor
|
|||||||
textField1.text = group.GroupName;
|
textField1.text = group.GroupName;
|
||||||
else
|
else
|
||||||
textField1.text = $"{group.GroupName} ({group.GroupDesc})";
|
textField1.text = $"{group.GroupName} ({group.GroupDesc})";
|
||||||
|
|
||||||
|
// 激活状态
|
||||||
|
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(group.ActiveRuleName);
|
||||||
|
bool isActive = activeRule.IsActiveGroup();
|
||||||
|
textField1.SetEnabled(isActive);
|
||||||
}
|
}
|
||||||
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
|
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
|
||||||
{
|
{
|
||||||
@@ -276,6 +329,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
_lastModifyGroup = selectGroup.GroupName;
|
_lastModifyGroup = selectGroup.GroupName;
|
||||||
_groupContainer.visible = true;
|
_groupContainer.visible = true;
|
||||||
|
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
|
||||||
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
||||||
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
||||||
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
||||||
@@ -523,7 +577,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
collectAssetInfos = collector.GetAllCollectAssets(group);
|
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, group);
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||||
|
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
<ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||||
|
<ui:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
|
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 启用分组
|
||||||
|
/// </summary>
|
||||||
|
public class EnableGroup : IActiveRule
|
||||||
|
{
|
||||||
|
public bool IsActiveGroup()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 禁用分组
|
||||||
|
/// </summary>
|
||||||
|
public class DisableGroup : IActiveRule
|
||||||
|
{
|
||||||
|
public bool IsActiveGroup()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2cfd65b3b7663b247b2df16077f4ef17
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -44,10 +44,19 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public bool IsCollectAsset(FilterRuleData data)
|
public bool IsCollectAsset(FilterRuleData data)
|
||||||
{
|
{
|
||||||
if (AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath) == typeof(Sprite))
|
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||||
return true;
|
if(mainAssetType == typeof(Texture2D))
|
||||||
|
{
|
||||||
|
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||||
|
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,8 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PackDirectory : IPackRule
|
public class PackDirectory : IPackRule
|
||||||
{
|
{
|
||||||
|
public static PackDirectory StaticPackRule = new PackDirectory();
|
||||||
|
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
return Path.GetDirectoryName(data.AssetPath);
|
return Path.GetDirectoryName(data.AssetPath);
|
||||||
|
|||||||
14
Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs
Normal file
14
Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源分组激活规则接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IActiveRule
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否激活分组
|
||||||
|
/// </summary>
|
||||||
|
bool IsActiveGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aed5a1a6733b7d44ca4f6149ed5a2bb8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,144 +1,298 @@
|
|||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
using UnityEditor.UIElements;
|
using UnityEditor.UIElements;
|
||||||
|
using UnityEditor.Networking.PlayerConnection;
|
||||||
|
using UnityEngine.Networking.PlayerConnection;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class AssetBundleDebuggerWindow : EditorWindow
|
public class AssetBundleDebuggerWindow : EditorWindow
|
||||||
{
|
{
|
||||||
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
||||||
public static void ShowExample()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
||||||
wnd.minSize = new Vector2(800, 600);
|
wnd.minSize = new Vector2(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 视图模式
|
/// 视图模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private enum EViewMode
|
private enum EViewMode
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内存视图
|
/// 内存视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
MemoryView,
|
MemoryView,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源对象视图
|
/// 资源对象视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
AssetView,
|
AssetView,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包视图
|
/// 资源包视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BundleView,
|
BundleView,
|
||||||
}
|
}
|
||||||
|
|
||||||
private ToolbarMenu _viewModeMenu;
|
|
||||||
private DebuggerAssetListViewer _assetListViewer;
|
|
||||||
private DebuggerBundleListViewer _bundleListViewer;
|
|
||||||
|
|
||||||
private EViewMode _viewMode;
|
|
||||||
private readonly DebugReport _debugReport = new DebugReport();
|
|
||||||
private string _searchKeyWord;
|
|
||||||
|
|
||||||
|
|
||||||
public void CreateGUI()
|
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
|
||||||
{
|
|
||||||
|
private Label _playerName;
|
||||||
|
private ToolbarMenu _viewModeMenu;
|
||||||
|
private SliderInt _frameSlider;
|
||||||
|
private DebuggerAssetListViewer _assetListViewer;
|
||||||
|
private DebuggerBundleListViewer _bundleListViewer;
|
||||||
|
|
||||||
|
private EViewMode _viewMode;
|
||||||
|
private string _searchKeyWord;
|
||||||
|
private DebugReport _currentReport;
|
||||||
|
private RemotePlayerSession _currentPlayerSession;
|
||||||
|
private int _rangeIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public void CreateGUI()
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
VisualElement root = rootVisualElement;
|
VisualElement root = rootVisualElement;
|
||||||
|
|
||||||
// 加载布局文件
|
// 加载布局文件
|
||||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
|
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
|
||||||
if (visualAsset == null)
|
if (visualAsset == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
visualAsset.CloneTree(root);
|
|
||||||
|
|
||||||
// 采样按钮
|
visualAsset.CloneTree(root);
|
||||||
var sampleBtn = root.Q<Button>("SampleButton");
|
|
||||||
sampleBtn.clicked += SampleBtn_onClick;
|
|
||||||
|
|
||||||
// 视口模式菜单
|
// 采样按钮
|
||||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
var sampleBtn = root.Q<Button>("SampleButton");
|
||||||
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
sampleBtn.clicked += SampleBtn_onClick;
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
|
||||||
|
|
||||||
// 搜索栏
|
// 用户列表菜单
|
||||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
_playerName = root.Q<Label>("PlayerName");
|
||||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
_playerName.text = "Editor player";
|
||||||
|
|
||||||
// 加载视图
|
// 视口模式菜单
|
||||||
_assetListViewer = new DebuggerAssetListViewer();
|
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||||
_assetListViewer.InitViewer();
|
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.AssetView);
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.BundleView);
|
||||||
|
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||||
|
|
||||||
// 加载视图
|
// 搜索栏
|
||||||
_bundleListViewer = new DebuggerBundleListViewer();
|
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||||
_bundleListViewer.InitViewer();
|
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||||
|
|
||||||
// 显示视图
|
// 帧数相关
|
||||||
_viewMode = EViewMode.AssetView;
|
{
|
||||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
_frameSlider = root.Q<SliderInt>("FrameSlider");
|
||||||
_assetListViewer.AttachParent(root);
|
_frameSlider.label = "Frame:";
|
||||||
}
|
_frameSlider.highValue = 0;
|
||||||
catch(Exception e)
|
_frameSlider.lowValue = 0;
|
||||||
|
_frameSlider.value = 0;
|
||||||
|
_frameSlider.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
OnFrameSliderChange(evt.newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
var frameLast = root.Q<ToolbarButton>("FrameLast");
|
||||||
|
frameLast.clicked += OnFrameLast_clicked;
|
||||||
|
|
||||||
|
var frameNext = root.Q<ToolbarButton>("FrameNext");
|
||||||
|
frameNext.clicked += OnFrameNext_clicked;
|
||||||
|
|
||||||
|
var frameClear = root.Q<ToolbarButton>("FrameClear");
|
||||||
|
frameClear.clicked += OnFrameClear_clicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_assetListViewer = new DebuggerAssetListViewer();
|
||||||
|
_assetListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_bundleListViewer = new DebuggerBundleListViewer();
|
||||||
|
_bundleListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 显示视图
|
||||||
|
_viewMode = EViewMode.AssetView;
|
||||||
|
_assetListViewer.AttachParent(root);
|
||||||
|
|
||||||
|
// 远程调试
|
||||||
|
EditorConnection.instance.Initialize();
|
||||||
|
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
|
||||||
|
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
|
||||||
|
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
|
||||||
|
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError(e.ToString());
|
Debug.LogError(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void SampleBtn_onClick()
|
public void OnDestroy()
|
||||||
{
|
{
|
||||||
YooAssets.GetDebugReport(_debugReport);
|
// 远程调试
|
||||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
|
||||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
|
||||||
}
|
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
|
||||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
_playerSessions.Clear();
|
||||||
{
|
}
|
||||||
_searchKeyWord = e.newValue;
|
|
||||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
private void OnHandleConnectionEvent(int playerId)
|
||||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
{
|
||||||
}
|
Debug.Log($"Game player connection : {playerId}");
|
||||||
private void ViewModeMenuAction1(DropdownMenuAction action)
|
_playerName.text = $"Connected player : {playerId}";
|
||||||
{
|
}
|
||||||
if (_viewMode != EViewMode.AssetView)
|
private void OnHandleDisconnectionEvent(int playerId)
|
||||||
{
|
{
|
||||||
_viewMode = EViewMode.AssetView;
|
Debug.Log($"Game player disconnection : {playerId}");
|
||||||
VisualElement root = this.rootVisualElement;
|
_playerName.text = $"Disconneced player : {playerId}";
|
||||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
}
|
||||||
_assetListViewer.AttachParent(root);
|
private void OnHandlePlayerMessage(MessageEventArgs args)
|
||||||
_bundleListViewer.DetachParent();
|
{
|
||||||
}
|
var debugReport = DebugReport.Deserialize(args.data);
|
||||||
}
|
OnHandleDebugReport(args.playerId, debugReport);
|
||||||
private void ViewModeMenuAction2(DropdownMenuAction action)
|
}
|
||||||
{
|
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
|
||||||
if (_viewMode != EViewMode.BundleView)
|
{
|
||||||
{
|
Debug.Log($"Handle player {playerId} debug report !");
|
||||||
_viewMode = EViewMode.BundleView;
|
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
|
||||||
VisualElement root = this.rootVisualElement;
|
_currentPlayerSession.AddDebugReport(debugReport);
|
||||||
_viewModeMenu.text = EViewMode.BundleView.ToString();
|
_frameSlider.highValue = _currentPlayerSession.MaxRangeValue;
|
||||||
_assetListViewer.DetachParent();
|
_frameSlider.value = _currentPlayerSession.MaxRangeValue;
|
||||||
_bundleListViewer.AttachParent(root);
|
UpdateFrameView(_currentPlayerSession);
|
||||||
}
|
}
|
||||||
}
|
private void OnFrameSliderChange(int sliderValue)
|
||||||
private DropdownMenuAction.Status ViewModeMenuFun1(DropdownMenuAction action)
|
{
|
||||||
{
|
if (_currentPlayerSession != null)
|
||||||
if (_viewMode == EViewMode.AssetView)
|
{
|
||||||
return DropdownMenuAction.Status.Checked;
|
_rangeIndex = _currentPlayerSession.ClampRangeIndex(sliderValue); ;
|
||||||
else
|
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||||
return DropdownMenuAction.Status.Normal;
|
}
|
||||||
}
|
}
|
||||||
private DropdownMenuAction.Status ViewModeMenuFun2(DropdownMenuAction action)
|
private void OnFrameLast_clicked()
|
||||||
{
|
{
|
||||||
if (_viewMode == EViewMode.BundleView)
|
if (_currentPlayerSession != null)
|
||||||
return DropdownMenuAction.Status.Checked;
|
{
|
||||||
else
|
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex - 1);
|
||||||
return DropdownMenuAction.Status.Normal;
|
_frameSlider.value = _rangeIndex;
|
||||||
}
|
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
private void OnFrameNext_clicked()
|
||||||
|
{
|
||||||
|
if (_currentPlayerSession != null)
|
||||||
|
{
|
||||||
|
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex + 1);
|
||||||
|
_frameSlider.value = _rangeIndex;
|
||||||
|
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void OnFrameClear_clicked()
|
||||||
|
{
|
||||||
|
if (_currentPlayerSession != null)
|
||||||
|
{
|
||||||
|
_frameSlider.label = $"Frame:";
|
||||||
|
_frameSlider.value = 0;
|
||||||
|
_frameSlider.lowValue = 0;
|
||||||
|
_frameSlider.highValue = 0;
|
||||||
|
_currentPlayerSession.ClearDebugReport();
|
||||||
|
_assetListViewer.ClearView();
|
||||||
|
_bundleListViewer.ClearView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
|
||||||
|
{
|
||||||
|
if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session))
|
||||||
|
{
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RemotePlayerSession newSession = new RemotePlayerSession(playerId);
|
||||||
|
_playerSessions.Add(playerId, newSession);
|
||||||
|
return newSession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateFrameView(RemotePlayerSession playerSession)
|
||||||
|
{
|
||||||
|
if (playerSession != null)
|
||||||
|
{
|
||||||
|
UpdateFrameView(playerSession, playerSession.MaxRangeValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void UpdateFrameView(RemotePlayerSession playerSession, int rangeIndex)
|
||||||
|
{
|
||||||
|
if (playerSession == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var debugReport = playerSession.GetDebugReport(rangeIndex);
|
||||||
|
if (debugReport != null)
|
||||||
|
{
|
||||||
|
_currentReport = debugReport;
|
||||||
|
_frameSlider.label = $"Frame: {debugReport.FrameCount}";
|
||||||
|
_assetListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||||
|
_bundleListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SampleBtn_onClick()
|
||||||
|
{
|
||||||
|
// 发送采集数据的命令
|
||||||
|
RemoteCommand command = new RemoteCommand();
|
||||||
|
command.CommandType = (int)ERemoteCommand.SampleOnce;
|
||||||
|
command.CommandParam = string.Empty;
|
||||||
|
byte[] data = RemoteCommand.Serialize(command);
|
||||||
|
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
|
||||||
|
RemoteDebuggerInRuntime.EditorRequestDebugReport();
|
||||||
|
}
|
||||||
|
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||||
|
{
|
||||||
|
_searchKeyWord = e.newValue;
|
||||||
|
if (_currentReport != null)
|
||||||
|
{
|
||||||
|
_assetListViewer.FillViewData(_currentReport, _searchKeyWord);
|
||||||
|
_bundleListViewer.FillViewData(_currentReport, _searchKeyWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void OnViewModeMenuChange(DropdownMenuAction action)
|
||||||
|
{
|
||||||
|
var viewMode = (EViewMode)action.userData;
|
||||||
|
if (_viewMode != viewMode)
|
||||||
|
{
|
||||||
|
_viewMode = viewMode;
|
||||||
|
VisualElement root = this.rootVisualElement;
|
||||||
|
_viewModeMenu.text = viewMode.ToString();
|
||||||
|
|
||||||
|
if (viewMode == EViewMode.AssetView)
|
||||||
|
{
|
||||||
|
_assetListViewer.AttachParent(root);
|
||||||
|
_bundleListViewer.DetachParent();
|
||||||
|
}
|
||||||
|
else if (viewMode == EViewMode.BundleView)
|
||||||
|
{
|
||||||
|
_assetListViewer.DetachParent();
|
||||||
|
_bundleListViewer.AttachParent(root);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException(viewMode.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private DropdownMenuAction.Status OnViewModeMenuStatusUpdate(DropdownMenuAction action)
|
||||||
|
{
|
||||||
|
var viewMode = (EViewMode)action.userData;
|
||||||
|
if (_viewMode == viewMode)
|
||||||
|
return DropdownMenuAction.Status.Checked;
|
||||||
|
else
|
||||||
|
return DropdownMenuAction.Status.Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex;">
|
<uie:Toolbar name="TopToolbar" style="display: flex;">
|
||||||
|
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: middle-left; padding-left: 5px;" />
|
||||||
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
||||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
|
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
|
<uie:Toolbar name="FrameToolbar">
|
||||||
|
<ui:SliderInt picking-mode="Ignore" label="Frame:" value="42" high-value="100" name="FrameSlider" style="flex-grow: 1;" />
|
||||||
|
<uie:ToolbarButton text=" << " display-tooltip-when-elided="true" name="FrameLast" />
|
||||||
|
<uie:ToolbarButton text=" >> " display-tooltip-when-elided="true" name="FrameNext" />
|
||||||
|
<uie:ToolbarButton text="Clear" display-tooltip-when-elided="true" name="FrameClear" />
|
||||||
|
</uie:Toolbar>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
internal class RemotePlayerSession
|
||||||
|
{
|
||||||
|
private readonly List<DebugReport> _reportList = new List<DebugReport>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户ID
|
||||||
|
/// </summary>
|
||||||
|
public int PlayerId { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存的报告最大数量
|
||||||
|
/// </summary>
|
||||||
|
public int MaxReportCount { private set; get; }
|
||||||
|
|
||||||
|
public int MinRangeValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int MaxRangeValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int index = _reportList.Count - 1;
|
||||||
|
if (index < 0)
|
||||||
|
index = 0;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RemotePlayerSession(int playerId, int maxReportCount = 1000)
|
||||||
|
{
|
||||||
|
PlayerId = playerId;
|
||||||
|
MaxReportCount = maxReportCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清理缓存数据
|
||||||
|
/// </summary>
|
||||||
|
public void ClearDebugReport()
|
||||||
|
{
|
||||||
|
_reportList.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加一个调试报告
|
||||||
|
/// </summary>
|
||||||
|
public void AddDebugReport(DebugReport report)
|
||||||
|
{
|
||||||
|
if (report == null)
|
||||||
|
Debug.LogWarning("Invalid debug report data !");
|
||||||
|
|
||||||
|
if (_reportList.Count >= MaxReportCount)
|
||||||
|
_reportList.RemoveAt(0);
|
||||||
|
_reportList.Add(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取调试报告
|
||||||
|
/// </summary>
|
||||||
|
public DebugReport GetDebugReport(int rangeIndex)
|
||||||
|
{
|
||||||
|
if (_reportList.Count == 0)
|
||||||
|
return null;
|
||||||
|
if (rangeIndex < 0 || rangeIndex >= _reportList.Count)
|
||||||
|
return null;
|
||||||
|
return _reportList[rangeIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 规范索引值
|
||||||
|
/// </summary>
|
||||||
|
public int ClampRangeIndex(int rangeIndex)
|
||||||
|
{
|
||||||
|
if (rangeIndex < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (rangeIndex > MaxRangeValue)
|
||||||
|
return MaxRangeValue;
|
||||||
|
|
||||||
|
return rangeIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 89b4ea90b9f7e474d9e80077656ef6c4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -47,6 +47,18 @@ namespace YooAsset.Editor
|
|||||||
_dependListView.bindItem = BindDependListViewItem;
|
_dependListView.bindItem = BindDependListViewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清空页面
|
||||||
|
/// </summary>
|
||||||
|
public void ClearView()
|
||||||
|
{
|
||||||
|
_debugReport = null;
|
||||||
|
_assetListView.Clear();
|
||||||
|
_assetListView.ClearSelection();
|
||||||
|
_assetListView.itemsSource.Clear();
|
||||||
|
_assetListView.Rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 填充页面数据
|
/// 填充页面数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -171,7 +183,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// Status
|
// Status
|
||||||
StyleColor textColor;
|
StyleColor textColor;
|
||||||
if (providerInfo.Status == ProviderBase.EStatus.Fail)
|
if (providerInfo.Status == (int)ProviderBase.EStatus.Fail)
|
||||||
textColor = new StyleColor(Color.yellow);
|
textColor = new StyleColor(Color.yellow);
|
||||||
else
|
else
|
||||||
textColor = label1.style.color;
|
textColor = label1.style.color;
|
||||||
|
|||||||
@@ -46,6 +46,18 @@ namespace YooAsset.Editor
|
|||||||
_usingListView.makeItem = MakeIncludeListViewItem;
|
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||||
_usingListView.bindItem = BindIncludeListViewItem;
|
_usingListView.bindItem = BindIncludeListViewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清空页面
|
||||||
|
/// </summary>
|
||||||
|
public void ClearView()
|
||||||
|
{
|
||||||
|
_debugReport = null;
|
||||||
|
_bundleListView.Clear();
|
||||||
|
_bundleListView.ClearSelection();
|
||||||
|
_bundleListView.itemsSource.Clear();
|
||||||
|
_bundleListView.Rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 填充页面数据
|
/// 填充页面数据
|
||||||
@@ -147,7 +159,7 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// Status
|
// Status
|
||||||
StyleColor textColor;
|
StyleColor textColor;
|
||||||
if (bundleInfo.Status == AssetBundleLoaderBase.EStatus.Failed)
|
if (bundleInfo.Status == (int)AssetBundleLoaderBase.EStatus.Failed)
|
||||||
textColor = new StyleColor(Color.yellow);
|
textColor = new StyleColor(Color.yellow);
|
||||||
else
|
else
|
||||||
textColor = label1.style.color;
|
textColor = label1.style.color;
|
||||||
|
|||||||
@@ -58,10 +58,13 @@ namespace YooAsset.Editor
|
|||||||
_buildReport = buildReport;
|
_buildReport = buildReport;
|
||||||
|
|
||||||
_items.Clear();
|
_items.Clear();
|
||||||
|
|
||||||
|
_items.Add(new ItemWrapper("YooAsset版本", buildReport.Summary.YooVersion));
|
||||||
_items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion));
|
_items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion));
|
||||||
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildTime));
|
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildDate));
|
||||||
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
|
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
|
||||||
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
|
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
|
||||||
|
_items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}"));
|
||||||
_items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}"));
|
_items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}"));
|
||||||
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}"));
|
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}"));
|
||||||
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
|
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
|
||||||
|
|||||||
@@ -73,7 +73,14 @@ namespace YooAsset.Editor
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (guids.Length != 1)
|
if (guids.Length != 1)
|
||||||
|
{
|
||||||
|
foreach (var guid in guids)
|
||||||
|
{
|
||||||
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||||
|
Debug.LogWarning($"Found multiple file : {path}");
|
||||||
|
}
|
||||||
throw new System.Exception($"Found multiple {settingType.Name} files !");
|
throw new System.Exception($"Found multiple {settingType.Name} files !");
|
||||||
|
}
|
||||||
|
|
||||||
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||||
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
|
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEditor.SceneManagement;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
@@ -265,6 +266,20 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region SceneUtility
|
||||||
|
public static bool HasDirtyScenes()
|
||||||
|
{
|
||||||
|
var sceneCount = EditorSceneManager.sceneCount;
|
||||||
|
for (var i = 0; i < sceneCount; ++i)
|
||||||
|
{
|
||||||
|
var scene = EditorSceneManager.GetSceneAt(i);
|
||||||
|
if (scene.isDirty)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 文件
|
#region 文件
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建文件所在的目录
|
/// 创建文件所在的目录
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ namespace YooAsset.Editor
|
|||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
|
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
|
||||||
{
|
{
|
||||||
|
// 先删除再保存,否则ShaderVariantCollection内容将无法及时刷新
|
||||||
|
AssetDatabase.DeleteAsset(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||||
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath);
|
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
"name": "YooAsset.Editor",
|
"name": "YooAsset.Editor",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"YooAsset"
|
"YooAsset",
|
||||||
|
"Unity.ScriptableBuildPipeline",
|
||||||
|
"Unity.ScriptableBuildPipeline.Editor"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ namespace YooAsset
|
|||||||
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
|
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
|
||||||
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
||||||
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||||
|
|
||||||
private static bool _simulationOnEditor;
|
private static bool _simulationOnEditor;
|
||||||
private static int _loadingMaxNumber;
|
private static int _loadingMaxNumber;
|
||||||
|
|
||||||
public static IDecryptionServices DecryptionServices { private set; get; }
|
public static IDecryptionServices DecryptionServices { private set; get; }
|
||||||
public static IBundleServices BundleServices { private set; get; }
|
public static IBundleServices BundleServices { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化资源系统
|
/// 初始化
|
||||||
/// 注意:在使用AssetSystem之前需要初始化
|
/// 注意:在使用AssetSystem之前需要初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||||
@@ -31,7 +31,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 轮询更新
|
/// 更新
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Update()
|
public static void Update()
|
||||||
{
|
{
|
||||||
@@ -63,6 +63,19 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销毁
|
||||||
|
/// </summary>
|
||||||
|
public static void DestroyAll()
|
||||||
|
{
|
||||||
|
_loaders.Clear();
|
||||||
|
_providers.Clear();
|
||||||
|
_sceneHandles.Clear();
|
||||||
|
|
||||||
|
DecryptionServices = null;
|
||||||
|
BundleServices = null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源回收(卸载引用计数为零的资源)
|
/// 资源回收(卸载引用计数为零的资源)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -321,9 +334,10 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 调试专属方法
|
#region 调试专属方法
|
||||||
internal static void GetDebugReport(DebugReport report)
|
internal static DebugReport GetDebugReport()
|
||||||
{
|
{
|
||||||
report.ClearAll();
|
DebugReport report = new DebugReport();
|
||||||
|
report.FrameCount = Time.frameCount;
|
||||||
report.BundleCount = _loaders.Count;
|
report.BundleCount = _loaders.Count;
|
||||||
report.AssetCount = _providers.Count;
|
report.AssetCount = _providers.Count;
|
||||||
|
|
||||||
@@ -334,8 +348,8 @@ namespace YooAsset
|
|||||||
providerInfo.SpawnScene = provider.SpawnScene;
|
providerInfo.SpawnScene = provider.SpawnScene;
|
||||||
providerInfo.SpawnTime = provider.SpawnTime;
|
providerInfo.SpawnTime = provider.SpawnTime;
|
||||||
providerInfo.RefCount = provider.RefCount;
|
providerInfo.RefCount = provider.RefCount;
|
||||||
providerInfo.Status = provider.Status;
|
providerInfo.Status = (int)provider.Status;
|
||||||
providerInfo.BundleInfos.Clear();
|
providerInfo.BundleInfos = new List<DebugBundleInfo>();
|
||||||
report.ProviderInfos.Add(providerInfo);
|
report.ProviderInfos.Add(providerInfo);
|
||||||
|
|
||||||
if (provider is BundledProvider)
|
if (provider is BundledProvider)
|
||||||
@@ -347,6 +361,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 重新排序
|
// 重新排序
|
||||||
report.ProviderInfos.Sort();
|
report.ProviderInfos.Sort();
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -49,6 +50,17 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源对象
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TAsset">资源类型</typeparam>
|
||||||
|
public TAsset GetAssetObject<TAsset>() where TAsset : UnityEngine.Object
|
||||||
|
{
|
||||||
|
if (IsValid == false)
|
||||||
|
return null;
|
||||||
|
return Provider.AssetObject as TAsset;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 等待异步执行完毕
|
/// 等待异步执行完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -117,20 +129,22 @@ namespace YooAsset
|
|||||||
if (Provider.AssetObject == null)
|
if (Provider.AssetObject == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
GameObject result;
|
||||||
if (setPositionRotation)
|
if (setPositionRotation)
|
||||||
{
|
{
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation);
|
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation);
|
||||||
else
|
else
|
||||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject);
|
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject);
|
||||||
else
|
else
|
||||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
|
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||||
{
|
{
|
||||||
@@ -139,4 +153,4 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal abstract void InvokeCallback();
|
internal abstract void InvokeCallback();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源信息
|
||||||
|
/// </summary>
|
||||||
|
public AssetInfo GetAssetInfo()
|
||||||
|
{
|
||||||
|
return _assetInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前状态
|
/// 当前状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -93,6 +102,20 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 句柄是否有效
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValidNoWarning
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Provider != null && Provider.IsDestroyed == false)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 释放句柄
|
/// 释放句柄
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -39,7 +40,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.None)
|
if (_steps == ESteps.None)
|
||||||
{
|
{
|
||||||
if(MainBundleInfo.IsInvalid)
|
if (MainBundleInfo.IsInvalid)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EStatus.Failed;
|
Status = EStatus.Failed;
|
||||||
@@ -116,7 +117,11 @@ namespace YooAsset
|
|||||||
if (AssetSystem.DecryptionServices == null)
|
if (AssetSystem.DecryptionServices == null)
|
||||||
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
|
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
|
||||||
|
|
||||||
ulong offset = AssetSystem.DecryptionServices.GetFileOffset();
|
DecryptionFileInfo fileInfo = new DecryptionFileInfo();
|
||||||
|
fileInfo.BundleName = MainBundleInfo.BundleName;
|
||||||
|
fileInfo.BundleHash = MainBundleInfo.Hash;
|
||||||
|
fileInfo.BundleCRC = MainBundleInfo.CRC;
|
||||||
|
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(fileInfo);
|
||||||
if (_isWaitForAsyncComplete)
|
if (_isWaitForAsyncComplete)
|
||||||
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
|
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
|
||||||
else
|
else
|
||||||
@@ -158,6 +163,21 @@ namespace YooAsset
|
|||||||
Status = EStatus.Failed;
|
Status = EStatus.Failed;
|
||||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}";
|
LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}";
|
||||||
YooLogger.Error(LastError);
|
YooLogger.Error(LastError);
|
||||||
|
|
||||||
|
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||||
|
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||||
|
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||||
|
{
|
||||||
|
string cacheLoadPath = MainBundleInfo.GetCacheLoadPath();
|
||||||
|
if (DownloadSystem.CheckContentIntegrity(EVerifyLevel.High, cacheLoadPath, MainBundleInfo.SizeBytes, MainBundleInfo.CRC) == false)
|
||||||
|
{
|
||||||
|
if (File.Exists(cacheLoadPath))
|
||||||
|
{
|
||||||
|
YooLogger.Error($"Delete the invalid cache file : {cacheLoadPath}");
|
||||||
|
File.Delete(cacheLoadPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -185,7 +205,7 @@ namespace YooAsset
|
|||||||
if (_isShowWaitForAsyncError == false)
|
if (_isShowWaitForAsyncError == false)
|
||||||
{
|
{
|
||||||
_isShowWaitForAsyncError = true;
|
_isShowWaitForAsyncError = true;
|
||||||
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {MainBundleInfo.BundleName} States : {Status}");
|
YooLogger.Error($"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.BundleName} from remote with sync load method !");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace YooAsset
|
|||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private float _tryTimer = 0;
|
private float _tryTimer = 0;
|
||||||
private string _webURL;
|
private string _webURL;
|
||||||
|
private bool _isShowWaitForAsyncError = false;
|
||||||
private UnityWebRequest _webRequest;
|
private UnityWebRequest _webRequest;
|
||||||
|
|
||||||
|
|
||||||
@@ -118,7 +119,11 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void WaitForAsyncComplete()
|
public override void WaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException($"WebGL platform not support {nameof(WaitForAsyncComplete)}");
|
if (_isShowWaitForAsyncError == false)
|
||||||
|
{
|
||||||
|
_isShowWaitForAsyncError = true;
|
||||||
|
YooLogger.Error($"WebGL platform not support {nameof(WaitForAsyncComplete)} ! Use the async load method instead of the sync load method !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ namespace YooAsset
|
|||||||
var bundleInfo = new DebugBundleInfo();
|
var bundleInfo = new DebugBundleInfo();
|
||||||
bundleInfo.BundleName = loader.MainBundleInfo.BundleName;
|
bundleInfo.BundleName = loader.MainBundleInfo.BundleName;
|
||||||
bundleInfo.RefCount = loader.RefCount;
|
bundleInfo.RefCount = loader.RefCount;
|
||||||
bundleInfo.Status = loader.Status;
|
bundleInfo.Status = (int)loader.Status;
|
||||||
output.Add(bundleInfo);
|
output.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ namespace YooAsset
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_handle.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_handle.AssetObject == null)
|
if (_handle.AssetObject == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
|
|||||||
@@ -203,7 +203,10 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadFromApk;
|
if (DownloadSystem.ContainsVerifyFile(_bundleInfo.Hash))
|
||||||
|
_steps = ESteps.CheckAndCopyFile;
|
||||||
|
else
|
||||||
|
_steps = ESteps.DownloadFromApk;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -235,7 +238,17 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.CheckAndCopyFile;
|
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||||
|
{
|
||||||
|
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||||
|
_steps = ESteps.CheckAndCopyFile;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "File content verify failed !";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_fileRequester.Dispose();
|
_fileRequester.Dispose();
|
||||||
}
|
}
|
||||||
@@ -342,7 +355,10 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadFromApk;
|
if (DownloadSystem.ContainsVerifyFile(_bundleInfo.Hash))
|
||||||
|
_steps = ESteps.CheckAndCopyFile;
|
||||||
|
else
|
||||||
|
_steps = ESteps.DownloadFromApk;
|
||||||
}
|
}
|
||||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||||
{
|
{
|
||||||
@@ -405,7 +421,17 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.CheckAndCopyFile;
|
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||||
|
{
|
||||||
|
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||||
|
_steps = ESteps.CheckAndCopyFile;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "File content verify failed !";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_fileRequester.Dispose();
|
_fileRequester.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
|||||||
var bundleInfo = new DebugBundleInfo();
|
var bundleInfo = new DebugBundleInfo();
|
||||||
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
|
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
|
||||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||||
bundleInfo.Status = OwnerBundle.Status;
|
bundleInfo.Status = (int)OwnerBundle.Status;
|
||||||
output.Add(bundleInfo);
|
output.Add(bundleInfo);
|
||||||
|
|
||||||
DependBundleGroup.GetBundleDebugInfos(output);
|
DependBundleGroup.GetBundleDebugInfos(output);
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
internal class DebugBundleInfo
|
internal class DebugBundleInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BundleName { set; get; }
|
public string BundleName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引用计数
|
/// 引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RefCount { set; get; }
|
public int RefCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载状态
|
/// 加载状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetBundleLoaderBase.EStatus Status { set; get; }
|
public int Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,37 +4,38 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
internal class DebugProviderInfo : IComparer<DebugProviderInfo>, IComparable<DebugProviderInfo>
|
internal class DebugProviderInfo : IComparer<DebugProviderInfo>, IComparable<DebugProviderInfo>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源对象路径
|
/// 资源对象路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AssetPath { set; get; }
|
public string AssetPath;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源出生的场景
|
/// 资源出生的场景
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SpawnScene { set; get; }
|
public string SpawnScene;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源出生的时间
|
/// 资源出生的时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SpawnTime { set; get; }
|
public string SpawnTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 引用计数
|
/// 引用计数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RefCount { set; get; }
|
public int RefCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载状态
|
/// 加载状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ProviderBase.EStatus Status { set; get; }
|
public int Status;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源包列表
|
/// 依赖的资源包列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly List<DebugBundleInfo> BundleInfos = new List<DebugBundleInfo>();
|
public List<DebugBundleInfo> BundleInfos;
|
||||||
|
|
||||||
public int CompareTo(DebugProviderInfo other)
|
public int CompareTo(DebugProviderInfo other)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,21 +1,49 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Text;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源系统调试信息
|
/// 资源系统调试信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
internal class DebugReport
|
internal class DebugReport
|
||||||
{
|
{
|
||||||
public readonly List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
|
public List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
|
||||||
public int BundleCount { set; get; }
|
|
||||||
public int AssetCount { set; get; }
|
|
||||||
|
|
||||||
public void ClearAll()
|
/// <summary>
|
||||||
{
|
/// 游戏帧
|
||||||
ProviderInfos.Clear();
|
/// </summary>
|
||||||
}
|
public int FrameCount;
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包总数
|
||||||
|
/// </summary>
|
||||||
|
public int BundleCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源对象总数
|
||||||
|
/// </summary>
|
||||||
|
public int AssetCount;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序列化
|
||||||
|
/// </summary>
|
||||||
|
public static byte[] Serialize(DebugReport debugReport)
|
||||||
|
{
|
||||||
|
return Encoding.UTF8.GetBytes(JsonUtility.ToJson(debugReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 反序列化
|
||||||
|
/// </summary>
|
||||||
|
public static DebugReport Deserialize(byte[] data)
|
||||||
|
{
|
||||||
|
return JsonUtility.FromJson<DebugReport>(Encoding.UTF8.GetString(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
45
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs
Normal file
45
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal enum ERemoteCommand
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 采样一次
|
||||||
|
/// </summary>
|
||||||
|
SampleOnce = 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal class RemoteCommand
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 命令类型
|
||||||
|
/// </summary>
|
||||||
|
public int CommandType;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 命令附加参数
|
||||||
|
/// </summary>
|
||||||
|
public string CommandParam;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序列化
|
||||||
|
/// </summary>
|
||||||
|
public static byte[] Serialize(RemoteCommand command)
|
||||||
|
{
|
||||||
|
return Encoding.UTF8.GetBytes(JsonUtility.ToJson(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 反序列化
|
||||||
|
/// </summary>
|
||||||
|
public static RemoteCommand Deserialize(byte[] data)
|
||||||
|
{
|
||||||
|
return JsonUtility.FromJson<RemoteCommand>(Encoding.UTF8.GetString(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs.meta
Normal file
11
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e79402f4d610fb4408aa6f8a94b09cb9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
12
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerDefine.cs
Normal file
12
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerDefine.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class RemoteDebuggerDefine
|
||||||
|
{
|
||||||
|
public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
|
||||||
|
public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3fd4f5f47edbfd54ba92427daf9ea3a4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
53
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerInRuntime.cs
Normal file
53
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerInRuntime.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking.PlayerConnection;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class RemoteDebuggerInRuntime : MonoBehaviour
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器下获取报告的回调
|
||||||
|
/// </summary>
|
||||||
|
public static Action<int, DebugReport> EditorHandleDebugReportCallback;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器下请求报告数据
|
||||||
|
/// </summary>
|
||||||
|
public static void EditorRequestDebugReport()
|
||||||
|
{
|
||||||
|
if(UnityEditor.EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
var report = AssetSystem.GetDebugReport();
|
||||||
|
EditorHandleDebugReportCallback?.Invoke(0, report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||||
|
}
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||||
|
}
|
||||||
|
private void OnHandleEditorMessage(MessageEventArgs args)
|
||||||
|
{
|
||||||
|
var command = RemoteCommand.Deserialize(args.data);
|
||||||
|
YooLogger.Log($"On handle remote command : {command.CommandType} Param : {command.CommandParam}");
|
||||||
|
if (command.CommandType == (int)ERemoteCommand.SampleOnce)
|
||||||
|
{
|
||||||
|
var debugReport = AssetSystem.GetDebugReport();
|
||||||
|
var data = DebugReport.Serialize(debugReport);
|
||||||
|
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgSendPlayerToEditor, data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException(command.CommandType.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 91030c545c99c944a846f6a9a2a0756a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -16,13 +16,16 @@ namespace YooAsset
|
|||||||
private static readonly List<string> _removeList = new List<string>(100);
|
private static readonly List<string> _removeList = new List<string>(100);
|
||||||
private static readonly Dictionary<string, string> _cachedHashList = new Dictionary<string, string>(1000);
|
private static readonly Dictionary<string, string> _cachedHashList = new Dictionary<string, string>(1000);
|
||||||
private static int _breakpointResumeFileSize = int.MaxValue;
|
private static int _breakpointResumeFileSize = int.MaxValue;
|
||||||
|
private static EVerifyLevel _verifyLevel = EVerifyLevel.High;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化
|
/// 初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Initialize(int breakpointResumeFileSize)
|
public static void Initialize(int breakpointResumeFileSize, EVerifyLevel verifyLevel)
|
||||||
{
|
{
|
||||||
_breakpointResumeFileSize = breakpointResumeFileSize;
|
_breakpointResumeFileSize = breakpointResumeFileSize;
|
||||||
|
_verifyLevel = verifyLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,7 +61,9 @@ namespace YooAsset
|
|||||||
downloader.Abort();
|
downloader.Abort();
|
||||||
}
|
}
|
||||||
_downloaderDic.Clear();
|
_downloaderDic.Clear();
|
||||||
YooLogger.Log("DownloadSystem destroy all !");
|
_removeList.Clear();
|
||||||
|
_cachedHashList.Clear();
|
||||||
|
_breakpointResumeFileSize = int.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,17 +148,18 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证文件完整性
|
/// <summary>
|
||||||
public static bool CheckContentIntegrity(BundleInfo bundleInfo)
|
/// 验证文件完整性
|
||||||
{
|
/// </summary>
|
||||||
return CheckContentIntegrity(bundleInfo.GetCacheLoadPath(), bundleInfo.SizeBytes, bundleInfo.CRC);
|
|
||||||
}
|
|
||||||
public static bool CheckContentIntegrity(PatchBundle patchBundle)
|
|
||||||
{
|
|
||||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
|
||||||
return CheckContentIntegrity(filePath, patchBundle.SizeBytes, patchBundle.CRC);
|
|
||||||
}
|
|
||||||
public static bool CheckContentIntegrity(string filePath, long size, string crc)
|
public static bool CheckContentIntegrity(string filePath, long size, string crc)
|
||||||
|
{
|
||||||
|
return CheckContentIntegrity(_verifyLevel, filePath, size, crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证文件完整性
|
||||||
|
/// </summary>
|
||||||
|
public static bool CheckContentIntegrity(EVerifyLevel verifyLevel, string filePath, long size, string crc)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -166,10 +172,17 @@ namespace YooAsset
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 再验证文件CRC
|
// 再验证文件CRC
|
||||||
string fileCRC = HashUtility.FileCRC32(filePath);
|
if (verifyLevel == EVerifyLevel.High)
|
||||||
return fileCRC == crc;
|
{
|
||||||
|
string fileCRC = HashUtility.FileCRC32(filePath);
|
||||||
|
return fileCRC == crc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ namespace YooAsset
|
|||||||
if (hasError == false)
|
if (hasError == false)
|
||||||
{
|
{
|
||||||
// 注意:如果文件验证失败需要删除文件
|
// 注意:如果文件验证失败需要删除文件
|
||||||
if (DownloadSystem.CheckContentIntegrity(_bundleInfo) == false)
|
|
||||||
|
if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false)
|
||||||
{
|
{
|
||||||
hasError = true;
|
hasError = true;
|
||||||
_lastError = $"Verification failed";
|
_lastError = $"Verification failed";
|
||||||
|
|||||||
19
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs
Normal file
19
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 下载文件校验等级
|
||||||
|
/// </summary>
|
||||||
|
public enum EVerifyLevel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 验证文件大小
|
||||||
|
/// </summary>
|
||||||
|
Low,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证文件大小和CRC
|
||||||
|
/// </summary>
|
||||||
|
High,
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs.meta
Normal file
11
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 02ad351eb8539da47a0c789e2f8c468f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -45,6 +45,17 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销毁异步操作系统
|
||||||
|
/// </summary>
|
||||||
|
public static void DestroyAll()
|
||||||
|
{
|
||||||
|
_operations.Clear();
|
||||||
|
_watch = null;
|
||||||
|
_maxTimeSlice = 0;
|
||||||
|
_frameTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 开始处理异步操作类
|
/// 开始处理异步操作类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public class AssetInfo
|
public class AssetInfo
|
||||||
@@ -41,11 +40,16 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal string Error { private set; get; }
|
internal string Error { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可寻址地址
|
||||||
|
/// </summary>
|
||||||
|
public string Address { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径
|
/// 资源路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AssetPath { private set; get; }
|
public string AssetPath { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源类型
|
/// 资源类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -63,6 +67,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
_patchAsset = patchAsset;
|
_patchAsset = patchAsset;
|
||||||
AssetType = assetType;
|
AssetType = assetType;
|
||||||
|
Address = patchAsset.Address;
|
||||||
AssetPath = patchAsset.AssetPath;
|
AssetPath = patchAsset.AssetPath;
|
||||||
Error = string.Empty;
|
Error = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -73,6 +78,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
_patchAsset = patchAsset;
|
_patchAsset = patchAsset;
|
||||||
AssetType = null;
|
AssetType = null;
|
||||||
|
Address = patchAsset.Address;
|
||||||
AssetPath = patchAsset.AssetPath;
|
AssetPath = patchAsset.AssetPath;
|
||||||
Error = string.Empty;
|
Error = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -80,6 +86,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_patchAsset = null;
|
_patchAsset = null;
|
||||||
AssetType = null;
|
AssetType = null;
|
||||||
|
Address = string.Empty;
|
||||||
AssetPath = string.Empty;
|
AssetPath = string.Empty;
|
||||||
Error = error;
|
Error = error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,11 +119,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 错误信息
|
|
||||||
/// </summary>
|
|
||||||
public string Error { private set; get; }
|
|
||||||
|
|
||||||
|
|
||||||
private BundleInfo()
|
private BundleInfo()
|
||||||
{
|
{
|
||||||
@@ -136,7 +131,6 @@ namespace YooAsset
|
|||||||
RemoteMainURL = mainURL;
|
RemoteMainURL = mainURL;
|
||||||
RemoteFallbackURL = fallbackURL;
|
RemoteFallbackURL = fallbackURL;
|
||||||
EditorAssetPath = string.Empty;
|
EditorAssetPath = string.Empty;
|
||||||
Error = string.Empty;
|
|
||||||
}
|
}
|
||||||
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath)
|
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath)
|
||||||
{
|
{
|
||||||
@@ -146,7 +140,6 @@ namespace YooAsset
|
|||||||
RemoteMainURL = string.Empty;
|
RemoteMainURL = string.Empty;
|
||||||
RemoteFallbackURL = string.Empty;
|
RemoteFallbackURL = string.Empty;
|
||||||
EditorAssetPath = editorAssetPath;
|
EditorAssetPath = editorAssetPath;
|
||||||
Error = string.Empty;
|
|
||||||
}
|
}
|
||||||
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
|
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
|
||||||
{
|
{
|
||||||
@@ -156,17 +149,6 @@ namespace YooAsset
|
|||||||
RemoteMainURL = string.Empty;
|
RemoteMainURL = string.Empty;
|
||||||
RemoteFallbackURL = string.Empty;
|
RemoteFallbackURL = string.Empty;
|
||||||
EditorAssetPath = string.Empty;
|
EditorAssetPath = string.Empty;
|
||||||
Error = string.Empty;
|
|
||||||
}
|
|
||||||
public BundleInfo(string error)
|
|
||||||
{
|
|
||||||
_patchBundle = null;
|
|
||||||
LoadMode = ELoadMode.None;
|
|
||||||
BundleName = string.Empty;
|
|
||||||
RemoteMainURL = string.Empty;
|
|
||||||
RemoteFallbackURL = string.Empty;
|
|
||||||
EditorAssetPath = string.Empty;
|
|
||||||
Error = error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ namespace YooAsset
|
|||||||
|
|
||||||
public delegate void OnDownloadOver(bool isSucceed);
|
public delegate void OnDownloadOver(bool isSucceed);
|
||||||
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
||||||
public delegate void OnDownloadFileFailed(string fileName);
|
public delegate void OnDownloadError(string fileName, string error);
|
||||||
|
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
||||||
|
|
||||||
private readonly int _downloadingMaxNumber;
|
private readonly int _downloadingMaxNumber;
|
||||||
private readonly int _failedTryAgain;
|
private readonly int _failedTryAgain;
|
||||||
private readonly List<BundleInfo> _downloadList;
|
private readonly List<BundleInfo> _downloadList;
|
||||||
private readonly List<BundleInfo> _loadFailedList = new List<BundleInfo>();
|
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||||
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>();
|
|
||||||
private readonly List<DownloaderBase> _removeList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
private readonly List<DownloaderBase> _removeList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||||
|
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||||
|
|
||||||
// 数据相关
|
// 数据相关
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
@@ -59,15 +60,20 @@ namespace YooAsset
|
|||||||
public OnDownloadOver OnDownloadOverCallback { set; get; }
|
public OnDownloadOver OnDownloadOverCallback { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当下载进度变化
|
/// 当下载进度发生变化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OnDownloadProgress OnDownloadProgressCallback { set; get; }
|
public OnDownloadProgress OnDownloadProgressCallback { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当文件下载失败
|
/// 当某个文件下载失败
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OnDownloadFileFailed OnDownloadFileFailedCallback { set; get; }
|
public OnDownloadError OnDownloadErrorCallback { set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当开始下载某个文件
|
||||||
|
/// </summary>
|
||||||
|
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -125,7 +131,7 @@ namespace YooAsset
|
|||||||
if (downloader.HasError())
|
if (downloader.HasError())
|
||||||
{
|
{
|
||||||
_removeList.Add(downloader);
|
_removeList.Add(downloader);
|
||||||
_loadFailedList.Add(bundleInfo);
|
_failedList.Add(downloader);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +158,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 动态创建新的下载器到最大数量限制
|
// 动态创建新的下载器到最大数量限制
|
||||||
// 注意:如果期间有下载失败的文件,暂停动态创建下载器
|
// 注意:如果期间有下载失败的文件,暂停动态创建下载器
|
||||||
if (_downloadList.Count > 0 && _loadFailedList.Count == 0)
|
if (_downloadList.Count > 0 && _failedList.Count == 0)
|
||||||
{
|
{
|
||||||
if (_isPause)
|
if (_isPause)
|
||||||
return;
|
return;
|
||||||
@@ -160,22 +166,25 @@ namespace YooAsset
|
|||||||
if (_downloaders.Count < _downloadingMaxNumber)
|
if (_downloaders.Count < _downloadingMaxNumber)
|
||||||
{
|
{
|
||||||
int index = _downloadList.Count - 1;
|
int index = _downloadList.Count - 1;
|
||||||
var operation = DownloadSystem.BeginDownload(_downloadList[index], _failedTryAgain);
|
var bundleInfo = _downloadList[index];
|
||||||
|
var operation = DownloadSystem.BeginDownload(bundleInfo, _failedTryAgain);
|
||||||
_downloaders.Add(operation);
|
_downloaders.Add(operation);
|
||||||
_downloadList.RemoveAt(index);
|
_downloadList.RemoveAt(index);
|
||||||
|
OnStartDownloadFileCallback?.Invoke(bundleInfo.BundleName, bundleInfo.SizeBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载结算
|
// 下载结算
|
||||||
if (_downloaders.Count == 0)
|
if (_downloaders.Count == 0)
|
||||||
{
|
{
|
||||||
if (_loadFailedList.Count > 0)
|
if (_failedList.Count > 0)
|
||||||
{
|
{
|
||||||
string fileName = _loadFailedList[0].BundleName;
|
var failedDownloader = _failedList[0];
|
||||||
|
string fileName = failedDownloader.GetBundleInfo().BundleName;
|
||||||
Error = $"Failed to download file : {fileName}";
|
Error = $"Failed to download file : {fileName}";
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
OnDownloadFileFailedCallback?.Invoke(fileName);
|
OnDownloadErrorCallback?.Invoke(fileName, failedDownloader.GetLastError());
|
||||||
OnDownloadOverCallback?.Invoke(false);
|
OnDownloadOverCallback?.Invoke(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -137,12 +137,14 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
InitCache,
|
InitCache,
|
||||||
Update,
|
LoadManifest,
|
||||||
|
CopyManifest,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HostPlayModeImpl _impl;
|
private readonly HostPlayModeImpl _impl;
|
||||||
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
private readonly AppManifestLoader _appManifestLoader = new AppManifestLoader();
|
||||||
|
private readonly AppManifestCopyer _appManifestCopyer = new AppManifestCopyer();
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
||||||
@@ -176,10 +178,10 @@ namespace YooAsset
|
|||||||
// 更新缓存文件
|
// 更新缓存文件
|
||||||
CacheData.UpdateCache();
|
CacheData.UpdateCache();
|
||||||
}
|
}
|
||||||
_steps = ESteps.Update;
|
_steps = ESteps.LoadManifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.Update)
|
if (_steps == ESteps.LoadManifest)
|
||||||
{
|
{
|
||||||
_appManifestLoader.Update();
|
_appManifestLoader.Update();
|
||||||
Progress = _appManifestLoader.Progress();
|
Progress = _appManifestLoader.Progress();
|
||||||
@@ -194,10 +196,29 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
_impl.SetAppPatchManifest(_appManifestLoader.Result);
|
_impl.SetAppPatchManifest(_appManifestLoader.Result);
|
||||||
_impl.SetLocalPatchManifest(_appManifestLoader.Result);
|
_impl.SetLocalPatchManifest(_appManifestLoader.Result);
|
||||||
|
_appManifestCopyer.Init(_appManifestLoader.StaticVersion);
|
||||||
|
_steps = ESteps.CopyManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CopyManifest)
|
||||||
|
{
|
||||||
|
_appManifestCopyer.Update();
|
||||||
|
if (_appManifestCopyer.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_appManifestCopyer.Result == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _appManifestCopyer.Error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,14 +236,12 @@ namespace YooAsset
|
|||||||
CheckStaticVersion,
|
CheckStaticVersion,
|
||||||
LoadAppManifest,
|
LoadAppManifest,
|
||||||
CheckAppManifest,
|
CheckAppManifest,
|
||||||
Succeed,
|
Done,
|
||||||
Failed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ESteps _steps = ESteps.LoadStaticVersion;
|
private ESteps _steps = ESteps.LoadStaticVersion;
|
||||||
private UnityWebDataRequester _downloader1;
|
private UnityWebDataRequester _downloader1;
|
||||||
private UnityWebDataRequester _downloader2;
|
private UnityWebDataRequester _downloader2;
|
||||||
private int _staticVersion = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 错误日志
|
/// 错误日志
|
||||||
@@ -230,19 +249,21 @@ namespace YooAsset
|
|||||||
public string Error { private set; get; }
|
public string Error { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 补丁清单
|
/// 加载结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PatchManifest Result { private set; get; }
|
public PatchManifest Result { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置补丁清单版本号
|
||||||
|
/// </summary>
|
||||||
|
public int StaticVersion { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否已经完成
|
/// 是否已经完成
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDone()
|
public bool IsDone()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.Succeed || _steps == ESteps.Failed)
|
return _steps == ESteps.Done;
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -255,6 +276,9 @@ namespace YooAsset
|
|||||||
return _downloader2.Progress();
|
return _downloader2.Progress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新流程
|
||||||
|
/// </summary>
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (IsDone())
|
if (IsDone())
|
||||||
@@ -278,11 +302,11 @@ namespace YooAsset
|
|||||||
if (_downloader1.HasError())
|
if (_downloader1.HasError())
|
||||||
{
|
{
|
||||||
Error = _downloader1.GetError();
|
Error = _downloader1.GetError();
|
||||||
_steps = ESteps.Failed;
|
_steps = ESteps.Done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_staticVersion = int.Parse(_downloader1.GetText());
|
StaticVersion = int.Parse(_downloader1.GetText());
|
||||||
_steps = ESteps.LoadAppManifest;
|
_steps = ESteps.LoadAppManifest;
|
||||||
}
|
}
|
||||||
_downloader1.Dispose();
|
_downloader1.Dispose();
|
||||||
@@ -291,7 +315,7 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.LoadAppManifest)
|
if (_steps == ESteps.LoadAppManifest)
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Load application patch manifest.");
|
YooLogger.Log($"Load application patch manifest.");
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
string filePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(StaticVersion));
|
||||||
string url = PathHelper.ConvertToWWWPath(filePath);
|
string url = PathHelper.ConvertToWWWPath(filePath);
|
||||||
_downloader2 = new UnityWebDataRequester();
|
_downloader2 = new UnityWebDataRequester();
|
||||||
_downloader2.SendRequest(url);
|
_downloader2.SendRequest(url);
|
||||||
@@ -306,16 +330,108 @@ namespace YooAsset
|
|||||||
if (_downloader2.HasError())
|
if (_downloader2.HasError())
|
||||||
{
|
{
|
||||||
Error = _downloader2.GetError();
|
Error = _downloader2.GetError();
|
||||||
_steps = ESteps.Failed;
|
_steps = ESteps.Done;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 解析APP里的补丁清单
|
// 解析APP里的补丁清单
|
||||||
Result = PatchManifest.Deserialize(_downloader2.GetText());
|
Result = PatchManifest.Deserialize(_downloader2.GetText());
|
||||||
_steps = ESteps.Succeed;
|
_steps = ESteps.Done;
|
||||||
}
|
}
|
||||||
_downloader2.Dispose();
|
_downloader2.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置补丁清单复制器
|
||||||
|
/// </summary>
|
||||||
|
internal class AppManifestCopyer
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
CopyAppManifest,
|
||||||
|
CheckAppManifest,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private ESteps _steps = ESteps.CopyAppManifest;
|
||||||
|
private UnityWebFileRequester _downloader1;
|
||||||
|
private int _staticVersion;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 错误日志
|
||||||
|
/// </summary>
|
||||||
|
public string Error { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 拷贝结果
|
||||||
|
/// </summary>
|
||||||
|
public bool Result { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已经完成
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDone()
|
||||||
|
{
|
||||||
|
return _steps == ESteps.Done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化流程
|
||||||
|
/// </summary>
|
||||||
|
public void Init(int staticVersion)
|
||||||
|
{
|
||||||
|
_staticVersion = staticVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新流程
|
||||||
|
/// </summary>
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (IsDone())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CopyAppManifest)
|
||||||
|
{
|
||||||
|
string destFilePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
||||||
|
if (File.Exists(destFilePath))
|
||||||
|
{
|
||||||
|
Result = true;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
YooLogger.Log($"Copy application patch manifest.");
|
||||||
|
string sourceFilePath = PathHelper.MakeStreamingLoadPath(YooAssetSettingsData.GetPatchManifestFileName(_staticVersion));
|
||||||
|
string url = PathHelper.ConvertToWWWPath(sourceFilePath);
|
||||||
|
_downloader1 = new UnityWebFileRequester();
|
||||||
|
_downloader1.SendRequest(url, destFilePath);
|
||||||
|
_steps = ESteps.CheckAppManifest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckAppManifest)
|
||||||
|
{
|
||||||
|
if (_downloader1.IsDone() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_downloader1.HasError())
|
||||||
|
{
|
||||||
|
Result = false;
|
||||||
|
Error = _downloader1.GetError();
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Result = true;
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
}
|
||||||
|
_downloader1.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,10 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class UpdateManifestOperation : AsyncOperationBase
|
public abstract class UpdateManifestOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否发现了新的补丁清单
|
||||||
|
/// </summary>
|
||||||
|
public bool FoundNewManifest { protected set; get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,6 +69,7 @@ namespace YooAsset
|
|||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebDataRequester _downloader1;
|
private UnityWebDataRequester _downloader1;
|
||||||
private UnityWebDataRequester _downloader2;
|
private UnityWebDataRequester _downloader2;
|
||||||
|
private VerifyManager _verifyManager = new VerifyManager();
|
||||||
private float _verifyTime;
|
private float _verifyTime;
|
||||||
|
|
||||||
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
||||||
@@ -114,11 +119,13 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
||||||
LoadSandboxPatchManifest(_resourceVersion);
|
LoadSandboxPatchManifest(_resourceVersion);
|
||||||
|
FoundNewManifest = false;
|
||||||
_steps = ESteps.InitVerifyingCache;
|
_steps = ESteps.InitVerifyingCache;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
|
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
|
||||||
|
FoundNewManifest = true;
|
||||||
_steps = ESteps.LoadWebManifest;
|
_steps = ESteps.LoadWebManifest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,20 +172,20 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.InitVerifyingCache)
|
if (_steps == ESteps.InitVerifyingCache)
|
||||||
{
|
{
|
||||||
InitVerifyingCache();
|
_verifyManager.InitVerifyingCache(_impl.AppPatchManifest, _impl.LocalPatchManifest, false);
|
||||||
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
_steps = ESteps.UpdateVerifyingCache;
|
_steps = ESteps.UpdateVerifyingCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.UpdateVerifyingCache)
|
if (_steps == ESteps.UpdateVerifyingCache)
|
||||||
{
|
{
|
||||||
Progress = GetVerifyProgress();
|
Progress = _verifyManager.GetVerifyProgress();
|
||||||
if (UpdateVerifyingCache())
|
if (_verifyManager.UpdateVerifyingCache())
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
YooLogger.Log($"Verify result : Success {_verifySuccessCount}, Fail {_verifyFailCount}, Elapsed time {costTime} seconds");
|
YooLogger.Log($"Verify result : Success {_verifyManager.VerifySuccessCount}, Fail {_verifyManager.VerifyFailCount}, Elapsed time {costTime} seconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,8 +249,107 @@ namespace YooAsset
|
|||||||
else
|
else
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region 多线程相关
|
/// <summary>
|
||||||
|
/// 网络模式的更新清单操作(弱联网)
|
||||||
|
/// </summary>
|
||||||
|
internal sealed class HostPlayModeWeaklyUpdateManifestOperation : UpdateManifestOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadSandboxManifestHash,
|
||||||
|
InitVerifyingCache,
|
||||||
|
UpdateVerifyingCache,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly HostPlayModeImpl _impl;
|
||||||
|
private readonly int _resourceVersion;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
private VerifyManager _verifyManager = new VerifyManager();
|
||||||
|
private float _verifyTime;
|
||||||
|
|
||||||
|
internal HostPlayModeWeaklyUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion)
|
||||||
|
{
|
||||||
|
_impl = impl;
|
||||||
|
_resourceVersion = resourceVersion;
|
||||||
|
}
|
||||||
|
internal override void Start()
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadSandboxManifestHash;
|
||||||
|
}
|
||||||
|
internal override void Update()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadSandboxManifestHash)
|
||||||
|
{
|
||||||
|
LoadSandboxPatchManifest(_resourceVersion);
|
||||||
|
_steps = ESteps.InitVerifyingCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.InitVerifyingCache)
|
||||||
|
{
|
||||||
|
if (_verifyManager.InitVerifyingCache(_impl.AppPatchManifest, _impl.LocalPatchManifest, true))
|
||||||
|
{
|
||||||
|
_verifyTime = UnityEngine.Time.realtimeSinceStartup;
|
||||||
|
_steps = ESteps.UpdateVerifyingCache;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The resource version {_resourceVersion} content is not complete !";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.UpdateVerifyingCache)
|
||||||
|
{
|
||||||
|
Progress = _verifyManager.GetVerifyProgress();
|
||||||
|
if (_verifyManager.UpdateVerifyingCache())
|
||||||
|
{
|
||||||
|
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
|
||||||
|
YooLogger.Log($"Verify result : Success {_verifyManager.VerifySuccessCount}, Fail {_verifyManager.VerifyFailCount}, Elapsed time {costTime} seconds");
|
||||||
|
if (_verifyManager.VerifyFailCount > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The resource version {_resourceVersion} content has verify failed file !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载沙盒内的补丁清单
|
||||||
|
/// 注意:在加载本地补丁清单之前,未验证过文件的哈希值
|
||||||
|
/// </summary>
|
||||||
|
private void LoadSandboxPatchManifest(int updateResourceVersion)
|
||||||
|
{
|
||||||
|
string filePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
YooLogger.Log("Load sandbox patch manifest file.");
|
||||||
|
string jsonData = File.ReadAllText(filePath);
|
||||||
|
var sandboxPatchManifest = PatchManifest.Deserialize(jsonData);
|
||||||
|
_impl.SetLocalPatchManifest(sandboxPatchManifest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地缓存文件验证管理器
|
||||||
|
/// </summary>
|
||||||
|
internal class VerifyManager
|
||||||
|
{
|
||||||
private class ThreadInfo
|
private class ThreadInfo
|
||||||
{
|
{
|
||||||
public bool Result = false;
|
public bool Result = false;
|
||||||
@@ -261,13 +367,14 @@ namespace YooAsset
|
|||||||
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
|
||||||
private int _verifyMaxNum = 32;
|
private int _verifyMaxNum = 32;
|
||||||
private int _verifyTotalCount = 0;
|
private int _verifyTotalCount = 0;
|
||||||
private int _verifySuccessCount = 0;
|
|
||||||
private int _verifyFailCount = 0;
|
|
||||||
|
|
||||||
private void InitVerifyingCache()
|
public int VerifySuccessCount { private set; get; } = 0;
|
||||||
|
public int VerifyFailCount { private set; get; } = 0;
|
||||||
|
|
||||||
|
public bool InitVerifyingCache(PatchManifest appPatchManifest, PatchManifest localPatchManifest, bool weaklyUpdate)
|
||||||
{
|
{
|
||||||
// 遍历所有文件然后验证并缓存合法文件
|
// 遍历所有文件然后验证并缓存合法文件
|
||||||
foreach (var patchBundle in _impl.LocalPatchManifest.BundleList)
|
foreach (var patchBundle in localPatchManifest.BundleList)
|
||||||
{
|
{
|
||||||
// 忽略缓存文件
|
// 忽略缓存文件
|
||||||
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||||
@@ -275,18 +382,27 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (_impl.AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (appPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查看文件是否存在
|
// 注意:在弱联网模式下,我们需要验证指定资源版本的所有资源完整性
|
||||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
if (weaklyUpdate)
|
||||||
if (File.Exists(filePath) == false)
|
{
|
||||||
continue;
|
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||||
|
if (File.Exists(filePath))
|
||||||
_waitingList.Add(patchBundle);
|
_waitingList.Add(patchBundle);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
_waitingList.Add(patchBundle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置同时验证的最大数
|
// 设置同时验证的最大数
|
||||||
@@ -294,8 +410,9 @@ namespace YooAsset
|
|||||||
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
|
||||||
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
_verifyMaxNum = Math.Min(workerThreads, ioThreads);
|
||||||
_verifyTotalCount = _waitingList.Count;
|
_verifyTotalCount = _waitingList.Count;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
private bool UpdateVerifyingCache()
|
public bool UpdateVerifyingCache()
|
||||||
{
|
{
|
||||||
_syncContext.Update();
|
_syncContext.Update();
|
||||||
|
|
||||||
@@ -325,6 +442,13 @@ namespace YooAsset
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
public float GetVerifyProgress()
|
||||||
|
{
|
||||||
|
if (_verifyTotalCount == 0)
|
||||||
|
return 1f;
|
||||||
|
return (float)(VerifySuccessCount + VerifyFailCount) / _verifyTotalCount;
|
||||||
|
}
|
||||||
|
|
||||||
private bool RunThread(PatchBundle patchBundle)
|
private bool RunThread(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||||
@@ -342,24 +466,17 @@ namespace YooAsset
|
|||||||
ThreadInfo info = (ThreadInfo)obj;
|
ThreadInfo info = (ThreadInfo)obj;
|
||||||
if (info.Result)
|
if (info.Result)
|
||||||
{
|
{
|
||||||
_verifySuccessCount++;
|
VerifySuccessCount++;
|
||||||
DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.BundleName);
|
DownloadSystem.CacheVerifyFile(info.Bundle.Hash, info.Bundle.BundleName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_verifyFailCount++;
|
VerifyFailCount++;
|
||||||
YooLogger.Warning($"Failed to verify file : {info.FilePath}");
|
YooLogger.Warning($"Failed to verify file : {info.FilePath}");
|
||||||
if (File.Exists(info.FilePath))
|
if (File.Exists(info.FilePath))
|
||||||
File.Delete(info.FilePath);
|
File.Delete(info.FilePath);
|
||||||
}
|
}
|
||||||
_verifyingList.Remove(info.Bundle);
|
_verifyingList.Remove(info.Bundle);
|
||||||
}
|
}
|
||||||
private float GetVerifyProgress()
|
|
||||||
{
|
|
||||||
if (_verifyTotalCount == 0)
|
|
||||||
return 1f;
|
|
||||||
return (float)(_verifySuccessCount + _verifyFailCount) / _verifyTotalCount;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (_impl.AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (_impl.AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ namespace YooAsset
|
|||||||
/// 资源包集合(提供BundleName获取PatchBundle)
|
/// 资源包集合(提供BundleName获取PatchBundle)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchBundle> Bundles = new Dictionary<string, PatchBundle>();
|
public readonly Dictionary<string, PatchBundle> BundleDic = new Dictionary<string, PatchBundle>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
/// 资源映射集合(提供AssetPath获取PatchAsset)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public readonly Dictionary<string, PatchAsset> Assets = new Dictionary<string, PatchAsset>();
|
public readonly Dictionary<string, PatchAsset> AssetDic = new Dictionary<string, PatchAsset>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径映射集合
|
/// 资源路径映射集合
|
||||||
@@ -117,7 +117,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string MappingToAssetPath(string location)
|
public string MappingToAssetPath(string location)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(location))
|
if (string.IsNullOrEmpty(location))
|
||||||
{
|
{
|
||||||
YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
|
YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
@@ -138,18 +138,18 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源包名称
|
/// 获取主资源包
|
||||||
/// 注意:传入的资源路径一定合法有效!
|
/// 注意:传入的资源路径一定合法有效!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GetBundleName(string assetPath)
|
public PatchBundle GetMainPatchBundle(string assetPath)
|
||||||
{
|
{
|
||||||
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
|
||||||
{
|
{
|
||||||
int bundleID = patchAsset.BundleID;
|
int bundleID = patchAsset.BundleID;
|
||||||
if (bundleID >= 0 && bundleID < BundleList.Count)
|
if (bundleID >= 0 && bundleID < BundleList.Count)
|
||||||
{
|
{
|
||||||
var patchBundle = BundleList[bundleID];
|
var patchBundle = BundleList[bundleID];
|
||||||
return patchBundle.BundleName;
|
return patchBundle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -166,17 +166,17 @@ namespace YooAsset
|
|||||||
/// 获取资源依赖列表
|
/// 获取资源依赖列表
|
||||||
/// 注意:传入的资源路径一定合法有效!
|
/// 注意:传入的资源路径一定合法有效!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] GetAllDependencies(string assetPath)
|
public PatchBundle[] GetAllDependencies(string assetPath)
|
||||||
{
|
{
|
||||||
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (AssetDic.TryGetValue(assetPath, out PatchAsset patchAsset))
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>(patchAsset.DependIDs.Length);
|
List<PatchBundle> result = new List<PatchBundle>(patchAsset.DependIDs.Length);
|
||||||
foreach (var dependID in patchAsset.DependIDs)
|
foreach (var dependID in patchAsset.DependIDs)
|
||||||
{
|
{
|
||||||
if (dependID >= 0 && dependID < BundleList.Count)
|
if (dependID >= 0 && dependID < BundleList.Count)
|
||||||
{
|
{
|
||||||
var dependPatchBundle = BundleList[dependID];
|
var dependPatchBundle = BundleList[dependID];
|
||||||
result.Add(dependPatchBundle.BundleName);
|
result.Add(dependPatchBundle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -191,6 +191,22 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试获取补丁资源
|
||||||
|
/// </summary>
|
||||||
|
public bool TryGetPatchAsset(string assetPath, out PatchAsset result)
|
||||||
|
{
|
||||||
|
return AssetDic.TryGetValue(assetPath, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试获取补丁资源包
|
||||||
|
/// </summary>
|
||||||
|
public bool TryGetPatchBundle(string bundleName, out PatchBundle result)
|
||||||
|
{
|
||||||
|
return BundleDic.TryGetValue(bundleName, out result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 序列化
|
/// 序列化
|
||||||
@@ -212,7 +228,7 @@ namespace YooAsset
|
|||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
patchBundle.ParseFlagsValue();
|
patchBundle.ParseFlagsValue();
|
||||||
patchManifest.Bundles.Add(patchBundle.BundleName, patchBundle);
|
patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssetList
|
// AssetList
|
||||||
@@ -220,10 +236,10 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
// 注意:我们不允许原始路径存在重名
|
// 注意:我们不允许原始路径存在重名
|
||||||
string assetPath = patchAsset.AssetPath;
|
string assetPath = patchAsset.AssetPath;
|
||||||
if (patchManifest.Assets.ContainsKey(assetPath))
|
if (patchManifest.AssetDic.ContainsKey(assetPath))
|
||||||
throw new Exception($"AssetPath have existed : {assetPath}");
|
throw new Exception($"AssetPath have existed : {assetPath}");
|
||||||
else
|
else
|
||||||
patchManifest.Assets.Add(assetPath, patchAsset);
|
patchManifest.AssetDic.Add(assetPath, patchAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchManifest;
|
return patchManifest;
|
||||||
|
|||||||
@@ -40,19 +40,13 @@ namespace YooAsset
|
|||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if(assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = _simulatePatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
var patchBundle = _simulatePatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
{
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
|
return bundleInfo;
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
@@ -64,7 +58,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (_simulatePatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (_simulatePatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -57,6 +57,16 @@ namespace YooAsset
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步更新补丁清单(弱联网)
|
||||||
|
/// </summary>
|
||||||
|
public UpdateManifestOperation WeaklyUpdatePatchManifestAsync(int resourceVersion)
|
||||||
|
{
|
||||||
|
var operation = new HostPlayModeWeaklyUpdateManifestOperation(this, resourceVersion);
|
||||||
|
OperationSystem.StartOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步更新资源包裹
|
/// 异步更新资源包裹
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -98,7 +108,7 @@ namespace YooAsset
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(used == false)
|
if (used == false)
|
||||||
{
|
{
|
||||||
YooLogger.Log($"Delete unused cache file : {fileInfo.Name}");
|
YooLogger.Log($"Delete unused cache file : {fileInfo.Name}");
|
||||||
File.Delete(fileInfo.FullName);
|
File.Delete(fileInfo.FullName);
|
||||||
@@ -126,7 +136,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
@@ -158,7 +168,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
@@ -205,21 +215,17 @@ namespace YooAsset
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
string mainBundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle))
|
PatchBundle mainBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
{
|
if (checkList.Contains(mainBundle) == false)
|
||||||
if (checkList.Contains(mainBundle) == false)
|
checkList.Add(mainBundle);
|
||||||
checkList.Add(mainBundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
foreach (var dependBundleName in dependBundleNames)
|
PatchBundle[] dependBundles = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
|
foreach (var dependBundle in dependBundles)
|
||||||
{
|
{
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle))
|
if (checkList.Contains(dependBundle) == false)
|
||||||
{
|
checkList.Add(dependBundle);
|
||||||
if (checkList.Contains(dependBundle) == false)
|
|
||||||
checkList.Add(dependBundle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +238,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
// 忽略APP资源
|
// 忽略APP资源
|
||||||
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
// 注意:如果是APP资源并且哈希值相同,则不需要下载
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
{
|
{
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
continue;
|
continue;
|
||||||
@@ -249,16 +255,60 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
|
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(AppPatchManifest, tags);
|
List<BundleInfo> unpcakList = GetUnpackListByTags(tags);
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
private List<BundleInfo> GetUnpackListByTags(string[] tags)
|
||||||
|
{
|
||||||
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
|
foreach (var patchBundle in AppPatchManifest.BundleList)
|
||||||
|
{
|
||||||
|
// 如果不是内置资源
|
||||||
|
if (patchBundle.IsBuildin == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 忽略缓存文件
|
||||||
|
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 查询DLC资源
|
||||||
|
if (patchBundle.HasTag(tags))
|
||||||
|
{
|
||||||
|
downloadList.Add(patchBundle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertToUnpackList(downloadList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建解压器
|
||||||
|
/// </summary>
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
|
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByAll(AppPatchManifest);
|
List<BundleInfo> unpcakList = GetUnpackListByAll();
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
private List<BundleInfo> GetUnpackListByAll()
|
||||||
|
{
|
||||||
|
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
||||||
|
foreach (var patchBundle in AppPatchManifest.BundleList)
|
||||||
|
{
|
||||||
|
// 如果不是内置资源
|
||||||
|
if (patchBundle.IsBuildin == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 忽略缓存文件
|
||||||
|
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
downloadList.Add(patchBundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertToUnpackList(downloadList);
|
||||||
|
}
|
||||||
|
|
||||||
// WEB相关
|
// WEB相关
|
||||||
public string GetPatchDownloadMainURL(string fileName)
|
public string GetPatchDownloadMainURL(string fileName)
|
||||||
@@ -290,6 +340,26 @@ namespace YooAsset
|
|||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解压相关
|
||||||
|
public List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
|
||||||
|
{
|
||||||
|
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
|
||||||
|
foreach (var patchBundle in unpackList)
|
||||||
|
{
|
||||||
|
var bundleInfo = ConvertToUnpackInfo(patchBundle);
|
||||||
|
result.Add(bundleInfo);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
||||||
|
{
|
||||||
|
// 注意:我们把流加载路径指定为远端下载地址
|
||||||
|
string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
||||||
|
streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
|
||||||
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
|
||||||
|
return bundleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
// 设置资源清单
|
// 设置资源清单
|
||||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
@@ -302,53 +372,51 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(string bundleName)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
if (patchBundle == null)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
// 查询沙盒资源
|
||||||
|
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
||||||
{
|
{
|
||||||
// 查询沙盒资源
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
|
||||||
if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash))
|
return bundleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询APP资源
|
||||||
|
if (AppPatchManifest.TryGetPatchBundle(patchBundle.BundleName, out PatchBundle appPatchBundle))
|
||||||
|
{
|
||||||
|
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
||||||
{
|
{
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromCache);
|
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||||
return bundleInfo;
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询APP资源
|
|
||||||
if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle))
|
|
||||||
{
|
|
||||||
if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
|
|
||||||
{
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(appPatchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从服务端下载
|
|
||||||
return ConvertToDownloadInfo(patchBundle);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从服务端下载
|
||||||
|
return ConvertToDownloadInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
return CreateBundleInfo(bundleName);
|
var patchBundle = LocalPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var bundleName in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
|
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
|
||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
@@ -359,7 +427,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (LocalPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (LocalPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -30,22 +30,6 @@ namespace YooAsset
|
|||||||
return _appPatchManifest.ResourceVersion;
|
return _appPatchManifest.ResourceVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建解压器
|
|
||||||
/// </summary>
|
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
|
||||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByTags(_appPatchManifest, tags);
|
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
|
||||||
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByAll(_appPatchManifest);
|
|
||||||
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置资源清单
|
// 设置资源清单
|
||||||
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
internal void SetAppPatchManifest(PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
@@ -54,36 +38,34 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region IBundleServices接口
|
#region IBundleServices接口
|
||||||
private BundleInfo CreateBundleInfo(string bundleName)
|
private BundleInfo CreateBundleInfo(PatchBundle patchBundle)
|
||||||
{
|
{
|
||||||
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
|
if (patchBundle == null)
|
||||||
{
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
}
|
|
||||||
|
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
||||||
|
return bundleInfo;
|
||||||
}
|
}
|
||||||
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath);
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
return CreateBundleInfo(bundleName);
|
var patchBundle = _appPatchManifest.GetMainPatchBundle(assetInfo.AssetPath);
|
||||||
|
return CreateBundleInfo(patchBundle);
|
||||||
}
|
}
|
||||||
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
// 注意:如果补丁清单里未找到资源包会抛出异常!
|
||||||
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
|
||||||
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
||||||
foreach (var bundleName in depends)
|
foreach (var patchBundle in depends)
|
||||||
{
|
{
|
||||||
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
|
BundleInfo bundleInfo = CreateBundleInfo(patchBundle);
|
||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
@@ -94,7 +76,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
|
||||||
{
|
{
|
||||||
if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
|
if (_appPatchManifest.TryGetPatchAsset(assetPath, out PatchAsset patchAsset))
|
||||||
return patchAsset;
|
return patchAsset;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
public struct DecryptionFileInfo
|
||||||
|
{
|
||||||
|
public string BundleName;
|
||||||
|
public string BundleHash;
|
||||||
|
public string BundleCRC;
|
||||||
|
}
|
||||||
|
|
||||||
public interface IDecryptionServices
|
public interface IDecryptionServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取加密文件的数据偏移量
|
/// 获取加密文件的数据偏移量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ulong GetFileOffset();
|
ulong GetFileOffset(DecryptionFileInfo fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string UnityManifestFileName = "UnityManifest";
|
public string UnityManifestFileName = "UnityManifest";
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建输出的报告文件
|
/// 构建输出的报告文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,5 +35,10 @@ namespace YooAsset
|
|||||||
/// 静态版本文件
|
/// 静态版本文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string VersionFileName = "StaticVersion.bytes";
|
public const string VersionFileName = "StaticVersion.bytes";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unity内置着色器资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public const string UnityBuiltInShadersBundleName = "UnityBuiltInShaders.bundle";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,72 +124,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class PatchHelper
|
internal static class PatchHelper
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 获取内置资源解压列表
|
|
||||||
/// </summary>
|
|
||||||
public static List<BundleInfo> GetUnpackListByTags(PatchManifest appPatchManifest, string[] tags)
|
|
||||||
{
|
|
||||||
// 注意:离线运行模式也依赖下面逻辑,所以判断沙盒内文件是否存在不能通过缓存系统去验证。
|
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
|
||||||
foreach (var patchBundle in appPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 如果已经在沙盒内
|
|
||||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
|
||||||
if (System.IO.File.Exists(filePath))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 如果不是内置资源
|
|
||||||
if (patchBundle.IsBuildin == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 查询DLC资源
|
|
||||||
if (patchBundle.HasTag(tags))
|
|
||||||
{
|
|
||||||
downloadList.Add(patchBundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConvertToUnpackList(downloadList);
|
|
||||||
}
|
|
||||||
public static List<BundleInfo> GetUnpackListByAll(PatchManifest appPatchManifest)
|
|
||||||
{
|
|
||||||
// 注意:离线运行模式也依赖下面逻辑,所以判断沙盒内文件是否存在不能通过缓存系统去验证。
|
|
||||||
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
|
|
||||||
foreach (var patchBundle in appPatchManifest.BundleList)
|
|
||||||
{
|
|
||||||
// 如果已经在沙盒内
|
|
||||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
|
||||||
if (System.IO.File.Exists(filePath))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// 如果不是内置资源
|
|
||||||
if (patchBundle.IsBuildin == false)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
downloadList.Add(patchBundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConvertToUnpackList(downloadList);
|
|
||||||
}
|
|
||||||
private static List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
|
|
||||||
{
|
|
||||||
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
|
|
||||||
foreach (var patchBundle in unpackList)
|
|
||||||
{
|
|
||||||
var bundleInfo = ConvertToUnpackInfo(patchBundle);
|
|
||||||
result.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
private static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
|
|
||||||
{
|
|
||||||
// 注意:我们把流加载路径指定为远端下载地址
|
|
||||||
string streamingPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash);
|
|
||||||
streamingPath = PathHelper.ConvertToWWWPath(streamingPath);
|
|
||||||
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, streamingPath, streamingPath);
|
|
||||||
return bundleInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源信息列表
|
/// 获取资源信息列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
void OnApplicationQuit()
|
void OnApplicationQuit()
|
||||||
{
|
{
|
||||||
DownloadSystem.DestroyAll();
|
YooAssets.InternalDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,11 +85,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class HostPlayModeParameters : InitializeParameters
|
public class HostPlayModeParameters : InitializeParameters
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 当缓存池被污染的时候清理缓存池
|
|
||||||
/// </summary>
|
|
||||||
public bool ClearCacheWhenDirty;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 默认的资源服务器下载地址
|
/// 默认的资源服务器下载地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -100,10 +95,20 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string FallbackHostServer;
|
public string FallbackHostServer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当缓存池被污染的时候清理缓存池
|
||||||
|
/// </summary>
|
||||||
|
public bool ClearCacheWhenDirty = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启用断点续传功能的文件大小
|
/// 启用断点续传功能的文件大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BreakpointResumeFileSize = int.MaxValue;
|
public int BreakpointResumeFileSize = int.MaxValue;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载文件校验等级
|
||||||
|
/// </summary>
|
||||||
|
public EVerifyLevel VerifyLevel = EVerifyLevel.High;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -118,6 +123,14 @@ namespace YooAsset
|
|||||||
private static HostPlayModeImpl _hostPlayModeImpl;
|
private static HostPlayModeImpl _hostPlayModeImpl;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已经初始化
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsInitialized
|
||||||
|
{
|
||||||
|
get { return _isInitialize; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步初始化
|
/// 异步初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -143,6 +156,10 @@ namespace YooAsset
|
|||||||
UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]");
|
UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]");
|
||||||
driverGo.AddComponent<YooAssetDriver>();
|
driverGo.AddComponent<YooAssetDriver>();
|
||||||
UnityEngine.Object.DontDestroyOnLoad(driverGo);
|
UnityEngine.Object.DontDestroyOnLoad(driverGo);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
driverGo.AddComponent<RemoteDebuggerInRuntime>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -181,7 +198,7 @@ namespace YooAsset
|
|||||||
throw new Exception($"{EPlayMode.HostPlayMode} not supports WebGL platform !");
|
throw new Exception($"{EPlayMode.HostPlayMode} not supports WebGL platform !");
|
||||||
#else
|
#else
|
||||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||||
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize);
|
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize, hostPlayModeParameters.VerifyLevel);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,6 +307,36 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 弱联网情况下加载补丁清单
|
||||||
|
/// 注意:当指定版本内容验证失败后会返回失败。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resourceVersion">指定的资源版本</param>
|
||||||
|
public static UpdateManifestOperation WeaklyUpdateManifestAsync(int resourceVersion)
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||||
|
{
|
||||||
|
var operation = new EditorPlayModeUpdateManifestOperation();
|
||||||
|
OperationSystem.StartOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||||
|
{
|
||||||
|
var operation = new OfflinePlayModeUpdateManifestOperation();
|
||||||
|
OperationSystem.StartOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else if (_playMode == EPlayMode.HostPlayMode)
|
||||||
|
{
|
||||||
|
return _hostPlayModeImpl.WeaklyUpdatePatchManifestAsync(resourceVersion);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 开启一个异步操作
|
/// 开启一个异步操作
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -409,6 +456,17 @@ namespace YooAsset
|
|||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _bundleServices.GetAssetInfos(tags);
|
return _bundleServices.GetAssetInfos(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="location">资源的定位地址</param>
|
||||||
|
/// <returns>如果location地址无效,则返回空字符串</returns>
|
||||||
|
public static string GetAssetPath(string location)
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
return _locationServices.ConvertLocationToAssetPath(location);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 场景加载
|
#region 场景加载
|
||||||
@@ -478,6 +536,15 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
|
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
|
||||||
|
if (bundleInfo.IsRawFile == false)
|
||||||
|
{
|
||||||
|
string error = $"Cannot load asset bundle file using {nameof(GetRawFileAsync)} interfaces !";
|
||||||
|
YooLogger.Warning(error);
|
||||||
|
RawFileOperation operation = new CompletedRawFileOperation(error, copyPath);
|
||||||
|
OperationSystem.StartOperaiton(operation);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||||
{
|
{
|
||||||
RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
|
RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
|
||||||
@@ -519,7 +586,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TObject">资源类型</typeparam>
|
/// <typeparam name="TObject">资源类型</typeparam>
|
||||||
/// <param name="location">资源的定位地址</param>
|
/// <param name="location">资源的定位地址</param>
|
||||||
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : class
|
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||||
@@ -554,7 +621,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TObject">资源类型</typeparam>
|
/// <typeparam name="TObject">资源类型</typeparam>
|
||||||
/// <param name="location">资源的定位地址</param>
|
/// <param name="location">资源的定位地址</param>
|
||||||
public static AssetOperationHandle LoadAssetAsync<TObject>(string location)
|
public static AssetOperationHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||||
@@ -599,7 +666,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TObject">资源类型</typeparam>
|
/// <typeparam name="TObject">资源类型</typeparam>
|
||||||
/// <param name="location">资源的定位地址</param>
|
/// <param name="location">资源的定位地址</param>
|
||||||
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location)
|
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||||
@@ -634,7 +701,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TObject">资源类型</typeparam>
|
/// <typeparam name="TObject">资源类型</typeparam>
|
||||||
/// <param name="location">资源的定位地址</param>
|
/// <param name="location">资源的定位地址</param>
|
||||||
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location)
|
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||||
@@ -813,7 +880,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||||
{
|
{
|
||||||
return _offlinePlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
|
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain);
|
||||||
|
return operation;
|
||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
else if (_playMode == EPlayMode.HostPlayMode)
|
||||||
{
|
{
|
||||||
@@ -841,7 +910,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||||
{
|
{
|
||||||
return _offlinePlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain);
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
|
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain);
|
||||||
|
return operation;
|
||||||
}
|
}
|
||||||
else if (_playMode == EPlayMode.HostPlayMode)
|
else if (_playMode == EPlayMode.HostPlayMode)
|
||||||
{
|
{
|
||||||
@@ -922,29 +993,30 @@ namespace YooAsset
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 内部方法
|
#region 内部方法
|
||||||
|
internal static void InternalDestroy()
|
||||||
|
{
|
||||||
|
_isInitialize = false;
|
||||||
|
_initializeError = string.Empty;
|
||||||
|
_initializeStatus = EOperationStatus.None;
|
||||||
|
|
||||||
|
_bundleServices = null;
|
||||||
|
_locationServices = null;
|
||||||
|
_editorSimulateModeImpl = null;
|
||||||
|
_offlinePlayModeImpl = null;
|
||||||
|
_hostPlayModeImpl = null;
|
||||||
|
|
||||||
|
OperationSystem.DestroyAll();
|
||||||
|
DownloadSystem.DestroyAll();
|
||||||
|
AssetSystem.DestroyAll();
|
||||||
|
YooLogger.Log("YooAssets destroy all !");
|
||||||
|
}
|
||||||
internal static void InternalUpdate()
|
internal static void InternalUpdate()
|
||||||
{
|
{
|
||||||
// 更新异步操作系统
|
|
||||||
OperationSystem.Update();
|
OperationSystem.Update();
|
||||||
|
|
||||||
// 更新下载管理系统
|
|
||||||
DownloadSystem.Update();
|
DownloadSystem.Update();
|
||||||
|
|
||||||
// 更新资源系统
|
|
||||||
AssetSystem.Update();
|
AssetSystem.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取调试信息
|
|
||||||
/// </summary>
|
|
||||||
internal static void GetDebugReport(DebugReport report)
|
|
||||||
{
|
|
||||||
if (report == null)
|
|
||||||
YooLogger.Error($"{nameof(DebugReport)} is null");
|
|
||||||
|
|
||||||
AssetSystem.GetDebugReport(report);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源定位地址转换为资源完整路径
|
/// 资源定位地址转换为资源完整路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.tuyoogame.yooasset",
|
"name": "com.tuyoogame.yooasset",
|
||||||
"displayName": "YooAsset",
|
"displayName": "YooAsset",
|
||||||
"version": "1.0.10",
|
"version": "1.2.0",
|
||||||
"unity": "2019.4",
|
"unity": "2019.4",
|
||||||
"description": "unity3d resources management system",
|
"description": "unity3d resources management system",
|
||||||
"author": {
|
"author": {
|
||||||
@@ -13,5 +13,10 @@
|
|||||||
"url": "https://github.com/tuyoogame/YooAsset.git"
|
"url": "https://github.com/tuyoogame/YooAsset.git"
|
||||||
},
|
},
|
||||||
"relatedPackages": {},
|
"relatedPackages": {},
|
||||||
"dependencies": {}
|
"dependencies": {
|
||||||
|
"com.unity.scriptablebuildpipeline": "1.20.2",
|
||||||
|
"com.unity.modules.assetbundle": "1.0.0",
|
||||||
|
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||||
|
"com.unity.modules.unitywebrequestassetbundle": "1.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,14 @@
|
|||||||
|
|
||||||
构建版本号,也是资源版本号,版本号必须大于零。
|
构建版本号,也是资源版本号,版本号必须大于零。
|
||||||
|
|
||||||
|
- **Build Pipeline**
|
||||||
|
|
||||||
|
构建管线
|
||||||
|
|
||||||
|
(1) BuiltinBuildPipeline: 传统的内置构建管线。
|
||||||
|
|
||||||
|
(2) ScriptableBuildPipeline: 可编程构建管线。
|
||||||
|
|
||||||
- **Build Mode**
|
- **Build Mode**
|
||||||
|
|
||||||
构建模式
|
构建模式
|
||||||
@@ -114,7 +122,8 @@ private static void BuildInternal(BuildTarget buildTarget)
|
|||||||
buildParameters.BuildinTags = "buildin";
|
buildParameters.BuildinTags = "buildin";
|
||||||
buildParameters.VerifyBuildingResult = true;
|
buildParameters.VerifyBuildingResult = true;
|
||||||
buildParameters.EnableAddressable = false;
|
buildParameters.EnableAddressable = false;
|
||||||
buildParameters.AppendFileExtension = false;
|
buildParameters.AppendFileExtension = false;
|
||||||
|
buildParameters.CopyBuildinTagFiles = true;
|
||||||
buildParameters.EncryptionServices = new GameEncryption();
|
buildParameters.EncryptionServices = new GameEncryption();
|
||||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,25 @@
|
|||||||
|
|
||||||
#### 资源分组
|
#### 资源分组
|
||||||
|
|
||||||
|
- Active Rule
|
||||||
|
|
||||||
|
激活规则,规则可以自定义扩展。下面是内置规则:
|
||||||
|
|
||||||
|
- EnableGroup 启用分组。
|
||||||
|
|
||||||
|
- DisableGroup 禁用分组。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
//自定义扩展范例
|
||||||
|
public class DisableGroup : IActiveRule
|
||||||
|
{
|
||||||
|
public bool IsActiveGroup()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
- Grouper Name
|
- Grouper Name
|
||||||
|
|
||||||
分组名称
|
分组名称
|
||||||
@@ -50,7 +69,13 @@
|
|||||||
|
|
||||||
- MainAssetCollector 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
- MainAssetCollector 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
||||||
- StaticAssetCollector 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
- StaticAssetCollector 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||||
- DependAssetCollector 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
- DependAssetCollector 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)(当依赖资源没有被任何主资源引用的时候,则会在打包的时候自动剔除)。
|
||||||
|
|
||||||
|
StaticAssetCollector收集器和DependAssetCollector收集器适合对资源进行定制化打包策略。
|
||||||
|
|
||||||
|
示例1:一个游戏的粒子特效的纹理会非常多,通常特效制作师会把这些纹理放到一个文件夹内管理。如果我们把这些纹理打进一个AssetBundle文件内,当下次更新的时候,如果新增或改动了一个纹理,那么就要上传整个纹理的AssetBundle文件。我们可以把特效纹理通过DependAssetCollector收集器进行收集并自定义打包规则,通过文件名称的首字母进行小粒度打包,这样一个AssetBundle文件会被拆分为26个AssetBundle文件。
|
||||||
|
|
||||||
|
示例2:当我们需要严格控制某个文件夹内的依赖资源打进同一个AssetBundle文件内,那么StaticAssetCollector收集器是最佳选择,该收集器收集的资源,无论是否被其它资源引用或被多个资源引用,这些资源都会按照设定的打包规则打包,且这些资源不会被处理为share资源包。
|
||||||
|
|
||||||
- **AddressRule**
|
- **AddressRule**
|
||||||
|
|
||||||
@@ -63,6 +88,7 @@
|
|||||||
- AddressByCollectorAndFileName 以收集器名+文件名为定位地址。
|
- AddressByCollectorAndFileName 以收集器名+文件名为定位地址。
|
||||||
|
|
||||||
````c#
|
````c#
|
||||||
|
//自定义扩展范例
|
||||||
public class AddressByFileName : IAddressRule
|
public class AddressByFileName : IAddressRule
|
||||||
{
|
{
|
||||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
# 调试器
|
# 调试器
|
||||||
|
|
||||||
调试器是在游戏运行时,帮助我们查看资源包加载信息的工具。可以查看资源对象列表信息(AssetView),资源包列表信息(BundleView)。
|
调试器是在游戏运行时,帮助我们查看资源包加载信息的工具,通过该工具可以发现潜在的资源泄漏。
|
||||||
|
|
||||||
未来计划支持在编辑器下通过远程调试真机信息。
|
可以查看资源对象列表信息(AssetView),资源包列表信息(BundleView)。
|
||||||
|
|
||||||
**注意**:该工具仅支持Unity2019+
|
**注意**:该工具仅支持Unity2019+
|
||||||
|
|
||||||
|
### 真机远程调试注意事项
|
||||||
|
|
||||||
|
在构建安装包的时候,需要勾选上Development Build和Autoconnect Profiler
|
||||||
|
|
||||||
### 资源对象列表视图
|
### 资源对象列表视图
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
````C#
|
````C#
|
||||||
// 资源系统初始化方法,根据不同的模式,我们传递不同的创建参数类
|
// 资源系统初始化方法,根据不同的模式,我们传递不同的创建参数类
|
||||||
YooAssets.InitializeAsync(CreateParameters parameters);
|
YooAssets.InitializeAsync(InitializeParameters parameters);
|
||||||
````
|
````
|
||||||
|
|
||||||
**编辑器模拟模式**
|
**编辑器模拟模式**
|
||||||
@@ -16,9 +16,9 @@ YooAssets.InitializeAsync(CreateParameters parameters);
|
|||||||
````c#
|
````c#
|
||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.EditorSimulateModeParameters();
|
var initParameters = new YooAssets.EditorSimulateModeParameters();
|
||||||
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
yield return YooAssets.InitializeAsync(initParameters);
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
@@ -31,9 +31,9 @@ private IEnumerator InitializeYooAsset()
|
|||||||
````c#
|
````c#
|
||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.OfflinePlayModeParameters();
|
var initParameters = new YooAssets.OfflinePlayModeParameters();
|
||||||
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
yield return YooAssets.InitializeAsync(initParameters);
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
@@ -59,16 +59,19 @@ private IEnumerator InitializeYooAsset()
|
|||||||
|
|
||||||
- FallbackHostServer : 备用的资源服务器IP地址。
|
- FallbackHostServer : 备用的资源服务器IP地址。
|
||||||
|
|
||||||
|
- VerifyLevel : 下载文件校验等级
|
||||||
|
|
||||||
````c#
|
````c#
|
||||||
private IEnumerator InitializeYooAsset()
|
private IEnumerator InitializeYooAsset()
|
||||||
{
|
{
|
||||||
var createParameters = new YooAssets.HostPlayModeParameters();
|
var initParameters = new YooAssets.HostPlayModeParameters();
|
||||||
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
createParameters.DecryptionServices = null;
|
initParameters.DecryptionServices = null;
|
||||||
createParameters.ClearCacheWhenDirty = false;
|
initParameters.ClearCacheWhenDirty = false;
|
||||||
createParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android";
|
initParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android";
|
||||||
createParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android";
|
initParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android";
|
||||||
yield return YooAssets.InitializeAsync(createParameters);
|
initParameters.VerifyLevel = EVerifyLevel.High;
|
||||||
|
yield return YooAssets.InitializeAsync(initParameters);
|
||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|||||||
@@ -86,9 +86,10 @@ IEnumerator Download()
|
|||||||
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||||
|
|
||||||
//注册回调方法
|
//注册回调方法
|
||||||
downloader.OnDownloadFileFailedCallback = OneDownloadFileFailed;
|
downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
|
||||||
downloader.OnDownloadProgressCallback = OnDownloadProgressUpdate;
|
downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
|
||||||
downloader.OnDownloadOverCallback = OnDownloadOver;
|
downloader.OnDownloadOverCallback = OnDownloadOverFunction;
|
||||||
|
downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
|
||||||
|
|
||||||
//开启下载
|
//开启下载
|
||||||
downloader.BeginDownload();
|
downloader.BeginDownload();
|
||||||
@@ -106,5 +107,48 @@ IEnumerator Download()
|
|||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
|
**弱联网更新解决方案**
|
||||||
|
|
||||||
|
对于偏单机但是也有资源热更需求的项目。当玩家本地网络不稳定或无网络的时候,我们又不希望玩家卡在资源更新步骤而不能正常游戏。所以当玩家本地网络有问题的时候,我们可以跳过资源更新的步骤。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
private IEnumerator UpdateStaticVersion()
|
||||||
|
{
|
||||||
|
UpdateStaticVersionOperation operation = YooAssets.UpdateStaticVersionAsync(10);
|
||||||
|
yield return operation;
|
||||||
|
if (operation.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
// 如果获取远端资源版本成功,说明当前网络连接并无问题,可以走正常更新流程。
|
||||||
|
......
|
||||||
|
|
||||||
|
// 注意:在成功下载所有资源之后,我们需要记录当前最新的资源版本号
|
||||||
|
PlayerPrefs.SetInt("STATIC_VERSION", resourceVersion);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果获取远端资源版本失败,我们走弱联网更新模式。
|
||||||
|
// 注意:如果从来没有保存过版本信息,则需要从内部读取StaticVersion.bytes文件的版本信息。
|
||||||
|
int staticVersion = PlayerPrefs.GetInt("STATIC_VERSION", -1);
|
||||||
|
if (staticVersion == -1)
|
||||||
|
{
|
||||||
|
staticVersion = LoadStaticVersionFromStreamingAssets();
|
||||||
|
PlayerPrefs.SetInt("STATIC_VERSION", staticVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在弱联网情况下更新补丁清单
|
||||||
|
UpdateManifestOperation operation2 = YooAssets.WeaklyUpdateManifestAsync(staticVersion);
|
||||||
|
yield return operation2;
|
||||||
|
if (operation2.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
StartGame();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 指定版本的资源内容本地并不完整,需要提示玩家更新。
|
||||||
|
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,42 @@
|
|||||||
# 资源加载
|
# 资源加载
|
||||||
|
|
||||||
加载方法:
|
**加载方法**
|
||||||
|
|
||||||
- YooAssets.LoadAssetSync() 同步加载资源对象
|
- YooAssets.LoadAssetSync() 同步加载资源对象
|
||||||
- YooAssets.LoadSubAssetsSync() 同步加载子资源对象
|
|
||||||
- YooAssets.LoadAssetAsync() 异步加载资源对象
|
- YooAssets.LoadAssetAsync() 异步加载资源对象
|
||||||
|
- YooAssets.LoadSubAssetsSync() 同步加载子资源对象
|
||||||
- YooAssets.LoadSubAssetsAsync() 异步加载子资源对象
|
- YooAssets.LoadSubAssetsAsync() 异步加载子资源对象
|
||||||
- YooAssets.LoadSceneAsync() 异步加载场景
|
- YooAssets.LoadSceneAsync() 异步加载场景
|
||||||
- YooAssets.GetRawFileAsync() 异步获取原生文件
|
- YooAssets.GetRawFileAsync() 异步获取原生文件
|
||||||
|
|
||||||
统一约定:location为资源的定位地址,也是加载资源对象的唯一标识符。
|
**统一约定**
|
||||||
|
|
||||||
DefaultLocationServices 默认资源定位服务,location代表的是资源对象的相对路径。
|
**Location**为资源的定位地址,也是加载资源对象的唯一标识符。
|
||||||
|
|
||||||
AddressLocationServices 可寻址资源定位服务,location代表的是资源对象可寻址地址。
|
- DefaultLocationServices 默认资源定位服务,location代表的是资源对象的相对路径。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
// 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3"
|
||||||
|
// 设定资源路径的根目录为:"Assets/GameRes",后续加载的资源定位地址填写相对路径:"Audio/bgMusic"
|
||||||
|
var createParameters = new YooAssets.EditorSimulateModeParameters();
|
||||||
|
createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes");
|
||||||
|
yield return YooAssets.InitializeAsync(createParameters);
|
||||||
|
......
|
||||||
|
YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic");
|
||||||
|
```
|
||||||
|
|
||||||
|
- AddressLocationServices 可寻址资源定位服务,location代表的是资源对象可寻址地址。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
// 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3"
|
||||||
|
// 需要在资源配置界面启用可寻址功能(Enable Addressable)。
|
||||||
|
// 配置界面的可寻址规则为AddressByFileName,那么资源定位地址填写文件名称:"bgMusic"
|
||||||
|
var createParameters = new YooAssets.EditorSimulateModeParameters();
|
||||||
|
createParameters.LocationServices = new AddressLocationServices();
|
||||||
|
yield return YooAssets.InitializeAsync(createParameters);
|
||||||
|
......
|
||||||
|
YooAssets.LoadAssetAsync<AudioClip>("bgMusic");
|
||||||
|
````
|
||||||
|
|
||||||
**注意**:以下范例执行环境是在DefaultLocationServices下。
|
**注意**:以下范例执行环境是在DefaultLocationServices下。
|
||||||
|
|
||||||
@@ -175,6 +198,9 @@ private object LoadFunc(string name, string extension, System.Type type, out Des
|
|||||||
return handle.AssetObject;
|
return handle.AssetObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行FairyGUI的添加包函数
|
||||||
|
UIPackage.AddPackage(name, LoadFunc);
|
||||||
|
|
||||||
// 释放资源句柄列表
|
// 释放资源句柄列表
|
||||||
private void ReleaseHandles()
|
private void ReleaseHandles()
|
||||||
{
|
{
|
||||||
|
|||||||
15
Docs/FAQ.md
15
Docs/FAQ.md
@@ -1,13 +1,24 @@
|
|||||||
# 常见问题解答
|
# 常见问题解答
|
||||||
|
|
||||||
### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
|
#### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
|
||||||
|
|
||||||
如果在打AssetBundle的时候,选定的构建目标是安卓。那么在windows操作系统下,编辑器的默认渲染模式为DX11,我们需要修改编辑器的渲染模式,可以通过UnityHub来修改启动项目的编辑器渲染模式,[参考官方文档](https://docs.unity3d.com/cn/2019.4/Manual/CommandLineArguments.html)。
|
如果在打AssetBundle的时候,选定的构建目标是安卓。那么在windows操作系统下,编辑器的默认渲染模式为DX11,我们需要修改编辑器的渲染模式,可以通过UnityHub来修改启动项目的编辑器渲染模式,[参考官方文档](https://docs.unity3d.com/cn/2019.4/Manual/CommandLineArguments.html)。
|
||||||
|
|
||||||
### 问题:YooAsset的DLL引用丢失导致编译报错了
|
windows平台添加命令: **-force-gles**
|
||||||
|
|
||||||
|
#### 问题:YooAsset的DLL引用丢失导致编译报错了
|
||||||
|
|
||||||
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
|
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
|
||||||
2. 关闭游戏工程后,删除Assets同级目录下所有的csproj文件和sln文件。
|
2. 关闭游戏工程后,删除Assets同级目录下所有的csproj文件和sln文件。
|
||||||
3. 删除Library/ScriptAssemblies文件夹。
|
3. 删除Library/ScriptAssemblies文件夹。
|
||||||
4. 重新打开游戏工程,然后点击某个脚本重新编译。
|
4. 重新打开游戏工程,然后点击某个脚本重新编译。
|
||||||
|
|
||||||
|
#### 问题:无效的资源路径,请检查路径是否带有特殊符号或中文:Assets/xxx/xxx/xxx
|
||||||
|
|
||||||
|
如果检查报错的文件路径内无特殊符合和中文字符,也可能是文件路径过长且文件名称带空格,在打包生成的manifest文件里文件路径被截断导致验证失败。
|
||||||
|
|
||||||
|
例如:Assets/My Game Res/JMO Assets/Cartoon FX Remaster/CFXR Assets/Shaders/CFXR Particle Glow.shader
|
||||||
|
|
||||||
|
解决方案1:缩短文件路径长度。
|
||||||
|
|
||||||
|
解决方案2:移除文件名称里的空格。
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 39 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user