mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
159 Commits
1.3.0-prev
...
1.4.0-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5197d42807 | ||
|
|
7a0f4caa9b | ||
|
|
5bf1d29edc | ||
|
|
2687466ed4 | ||
|
|
14512d6470 | ||
|
|
32268f5a4a | ||
|
|
81401ca0b8 | ||
|
|
688cc271d5 | ||
|
|
a290353cfa | ||
|
|
6038e7acd6 | ||
|
|
4abec5a389 | ||
|
|
a2b51a8044 | ||
|
|
19cb239746 | ||
|
|
7aab610be5 | ||
|
|
4ec5a126ac | ||
|
|
32643caf51 | ||
|
|
114ebab6ae | ||
|
|
d1463e1fc6 | ||
|
|
aa49980231 | ||
|
|
2696da092d | ||
|
|
5415d95f36 | ||
|
|
efa71c8bb7 | ||
|
|
d59df4c561 | ||
|
|
140bcb037f | ||
|
|
2a4384e093 | ||
|
|
5aafed85ed | ||
|
|
6ad4b91c60 | ||
|
|
cd62686316 | ||
|
|
dcd606e573 | ||
|
|
f6f326119c | ||
|
|
f31e5e0d22 | ||
|
|
abc12d2a1d | ||
|
|
b7e2f084b1 | ||
|
|
adf1776b1e | ||
|
|
fd1edcdedf | ||
|
|
ebc25c401d | ||
|
|
67574bf759 | ||
|
|
e94923c3c6 | ||
|
|
5718d57b88 | ||
|
|
82cff36194 | ||
|
|
3e4e2d5eb6 | ||
|
|
015f09d27b | ||
|
|
3fedc5b1b3 | ||
|
|
4776ab9bd8 | ||
|
|
3bb01ef9a8 | ||
|
|
0204f5f68f | ||
|
|
217d88beaa | ||
|
|
77080b3934 | ||
|
|
83f6dc2f76 | ||
|
|
29b3ca4e69 | ||
|
|
9394ff49fd | ||
|
|
49949ecda5 | ||
|
|
1dab0f2b19 | ||
|
|
1cf03bf049 | ||
|
|
c00594738f | ||
|
|
d5f601b0eb | ||
|
|
304bff1f19 | ||
|
|
ce9e0cd88c | ||
|
|
40903d9ad5 | ||
|
|
0fc97ad2f1 | ||
|
|
2bb66ea583 | ||
|
|
03aa9780eb | ||
|
|
d3a9005964 | ||
|
|
48bcf4a848 | ||
|
|
72f0426531 | ||
|
|
44ec5b3de3 | ||
|
|
292fdb1288 | ||
|
|
76e65286fd | ||
|
|
9397a0ebae | ||
|
|
c37b5e52ac | ||
|
|
ecfced7195 | ||
|
|
1c7a79f7d7 | ||
|
|
1149906786 | ||
|
|
9db111c08a | ||
|
|
0844447b46 | ||
|
|
c7116ad165 | ||
|
|
a805e0639e | ||
|
|
e8e69a2e86 | ||
|
|
3e4761a60f | ||
|
|
3413157c67 | ||
|
|
b5f2174ed0 | ||
|
|
bdc8285255 | ||
|
|
cd79f0e434 | ||
|
|
171f40551e | ||
|
|
ba4efebbce | ||
|
|
2486287a0e | ||
|
|
2599639aeb | ||
|
|
c1192b37c6 | ||
|
|
1f647163f2 | ||
|
|
cc04efe76b | ||
|
|
18426d0481 | ||
|
|
500b469bce | ||
|
|
49c242e7bc | ||
|
|
2d72d6dbc9 | ||
|
|
1f3e55ebea | ||
|
|
0ecb37419b | ||
|
|
c758bf6530 | ||
|
|
46d985a720 | ||
|
|
9404882fc7 | ||
|
|
ec1c3d6070 | ||
|
|
8eb7816e30 | ||
|
|
c196e44bc6 | ||
|
|
989d88f7d3 | ||
|
|
cb4ebb6306 | ||
|
|
92e7ec9682 | ||
|
|
32b7ff1b36 | ||
|
|
5a68ef558f | ||
|
|
18d48ae963 | ||
|
|
d61c723933 | ||
|
|
bb64ff7278 | ||
|
|
d7760cd34d | ||
|
|
f9ecad1cf0 | ||
|
|
a6de89ab74 | ||
|
|
e663dcf83b | ||
|
|
88e8e5cd54 | ||
|
|
9b43d36793 | ||
|
|
794314a8e1 | ||
|
|
0a1c40cee5 | ||
|
|
958cdd25a5 | ||
|
|
2fb77c1bf8 | ||
|
|
3aa46664f7 | ||
|
|
8389ce5793 | ||
|
|
5199430766 | ||
|
|
0afe5ada2c | ||
|
|
1774eb63b7 | ||
|
|
609cd21603 | ||
|
|
97fc65e66d | ||
|
|
ccac691701 | ||
|
|
a283c8bbad | ||
|
|
9bc5580229 | ||
|
|
eca5d73b94 | ||
|
|
fdacd5f3f8 | ||
|
|
c449a070b4 | ||
|
|
9e2efe3717 | ||
|
|
90ad292b84 | ||
|
|
f2422ed16c | ||
|
|
52ac982481 | ||
|
|
661c3a6d61 | ||
|
|
c14db5fd0d | ||
|
|
6116e49a05 | ||
|
|
8b6cd759ef | ||
|
|
e3f1ad79a8 | ||
|
|
b4c190efb7 | ||
|
|
bd11f2e7b8 | ||
|
|
1f26f001e9 | ||
|
|
ecd2bb4590 | ||
|
|
330eabcfc5 | ||
|
|
bd8ecab31b | ||
|
|
e9af0c7042 | ||
|
|
72a49d0ed8 | ||
|
|
66304c91ec | ||
|
|
c2192dd657 | ||
|
|
1de9e0b79d | ||
|
|
608f401a80 | ||
|
|
ef1acdc3d1 | ||
|
|
82631fb336 | ||
|
|
a348d9131d | ||
|
|
fc575f5bc0 | ||
|
|
e277649878 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -58,7 +58,4 @@ sysinfo.txt
|
||||
# Crashlytics generated file
|
||||
crashlytics-build.properties
|
||||
|
||||
*.vsconfig
|
||||
|
||||
Sandbox/
|
||||
Bundles/
|
||||
*.vsconfig
|
||||
@@ -2,6 +2,317 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.4.0-preview] - 2022-12-04
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#46)修复了资源包初始化失败之后,再次初始化发生异常的问题。
|
||||
- 修复了在初始化失败的之后,销毁YooAssets会报异常的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 优化了资源收集界面,可以选择显示中文别名。
|
||||
- **优化了补丁清单序列化方式,由文本数据修改为二进制数据。**
|
||||
- 资源操作句柄增加using支持。
|
||||
|
||||
## [1.3.7] - 2022-11-26
|
||||
|
||||
全新的太空战机Demo !
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#45)修复了package列表更新触发的异常。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了YooAssets.Destroy()资源系统销毁方法。
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// 销毁资源系统
|
||||
/// </summary>
|
||||
public static void Destroy();
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 优化了资源收集规则,原生文件打包名称现在已经包含文件后缀名。
|
||||
- 优化了资源收集规则,非原生文件收集器自动移除Unity无法识别的文件。
|
||||
- 优化了调试信息窗口,列表元素的加载状态显示为文本。
|
||||
|
||||
## [1.3.5] - 2022-11-19
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了同步接口加载加密文件失败的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了方法AssetsPackage.ClearPackageUnusedCacheFilesAsync()
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 清理本地包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public ClearPackageUnusedCacheFilesOperation ClearPackageUnusedCacheFilesAsync()
|
||||
```
|
||||
|
||||
- 新增了方法AssetsPackage.LoadRawFileAsync()
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 异步加载原生文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public RawFileOperationHandle LoadRawFileAsync(string location)
|
||||
```
|
||||
|
||||
- 新增了方法AssetsPackage.LoadRawFileSync()
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 同步加载原生文件
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public RawFileOperationHandle LoadRawFileSync(string location)
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 重命名AssetsPackage.UpdateStaticVersionAsync()为AssetsPackage.UpdatePackageVersionAsync();
|
||||
- 重命名AssetsPackage.UpdateManifestAsync()为AssetsPackage.UpdatePackageManifestAsync();
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了方法YooAssets.ClearUnusedCacheFiles()
|
||||
- 移除了方法AssetsPackage.GetRawFileAsync()
|
||||
|
||||
## [1.3.4] - 2022-11-04
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#29)修复了EditorHelper中根据guid找uxml有时候会出错的问题。
|
||||
- (#37)修复了在修改GroupName和GroupDesc时,左侧Group栏显示没刷新的问题。
|
||||
- (#38)修复了工程里没有shader的话,SBP构建会报异常的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了AssetsPackage.CheckPackageContentsAsync()方法
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 检查本地包裹内容的完整性
|
||||
/// </summary>
|
||||
public CheckPackageContentsOperation CheckPackageContentsAsync()
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 优化了HostPlayMode的初始化逻辑,优先读取沙盒内的清单,如果不存在则读取内置清单。
|
||||
|
||||
- 重写了文件的加密和解密逻辑。
|
||||
|
||||
```c#
|
||||
public interface IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件偏移解密方法
|
||||
/// </summary>
|
||||
ulong LoadFromFileOffset(DecryptFileInfo fileInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 文件内存解密方法
|
||||
/// </summary>
|
||||
byte[] LoadFromMemory(DecryptFileInfo fileInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 文件流解密方法
|
||||
/// </summary>
|
||||
System.IO.FileStream LoadFromStream(DecryptFileInfo fileInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 文件流解密的托管缓存大小
|
||||
/// </summary>
|
||||
uint GetManagedReadBufferSize();
|
||||
}
|
||||
```
|
||||
|
||||
- AssetBundleBuilder界面增加了构建版本选项。
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了AssetsPackage.WeaklyUpdateManifestAsync()方法。
|
||||
|
||||
## [1.3.3] - 2022-10-27
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了资源回收方法无效的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了PackageVersion构建参数。
|
||||
|
||||
````c#
|
||||
public class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
}
|
||||
````
|
||||
|
||||
### Changed
|
||||
|
||||
- AssetBundleDebugger窗口增加了包裹名称显示列。
|
||||
- AssetBundleDebugger窗口增加资源对象的加载耗时统计和显示。
|
||||
- AssetBundleDebugger窗口增加帧调试数据导出功能。
|
||||
- AssetBundleBuilder构建流程增加输出目录文件路径过长的检测。
|
||||
- 下载器返回的错误提示增加HTTP Response Code。
|
||||
- UpdateStaticVersionOperation.PackageCRC重名为UpdateStaticVersionOperation.PackageVersion。
|
||||
- AssetPackage.GetHumanReadableVersion()重名为AssetPackage.GetPackageVersion()
|
||||
|
||||
## [1.3.2] - 2022-10-22
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了AssetBundleCollector界面点击修复按钮界面没有刷新的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了自定义证书认证方法。
|
||||
|
||||
````c#
|
||||
public static class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置下载系统参数,自定义的证书认证实例
|
||||
/// </summary>
|
||||
public static void SetDownloadSystemCertificateHandler(UnityEngine.Networking.CertificateHandler instance)
|
||||
}
|
||||
````
|
||||
|
||||
- 新增了下载失败后清理文件的方法。
|
||||
|
||||
````c#
|
||||
public static class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置下载系统参数,下载失败后清理文件的HTTP错误码
|
||||
/// </summary>
|
||||
public static void SetDownloadSystemClearFileResponseCode(List<long> codes)
|
||||
}
|
||||
````
|
||||
|
||||
- 新增了检查资源定位地址是否有效的方法。
|
||||
|
||||
```c#
|
||||
public class AssetsPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 检查资源定位地址是否有效
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public bool CheckLocationValid(string location)
|
||||
}
|
||||
```
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了ILocationServices接口类和初始化字段。
|
||||
- 移除了AssetPackage.GetAssetPath(string location)方法。
|
||||
- 移除了BuildParameters.EnableAddressable字段。
|
||||
|
||||
### Changed
|
||||
|
||||
- AssetBundleCollector配置增加了UniqueBundleName设置,用于解决不同包裹之间Bundle名称冲突的问题。
|
||||
|
||||
## [1.3.1] - 2022-10-18
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了原生文件每次获取都重复拷贝的问题。
|
||||
- 修复了断点续传下载字节数统计不准确的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 所有下载相关方法增加超时判断参数。
|
||||
|
||||
- 新增首包资源文件拷贝选项。
|
||||
|
||||
```c#
|
||||
public class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 拷贝内置资源选项
|
||||
/// </summary>
|
||||
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源的标签
|
||||
/// </summary>
|
||||
public string CopyBuildinFileTags = string.Empty;
|
||||
}
|
||||
```
|
||||
|
||||
- 新增资源包初始化查询字段。
|
||||
|
||||
```c#
|
||||
public class AssetsPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化状态
|
||||
/// </summary>
|
||||
public EOperationStatus InitializeStatus
|
||||
}
|
||||
```
|
||||
|
||||
- 增加获取人类可读的版本信息。
|
||||
|
||||
````c#
|
||||
public class AssetsPackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取人类可读的版本信息
|
||||
/// </summary>
|
||||
public string GetHumanReadableVersion()
|
||||
}
|
||||
````
|
||||
|
||||
- 新增资源缓存清理方法。
|
||||
|
||||
```c#
|
||||
public static class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理未使用的缓存文件
|
||||
/// </summary>
|
||||
public static ClearUnusedCacheFilesOperation ClearUnusedCacheFiles()
|
||||
}
|
||||
```
|
||||
|
||||
- 异步操作类新增繁忙查询方法。
|
||||
|
||||
````c#
|
||||
public abstract class GameAsyncOperation
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步操作系统是否繁忙
|
||||
/// </summary>
|
||||
protected bool IsBusy()
|
||||
}
|
||||
````
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了AssetsPackage.IsInitialized()方法。
|
||||
- 移除了YooAssets.ClearAllCacheFiles()方法。
|
||||
|
||||
### Changed
|
||||
|
||||
- YooAssetsPackage类重名为AssetsPackage
|
||||
|
||||
## [1.3.0-preview] - 2022-10-08
|
||||
|
||||
该预览版本提供了分布式构建的功能,用于解决分工程或分内容构建的问题。
|
||||
|
||||
@@ -56,9 +56,11 @@ namespace YooAsset.Editor
|
||||
new TaskBuilding(), //开始执行构建
|
||||
new TaskVerifyBuildResult(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBuildInfo(), //更新构建信息
|
||||
new TaskCreatePatchManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
new TaskCreatePatchPackage(), //制作补丁包
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
}
|
||||
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
@@ -70,9 +72,11 @@ namespace YooAsset.Editor
|
||||
new TaskBuilding_SBP(), //开始执行构建
|
||||
new TaskVerifyBuildResult_SBP(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBuildInfo(), //更新构建信息
|
||||
new TaskCreatePatchManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
new TaskCreatePatchPackage(), //制作补丁包
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -84,7 +88,6 @@ namespace YooAsset.Editor
|
||||
var buildResult = BuildRunner.Run(pipeline, _buildContext);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
buildResult.OutputPackageCRC = buildParametersContext.OutputPackageCRC;
|
||||
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public static string GetStreamingAssetsFolderPath()
|
||||
{
|
||||
return $"{Application.dataPath}/StreamingAssets/YooAssets/";
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.StreamingAssetsBuildinFolder}/";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,27 +64,8 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public static string MakePipelineOutputDirectory(string outputRoot, string buildPackage, BuildTarget buildTarget, EBuildMode buildMode)
|
||||
{
|
||||
string result = $"{outputRoot}/{buildPackage}/{buildTarget}/{YooAssetSettings.OutputFolderName}";
|
||||
if (buildMode == EBuildMode.DryRunBuild)
|
||||
result += $"_{EBuildMode.DryRunBuild}";
|
||||
else if (buildMode == EBuildMode.SimulateBuild)
|
||||
result += $"_{EBuildMode.SimulateBuild}";
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载补丁清单文件
|
||||
/// </summary>
|
||||
internal static PatchManifest LoadPatchManifestFile(string fileDirectory, string packageName, string packageCRC)
|
||||
{
|
||||
string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC)}";
|
||||
if (File.Exists(filePath) == false)
|
||||
{
|
||||
throw new System.Exception($"Not found patch manifest file : {filePath}");
|
||||
}
|
||||
|
||||
string jsonData = FileUtility.ReadFile(filePath);
|
||||
return PatchManifest.Deserialize(jsonData);
|
||||
string outputDirectory = $"{outputRoot}/{buildPackage}/{buildTarget}/{YooAssetSettings.OutputFolderName}";
|
||||
return outputDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
|
||||
|
||||
/// <summary>
|
||||
/// 首包资源文件的拷贝方式
|
||||
/// </summary>
|
||||
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
/// <summary>
|
||||
/// 首包资源文件的标签集合
|
||||
/// </summary>
|
||||
public string CopyBuildinFileTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 加密类名称
|
||||
/// </summary>
|
||||
|
||||
@@ -27,10 +27,13 @@ namespace YooAsset.Editor
|
||||
private TextField _buildOutputField;
|
||||
private EnumField _buildPipelineField;
|
||||
private EnumField _buildModeField;
|
||||
private TextField _buildVersionField;
|
||||
private PopupField<string> _buildPackageField;
|
||||
private PopupField<string> _encryptionField;
|
||||
private EnumField _compressionField;
|
||||
private EnumField _outputNameStyleField;
|
||||
private EnumField _copyBuildinFileOptionField;
|
||||
private TextField _copyBuildinFileTagsField;
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
@@ -89,6 +92,10 @@ namespace YooAsset.Editor
|
||||
RefreshWindow();
|
||||
});
|
||||
|
||||
// 构建版本
|
||||
_buildVersionField = root.Q<TextField>("BuildVersion");
|
||||
_buildVersionField.SetValueWithoutNotify(GetBuildPackageVersion());
|
||||
|
||||
// 构建包裹
|
||||
var buildPackageContainer = root.Q("BuildPackageContainer");
|
||||
if (_buildPackageNames.Count > 0)
|
||||
@@ -135,7 +142,7 @@ namespace YooAsset.Editor
|
||||
encryptionContainer.Add(_encryptionField);
|
||||
}
|
||||
|
||||
// 压缩方式
|
||||
// 压缩方式选项
|
||||
_compressionField = root.Q<EnumField>("Compression");
|
||||
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
@@ -157,6 +164,27 @@ namespace YooAsset.Editor
|
||||
AssetBundleBuilderSettingData.Setting.OutputNameStyle = (EOutputNameStyle)_outputNameStyleField.value;
|
||||
});
|
||||
|
||||
// 首包文件拷贝选项
|
||||
_copyBuildinFileOptionField = root.Q<EnumField>("CopyBuildinFileOption");
|
||||
_copyBuildinFileOptionField.Init(AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption);
|
||||
_copyBuildinFileOptionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption);
|
||||
_copyBuildinFileOptionField.style.width = 350;
|
||||
_copyBuildinFileOptionField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.IsDirty = true;
|
||||
AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption = (ECopyBuildinFileOption)_copyBuildinFileOptionField.value;
|
||||
RefreshWindow();
|
||||
});
|
||||
|
||||
// 首包文件的资源标签
|
||||
_copyBuildinFileTagsField = root.Q<TextField>("CopyBuildinFileTags");
|
||||
_copyBuildinFileTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags);
|
||||
_copyBuildinFileTagsField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.IsDirty = true;
|
||||
AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags = _copyBuildinFileTagsField.value;
|
||||
});
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked; ;
|
||||
@@ -193,10 +221,15 @@ namespace YooAsset.Editor
|
||||
private void RefreshWindow()
|
||||
{
|
||||
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||
var copyOption = AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption;
|
||||
bool enableElement = buildMode == EBuildMode.ForceRebuild;
|
||||
bool tagsFiledVisible = copyOption == ECopyBuildinFileOption.ClearAndCopyByTags || copyOption == ECopyBuildinFileOption.OnlyCopyByTags;
|
||||
_encryptionField.SetEnabled(enableElement);
|
||||
_compressionField.SetEnabled(enableElement);
|
||||
_outputNameStyleField.SetEnabled(enableElement);
|
||||
_copyBuildinFileOptionField.SetEnabled(enableElement);
|
||||
_copyBuildinFileTagsField.SetEnabled(enableElement);
|
||||
_copyBuildinFileTagsField.visible = tagsFiledVisible;
|
||||
}
|
||||
private void SaveBtn_clicked()
|
||||
{
|
||||
@@ -227,12 +260,14 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildTarget = _buildTarget;
|
||||
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
|
||||
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
|
||||
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
|
||||
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;
|
||||
buildParameters.CopyBuildinFileOption = AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption;
|
||||
buildParameters.CopyBuildinFileTags = AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags;
|
||||
|
||||
if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
@@ -248,6 +283,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
// 构建版本相关
|
||||
private string GetBuildPackageVersion()
|
||||
{
|
||||
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||
}
|
||||
|
||||
// 构建包裹相关
|
||||
private int GetDefaultPackageIndex(string packageName)
|
||||
{
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||
<uie:EnumField label="Build Pipeline" name="BuildPipeline" />
|
||||
<uie:EnumField label="Build Mode" name="BuildMode" />
|
||||
<ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" style="width: 350px;" />
|
||||
<ui:VisualElement name="BuildPackageContainer" style="height: 24px;" />
|
||||
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
||||
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
||||
<uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" />
|
||||
<uie:EnumField label="Copy Buildin File Option" value="Center" name="CopyBuildinFileOption" />
|
||||
<ui:TextField picking-mode="Ignore" label="Copy Buildin File Tags" name="CopyBuildinFileTags" />
|
||||
<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:UXML>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -7,23 +8,23 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 模拟构建
|
||||
/// </summary>
|
||||
public static string SimulateBuild(string packageName, bool enableAddressable)
|
||||
public static string SimulateBuild(string packageName)
|
||||
{
|
||||
Debug.Log($"Begin to create simulate package : {packageName}");
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.BuildPackage = packageName;
|
||||
buildParameters.EnableAddressable = enableAddressable;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
var buildResult = builder.Run(buildParameters);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildPackage, buildParameters.BuildTarget, buildParameters.BuildMode);
|
||||
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildResult.OutputPackageCRC);
|
||||
string manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}";
|
||||
string manifestFileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||
return manifestFilePath;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace YooAsset.Editor
|
||||
IsRawAsset = isRawAsset;
|
||||
|
||||
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
IsShaderAsset = true;
|
||||
else
|
||||
IsShaderAsset = false;
|
||||
@@ -76,7 +76,7 @@ namespace YooAsset.Editor
|
||||
IsRawAsset = false;
|
||||
|
||||
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
IsShaderAsset = true;
|
||||
else
|
||||
IsShaderAsset = false;
|
||||
@@ -166,7 +166,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 计算主资源或共享资源的完整包名
|
||||
/// </summary>
|
||||
public void CalculateFullBundleName()
|
||||
public void CalculateFullBundleName(bool uniqueBundleName, string packageName)
|
||||
{
|
||||
if (CollectorType == ECollectorType.None)
|
||||
{
|
||||
@@ -177,15 +177,22 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_referenceBundleNames.Count > 1)
|
||||
{
|
||||
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
||||
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
if (_referenceBundleNames.Count > 1)
|
||||
if (uniqueBundleName)
|
||||
{
|
||||
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
||||
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
if (string.IsNullOrEmpty(_shareBundleName) == false)
|
||||
_shareBundleName = $"{packageName.ToLower()}_{_shareBundleName}";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -8,6 +8,40 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildBundleInfo
|
||||
{
|
||||
public class BuildPatchInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建内容的哈希值
|
||||
/// </summary>
|
||||
public string ContentHash { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public string PatchFileHash { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public string PatchFileCRC { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public long PatchFileSize { set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出的文件路径
|
||||
/// </summary>
|
||||
public string BuildOutputFilePath { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 补丁包输出文件路径
|
||||
/// </summary>
|
||||
public string PatchOutputFilePath { set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
@@ -19,6 +53,22 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public readonly List<BuildAssetInfo> BuildinAssets = new List<BuildAssetInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 补丁文件信息
|
||||
/// </summary>
|
||||
public readonly BuildPatchInfo PatchInfo = new BuildPatchInfo();
|
||||
|
||||
/// <summary>
|
||||
/// Bundle文件的加载方法
|
||||
/// </summary>
|
||||
public EBundleLoadMethod LoadMethod { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加密生成文件的路径
|
||||
/// 注意:如果未加密该路径为空
|
||||
/// </summary>
|
||||
public string EncryptedFilePath { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生文件
|
||||
/// </summary>
|
||||
@@ -36,9 +86,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建内容哈希值
|
||||
/// 是否为加密文件
|
||||
/// </summary>
|
||||
public string ContentHash { set; get; } = "00000000000000000000000000000000"; //32位
|
||||
public bool IsEncryptedFile
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(EncryptedFilePath))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BuildBundleInfo(string bundleName)
|
||||
@@ -89,14 +148,6 @@ namespace YooAsset.Editor
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的扩展名
|
||||
/// </summary>
|
||||
public string GetAppendExtension()
|
||||
{
|
||||
return System.IO.Path.GetExtension(BundleName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的资源路径列表
|
||||
/// </summary>
|
||||
@@ -125,5 +176,21 @@ namespace YooAsset.Editor
|
||||
build.assetNames = GetBuildinAssetPaths();
|
||||
return build;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建PatchBundle类
|
||||
/// </summary>
|
||||
internal PatchBundle CreatePatchBundle()
|
||||
{
|
||||
PatchBundle patchBundle = new PatchBundle();
|
||||
patchBundle.BundleName = BundleName;
|
||||
patchBundle.FileHash = PatchInfo.PatchFileHash;
|
||||
patchBundle.FileCRC = PatchInfo.PatchFileCRC;
|
||||
patchBundle.FileSize = PatchInfo.PatchFileSize;
|
||||
patchBundle.IsRawFile = IsRawFile;
|
||||
patchBundle.LoadMethod = (byte)LoadMethod;
|
||||
patchBundle.Tags = GetBundleTags();
|
||||
return patchBundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public int AssetFileCount;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包列表
|
||||
/// </summary>
|
||||
@@ -54,18 +64,6 @@ namespace YooAsset.Editor
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的分类标签列表
|
||||
/// </summary>
|
||||
public string[] GetBundleTags(string bundleName)
|
||||
{
|
||||
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
return bundleInfo.GetBundleTags();
|
||||
}
|
||||
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取AssetBundle内构建的资源路径列表
|
||||
/// </summary>
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace YooAsset.Editor
|
||||
AssetBundleCollectorSettingData.Setting.CheckConfigError();
|
||||
|
||||
// 2. 获取所有收集器收集的资源
|
||||
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
var buildResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
List<CollectAssetInfo> allCollectAssets = buildResult.CollectAssets;
|
||||
|
||||
// 3. 剔除未被引用的依赖资源
|
||||
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
|
||||
@@ -72,9 +73,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
context.AssetFileCount = buildAssetDic.Count;
|
||||
|
||||
// 6. 填充主动收集资源的依赖列表
|
||||
// 6. 记录关键信息
|
||||
context.AssetFileCount = buildAssetDic.Count;
|
||||
context.EnableAddressable = buildResult.EnableAddressable;
|
||||
context.UniqueBundleName = buildResult.UniqueBundleName;
|
||||
|
||||
// 7. 填充主动收集资源的依赖列表
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
||||
@@ -88,13 +93,13 @@ namespace YooAsset.Editor
|
||||
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
|
||||
}
|
||||
|
||||
// 7. 计算完整的资源包名
|
||||
// 8. 计算完整的资源包名
|
||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||
{
|
||||
pair.Value.CalculateFullBundleName();
|
||||
pair.Value.CalculateFullBundleName(buildResult.UniqueBundleName, buildResult.PackageName);
|
||||
}
|
||||
|
||||
// 8. 移除不参与构建的资源
|
||||
// 9. 移除不参与构建的资源
|
||||
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
|
||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||
{
|
||||
@@ -107,7 +112,7 @@ namespace YooAsset.Editor
|
||||
buildAssetDic.Remove(removeValue.AssetPath);
|
||||
}
|
||||
|
||||
// 9. 构建资源包
|
||||
// 10. 构建资源包
|
||||
var allBuildinAssets = buildAssetDic.Values.ToList();
|
||||
if (allBuildinAssets.Count == 0)
|
||||
throw new Exception("构建的资源列表不能为空");
|
||||
|
||||
@@ -57,21 +57,21 @@ namespace YooAsset.Editor
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的Package名称
|
||||
/// 构建的包裹名称
|
||||
/// </summary>
|
||||
public string BuildPackage;
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
public bool VerifyBuildingResult = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加密类
|
||||
/// </summary>
|
||||
@@ -82,6 +82,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源选项
|
||||
/// </summary>
|
||||
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源的标签
|
||||
/// </summary>
|
||||
public string CopyBuildinFileTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 压缩选项
|
||||
/// </summary>
|
||||
|
||||
@@ -11,30 +11,12 @@ namespace YooAsset.Editor
|
||||
|
||||
private string _pipelineOutputDirectory = string.Empty;
|
||||
private string _packageOutputDirectory = string.Empty;
|
||||
private string _outputPackageCRC = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 构建参数
|
||||
/// </summary>
|
||||
public BuildParameters Parameters { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出的包裹清单哈希值
|
||||
/// </summary>
|
||||
public string OutputPackageCRC
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_outputPackageCRC))
|
||||
throw new Exception("Output package file CRC32 is empty !");
|
||||
return _outputPackageCRC;
|
||||
}
|
||||
set
|
||||
{
|
||||
_outputPackageCRC = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BuildParametersContext(BuildParameters parameters)
|
||||
{
|
||||
@@ -49,7 +31,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
||||
{
|
||||
_pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(Parameters.OutputRoot, Parameters.BuildPackage, Parameters.BuildTarget, Parameters.BuildMode);
|
||||
_pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(Parameters.OutputRoot, Parameters.PackageName, Parameters.BuildTarget, Parameters.BuildMode);
|
||||
}
|
||||
return _pipelineOutputDirectory;
|
||||
}
|
||||
@@ -61,7 +43,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
||||
{
|
||||
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildPackage}/{Parameters.BuildTarget}/{OutputPackageCRC}";
|
||||
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.PackageName}/{Parameters.BuildTarget}/{Parameters.PackageVersion}";
|
||||
}
|
||||
return _packageOutputDirectory;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
@@ -56,6 +57,9 @@ namespace YooAsset.Editor
|
||||
|
||||
public static void Serialize(string savePath, BuildReport buildReport)
|
||||
{
|
||||
if (File.Exists(savePath))
|
||||
File.Delete(savePath);
|
||||
|
||||
string json = JsonUtility.ToJson(buildReport, true);
|
||||
FileUtility.CreateFile(savePath, json);
|
||||
}
|
||||
|
||||
@@ -8,21 +8,6 @@ namespace YooAsset.Editor
|
||||
[Serializable]
|
||||
public class ReportBundleInfo
|
||||
{
|
||||
public class FlagsData
|
||||
{
|
||||
public bool IsEncrypted { private set; get; }
|
||||
public bool IsBuildin { private set; get; }
|
||||
public bool IsRawFile { private set; get; }
|
||||
public FlagsData(bool isEncrypted, bool isBuildin, bool isRawFile)
|
||||
{
|
||||
IsEncrypted = isEncrypted;
|
||||
IsBuildin = isBuildin;
|
||||
IsRawFile = isRawFile;
|
||||
}
|
||||
}
|
||||
|
||||
private FlagsData _flagData;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
@@ -48,33 +33,21 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生文件
|
||||
/// </summary>
|
||||
public bool IsRawFile;
|
||||
|
||||
/// <summary>
|
||||
/// 加载方法
|
||||
/// </summary>
|
||||
public EBundleLoadMethod LoadMethod;
|
||||
|
||||
/// <summary>
|
||||
/// Tags
|
||||
/// </summary>
|
||||
public string[] Tags;
|
||||
|
||||
/// <summary>
|
||||
/// Flags
|
||||
/// </summary>
|
||||
public int Flags;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取标志位的解析数据
|
||||
/// </summary>
|
||||
public FlagsData GetFlagData()
|
||||
{
|
||||
if (_flagData == null)
|
||||
{
|
||||
BitMask32 value = Flags;
|
||||
bool isEncrypted = value.Test(0);
|
||||
bool isBuildin = value.Test(1);
|
||||
bool isRawFile = value.Test(2);
|
||||
_flagData = new FlagsData(isEncrypted, isBuildin, isRawFile);
|
||||
}
|
||||
return _flagData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源分类标签的字符串
|
||||
/// </summary>
|
||||
@@ -85,16 +58,5 @@ namespace YooAsset.Editor
|
||||
else
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原生文件
|
||||
/// </summary>
|
||||
public bool IsRawFile()
|
||||
{
|
||||
if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}")
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,15 +44,25 @@ namespace YooAsset.Editor
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建包裹
|
||||
/// 构建包裹名称
|
||||
/// </summary>
|
||||
public string BuildPackage;
|
||||
public string BuildPackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 构建包裹版本
|
||||
/// </summary>
|
||||
public string BuildPackageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 加密服务类名称
|
||||
/// </summary>
|
||||
|
||||
@@ -25,10 +25,5 @@ namespace YooAsset.Editor
|
||||
/// 输出的补丁包目录
|
||||
/// </summary>
|
||||
public string OutputPackageDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// 输出的包裹清单哈希值
|
||||
/// </summary>
|
||||
public string OutputPackageCRC;
|
||||
}
|
||||
}
|
||||
@@ -25,16 +25,19 @@ namespace YooAsset.Editor
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 开始构建
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
BuildAssetBundleOptions buildOptions = buildParametersContext.GetPipelineBuildOptions();
|
||||
AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
if (buildResults == null)
|
||||
{
|
||||
throw new Exception("构建过程中发生错误!");
|
||||
}
|
||||
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
string unityOutputManifestFilePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{YooAssetSettings.OutputFolderName}";
|
||||
if(System.IO.File.Exists(unityOutputManifestFilePath) == false)
|
||||
string unityOutputManifestFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
|
||||
if (System.IO.File.Exists(unityOutputManifestFilePath) == false)
|
||||
throw new Exception("构建过程中发生严重错误!请查阅上下文日志!");
|
||||
}
|
||||
|
||||
@@ -43,10 +46,10 @@ namespace YooAsset.Editor
|
||||
buildResultContext.UnityManifest = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
UpdateBuildBundleInfo(buildMapContext, buildParametersContext, buildResultContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,29 +72,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新构建结果
|
||||
/// </summary>
|
||||
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
|
||||
{
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName);
|
||||
if (hash.isValid)
|
||||
bundleInfo.ContentHash = hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,10 +46,10 @@ namespace YooAsset.Editor
|
||||
buildResultContext.Results = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
UpdateBuildBundleInfo(buildMapContext, buildParametersContext, buildResultContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,29 +72,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新构建结果
|
||||
/// </summary>
|
||||
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
|
||||
{
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:当资源包的依赖列表发生变化的时候,ContentHash也会发生变化!
|
||||
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
|
||||
bundleInfo.ContentHash = value.Hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("拷贝内置文件到流目录")]
|
||||
public class TaskCopyBuildinFiles : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var patchManifestContext = context.GetContextObject<PatchManifestContext>();
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
if (buildParametersContext.Parameters.CopyBuildinFileOption != ECopyBuildinFileOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, patchManifestContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝首包资源文件
|
||||
/// </summary>
|
||||
private void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext, PatchManifestContext patchManifestContext)
|
||||
{
|
||||
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
string streamingAssetsDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
|
||||
string buildPackageName = buildParametersContext.Parameters.PackageName;
|
||||
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
|
||||
|
||||
// 加载补丁清单
|
||||
PatchManifest patchManifest = patchManifestContext.Manifest;
|
||||
|
||||
// 清空流目录
|
||||
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
|
||||
{
|
||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||
}
|
||||
|
||||
// 拷贝补丁清单文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildPackageName, buildPackageVersion);
|
||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
// 拷贝补丁清单哈希文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestHashFileName(buildPackageName, buildPackageVersion);
|
||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
// 拷贝补丁清单版本文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(buildPackageName);
|
||||
string sourcePath = $"{packageOutputDirectory}/{fileName}";
|
||||
string destPath = $"{streamingAssetsDirectory}/{fileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
// 拷贝文件列表(所有文件)
|
||||
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.OnlyCopyAll)
|
||||
{
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
string sourcePath = $"{packageOutputDirectory}/{patchBundle.FileName}";
|
||||
string destPath = $"{streamingAssetsDirectory}/{patchBundle.FileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 拷贝文件列表(带标签的文件)
|
||||
if (option == ECopyBuildinFileOption.ClearAndCopyByTags || option == ECopyBuildinFileOption.OnlyCopyByTags)
|
||||
{
|
||||
string[] tags = buildParametersContext.Parameters.CopyBuildinFileTags.Split(';');
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.HasTag(tags) == false)
|
||||
continue;
|
||||
string sourcePath = $"{packageOutputDirectory}/{patchBundle.FileName}";
|
||||
string destPath = $"{streamingAssetsDirectory}/{patchBundle.FileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新目录
|
||||
AssetDatabase.Refresh();
|
||||
BuildRunner.Log($"内置文件拷贝完成:{streamingAssetsDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 057a358d2d0c92b47add59dac8bef783
|
||||
guid: 5c77e17c3a3a57548a218f1cd26f5a55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -8,6 +8,11 @@ using UnityEditor.Build.Pipeline.Interfaces;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class PatchManifestContext : IContextObject
|
||||
{
|
||||
internal PatchManifest Manifest;
|
||||
}
|
||||
|
||||
[TaskAttribute("创建补丁清单文件")]
|
||||
public class TaskCreatePatchManifest : IBuildTask
|
||||
{
|
||||
@@ -21,48 +26,69 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private void CreatePatchManifestFile(BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
|
||||
// 创建新补丁清单
|
||||
PatchManifest patchManifest = new PatchManifest();
|
||||
patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion;
|
||||
patchManifest.EnableAddressable = buildParameters.EnableAddressable;
|
||||
patchManifest.EnableAddressable = buildMapContext.EnableAddressable;
|
||||
patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
|
||||
patchManifest.PackageName = buildParameters.BuildPackage;
|
||||
patchManifest.PackageName = buildParameters.PackageName;
|
||||
patchManifest.PackageVersion = buildParameters.PackageVersion;
|
||||
patchManifest.BundleList = GetAllPatchBundle(context);
|
||||
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
||||
|
||||
// 更新Unity内置资源包的引用关系
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
if(buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
||||
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建补丁清单文件
|
||||
string manifestFileTempName = YooAssetSettingsData.GetPatchManifestTempFileName(buildParameters.BuildPackage);
|
||||
string manifestFileTempPath = $"{pipelineOutputDirectory}/{manifestFileTempName}";
|
||||
BuildRunner.Log($"创建补丁清单文件:{manifestFileTempPath}");
|
||||
PatchManifest.Serialize(manifestFileTempPath, patchManifest);
|
||||
// 创建补丁清单文本文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
PatchManifest.SerializeToJson(filePath, patchManifest);
|
||||
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||
}
|
||||
|
||||
// 计算补丁清单文件的CRC32
|
||||
buildParametersContext.OutputPackageCRC = HashUtility.FileCRC32(manifestFileTempPath);
|
||||
// 创建补丁清单二进制文件
|
||||
string packageHash;
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
PatchManifest.SerializeToBinary(filePath, patchManifest);
|
||||
packageHash = HashUtility.FileMD5(filePath);
|
||||
BuildRunner.Log($"创建补丁清单文件:{filePath}");
|
||||
|
||||
// 补丁清单文件重命名
|
||||
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
string manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}";
|
||||
EditorTools.FileMoveTo(manifestFileTempPath, manifestFilePath);
|
||||
PatchManifestContext patchManifestContext = new PatchManifestContext();
|
||||
byte[] bytesData = FileUtility.ReadAllBytes(filePath);
|
||||
patchManifestContext.Manifest = PatchManifest.DeserializeFromBinary(bytesData);
|
||||
context.SetContextObject(patchManifestContext);
|
||||
}
|
||||
|
||||
// 创建静态版本文件
|
||||
string staticVersionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage);
|
||||
string staticVersionFilePath = $"{pipelineOutputDirectory}/{staticVersionFileName}";
|
||||
BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}");
|
||||
FileUtility.CreateFile(staticVersionFilePath, buildParametersContext.OutputPackageCRC);
|
||||
// 创建补丁清单哈希文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
FileUtility.CreateFile(filePath, packageHash);
|
||||
BuildRunner.Log($"创建补丁清单哈希文件:{filePath}");
|
||||
}
|
||||
|
||||
// 创建补丁清单版本文件
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPatchManifestVersionFileName(buildParameters.PackageName);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
FileUtility.CreateFile(filePath, buildParameters.PackageVersion);
|
||||
BuildRunner.Log($"创建补丁清单版本文件:{filePath}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,61 +96,23 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private List<PatchBundle> GetAllPatchBundle(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
|
||||
List<PatchBundle> result = new List<PatchBundle>(1000);
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var bundleName = bundleInfo.BundleName;
|
||||
string fileHash = GetBundleFileHash(bundleInfo, buildParameters);
|
||||
string fileCRC = GetBundleFileCRC(bundleInfo, buildParameters);
|
||||
long fileSize = GetBundleFileSize(bundleInfo, buildParameters);
|
||||
string[] tags = buildMapContext.GetBundleTags(bundleName);
|
||||
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
||||
bool isRawFile = bundleInfo.IsRawFile;
|
||||
|
||||
PatchBundle patchBundle = new PatchBundle(bundleName, fileHash, fileCRC, fileSize, tags);
|
||||
patchBundle.SetFlagsValue(isRawFile, isEncrypted);
|
||||
var patchBundle = bundleInfo.CreatePatchBundle();
|
||||
result.Add(patchBundle);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
|
||||
string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
private string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
|
||||
string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
private long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return 0;
|
||||
|
||||
string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源列表
|
||||
/// </summary>
|
||||
private List<PatchAsset> GetAllPatchAsset(BuildContext context, PatchManifest patchManifest)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
List<PatchAsset> result = new List<PatchAsset>(1000);
|
||||
@@ -134,7 +122,7 @@ namespace YooAsset.Editor
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
PatchAsset patchAsset = new PatchAsset();
|
||||
if (buildParameters.Parameters.EnableAddressable)
|
||||
if (buildMapContext.EnableAddressable)
|
||||
patchAsset.Address = assetInfo.Address;
|
||||
else
|
||||
patchAsset.Address = string.Empty;
|
||||
@@ -188,6 +176,10 @@ namespace YooAsset.Editor
|
||||
shaderBundleReferenceList.Add(valuePair.Key);
|
||||
}
|
||||
|
||||
// 注意:没有任何资源依赖着色器
|
||||
if (shaderBundleReferenceList.Count == 0)
|
||||
return;
|
||||
|
||||
// 获取着色器资源包索引
|
||||
Predicate<PatchBundle> predicate = new Predicate<PatchBundle>(s => s.BundleName == shadersBunldeName);
|
||||
int shaderBundleId = patchManifest.BundleList.FindIndex(predicate);
|
||||
|
||||
@@ -9,47 +9,24 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyPatchFiles(buildParameters);
|
||||
CopyPatchFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝补丁文件到补丁包目录
|
||||
/// </summary>
|
||||
private void CopyPatchFiles(BuildParametersContext buildParametersContext)
|
||||
private void CopyPatchFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageOutputDirectory}");
|
||||
|
||||
// 拷贝Report文件
|
||||
{
|
||||
string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
string sourcePath = $"{pipelineOutputDirectory}/{reportFileName}";
|
||||
string destPath = $"{packageOutputDirectory}/{reportFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
// 拷贝补丁清单文件
|
||||
{
|
||||
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
string sourcePath = $"{pipelineOutputDirectory}/{manifestFileName}";
|
||||
string destPath = $"{packageOutputDirectory}/{manifestFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
// 拷贝静态版本文件
|
||||
{
|
||||
string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage);
|
||||
string sourcePath = $"{pipelineOutputDirectory}/{versionFileName}";
|
||||
string destPath = $"{packageOutputDirectory}/{versionFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
// 拷贝构建日志
|
||||
@@ -67,7 +44,7 @@ namespace YooAsset.Editor
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
// 拷贝UnityManifest序列化文件
|
||||
{
|
||||
@@ -83,16 +60,17 @@ namespace YooAsset.Editor
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
// 拷贝所有补丁文件
|
||||
int progressValue = 0;
|
||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
int patchFileTotalCount = patchManifest.BundleList.Count;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
int patchFileTotalCount = buildMapContext.BundleInfos.Count;
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||
string destPath = $"{packageOutputDirectory}/{patchBundle.FileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
EditorTools.CopyFile(bundleInfo.PatchInfo.BuildOutputFilePath, bundleInfo.PatchInfo.PatchOutputFilePath, true);
|
||||
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
@@ -12,24 +12,25 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var patchManifestContext = context.GetContextObject<PatchManifestContext>();
|
||||
buildParameters.StopWatch();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreateReportFile(buildParameters, buildMapContext);
|
||||
CreateReportFile(buildParameters, buildMapContext, patchManifestContext);
|
||||
}
|
||||
|
||||
float buildSeconds = buildParameters.GetBuildingSeconds();
|
||||
BuildRunner.Info($"Build time consuming {buildSeconds} seconds.");
|
||||
}
|
||||
|
||||
private void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
private void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext, PatchManifestContext patchManifestContext)
|
||||
{
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
PatchManifest patchManifest = patchManifestContext.Manifest;
|
||||
BuildReport buildReport = new BuildReport();
|
||||
|
||||
// 概述信息
|
||||
@@ -45,8 +46,10 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
|
||||
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
|
||||
buildReport.Summary.BuildMode = buildParameters.BuildMode;
|
||||
buildReport.Summary.BuildPackage = buildParameters.BuildPackage;
|
||||
buildReport.Summary.EnableAddressable = buildParameters.EnableAddressable;
|
||||
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
|
||||
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
|
||||
buildReport.Summary.EnableAddressable = buildMapContext.EnableAddressable;
|
||||
buildReport.Summary.UniqueBundleName = buildMapContext.UniqueBundleName;
|
||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
|
||||
"null" : buildParameters.EncryptionServices.GetType().FullName;
|
||||
|
||||
@@ -95,17 +98,14 @@ namespace YooAsset.Editor
|
||||
reportBundleInfo.FileCRC = patchBundle.FileCRC;
|
||||
reportBundleInfo.FileSize = patchBundle.FileSize;
|
||||
reportBundleInfo.Tags = patchBundle.Tags;
|
||||
reportBundleInfo.Flags = patchBundle.Flags;
|
||||
reportBundleInfo.IsRawFile = patchBundle.IsRawFile;
|
||||
reportBundleInfo.LoadMethod = (EBundleLoadMethod)patchBundle.LoadMethod;
|
||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||
}
|
||||
|
||||
// 删除旧文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
|
||||
string filePath = $"{pipelineOutputDirectory}/{fileName}";
|
||||
if (File.Exists(filePath))
|
||||
File.Delete(filePath);
|
||||
|
||||
// 序列化文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
BuildReport.Serialize(filePath, buildReport);
|
||||
BuildRunner.Log($"资源构建报告文件创建完成:{filePath}");
|
||||
}
|
||||
@@ -179,7 +179,7 @@ namespace YooAsset.Editor
|
||||
int fileCount = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.IsEncrypted)
|
||||
if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
|
||||
fileCount++;
|
||||
}
|
||||
return fileCount;
|
||||
@@ -189,7 +189,7 @@ namespace YooAsset.Editor
|
||||
long fileBytes = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.IsEncrypted)
|
||||
if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
|
||||
fileBytes += patchBundle.FileSize;
|
||||
}
|
||||
return fileBytes;
|
||||
|
||||
@@ -9,19 +9,6 @@ namespace YooAsset.Editor
|
||||
[TaskAttribute("资源包加密")]
|
||||
public class TaskEncryption : IBuildTask
|
||||
{
|
||||
public class EncryptionContext : IContextObject
|
||||
{
|
||||
public List<string> EncryptList;
|
||||
|
||||
/// <summary>
|
||||
/// 检测是否为加密文件
|
||||
/// </summary>
|
||||
public bool IsEncryptFile(string bundleName)
|
||||
{
|
||||
return EncryptList.Contains(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
@@ -30,65 +17,52 @@ namespace YooAsset.Editor
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptionContext encryptionContext = new EncryptionContext();
|
||||
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||
context.SetContextObject(encryptionContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
EncryptionContext encryptionContext = new EncryptionContext();
|
||||
encryptionContext.EncryptList = new List<string>();
|
||||
context.SetContextObject(encryptionContext);
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密文件
|
||||
/// </summary>
|
||||
private List<string> EncryptFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
private void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
|
||||
|
||||
// 加密资源列表
|
||||
List<string> encryptList = new List<string>();
|
||||
|
||||
// 如果没有设置加密类
|
||||
if (encryptionServices == null)
|
||||
return encryptList;
|
||||
return;
|
||||
|
||||
int progressValue = 0;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
if (encryptionServices.Check(bundleInfo.BundleName))
|
||||
bundleInfo.LoadMethod = EBundleLoadMethod.Normal;
|
||||
|
||||
EncryptFileInfo fileInfo = new EncryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.BundleName;
|
||||
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
|
||||
var encryptResult = encryptionServices.Encrypt(fileInfo);
|
||||
if (encryptResult.LoadMethod != EBundleLoadMethod.Normal)
|
||||
{
|
||||
// 注意:原生文件不支持加密
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Encryption not support raw file : {bundleInfo.BundleName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
encryptList.Add(bundleInfo.BundleName);
|
||||
|
||||
// 注意:通过判断文件合法性,规避重复加密一个文件
|
||||
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
byte[] fileData = File.ReadAllBytes(filePath);
|
||||
if (EditorTools.CheckBundleFileValid(fileData))
|
||||
{
|
||||
byte[] bytes = encryptionServices.Encrypt(fileData);
|
||||
File.WriteAllBytes(filePath, bytes);
|
||||
BuildRunner.Log($"文件加密完成:{filePath}");
|
||||
}
|
||||
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
|
||||
FileUtility.CreateFile(filePath, encryptResult.EncryptedData);
|
||||
bundleInfo.EncryptedFilePath = filePath;
|
||||
bundleInfo.LoadMethod = encryptResult.LoadMethod;
|
||||
BuildRunner.Log($"Bundle文件加密完成:{filePath}");
|
||||
}
|
||||
|
||||
// 进度条
|
||||
EditorTools.DisplayProgressBar("加密资源包", ++progressValue, buildMapContext.BundleInfos.Count);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if(encryptList.Count == 0)
|
||||
UnityEngine.Debug.LogWarning($"没有发现需要加密的文件!");
|
||||
return encryptList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.BuildPackage);
|
||||
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.PackageName);
|
||||
context.SetContextObject(buildMapContext);
|
||||
BuildRunner.Log("构建内容准备完毕!");
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ namespace YooAsset.Editor
|
||||
// 检测构建参数合法性
|
||||
if (buildParameters.BuildTarget == BuildTarget.NoTarget)
|
||||
throw new Exception("请选择目标平台");
|
||||
if (string.IsNullOrEmpty(buildParameters.BuildPackage))
|
||||
if (string.IsNullOrEmpty(buildParameters.PackageName))
|
||||
throw new Exception("包裹名称不能为空");
|
||||
if(string.IsNullOrEmpty(buildParameters.PackageVersion))
|
||||
throw new Exception("包裹版本不能为空");
|
||||
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
@@ -32,13 +34,27 @@ namespace YooAsset.Editor
|
||||
if (EditorTools.HasDirtyScenes())
|
||||
throw new Exception("检测到未保存的场景文件");
|
||||
|
||||
// 检测首包资源标签
|
||||
if (buildParameters.CopyBuildinFileOption == ECopyBuildinFileOption.ClearAndCopyByTags
|
||||
|| buildParameters.CopyBuildinFileOption == ECopyBuildinFileOption.OnlyCopyByTags)
|
||||
{
|
||||
if (string.IsNullOrEmpty(buildParameters.CopyBuildinFileTags))
|
||||
throw new Exception("首包资源标签不能为空!");
|
||||
}
|
||||
|
||||
// 检测包裹输出目录是否存在
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
throw new Exception($"本次构建的补丁目录已经存在:{packageOutputDirectory}");
|
||||
|
||||
// 保存改动的资源
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
{
|
||||
// 删除平台总目录
|
||||
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildPackage}/{buildParameters.BuildTarget}";
|
||||
string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.PackageName}/{buildParameters.BuildTarget}";
|
||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
||||
{
|
||||
BuildRunner.Log($"删除平台总目录:{platformDirectory}");
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("更新构建信息")]
|
||||
public class TaskUpdateBuildInfo : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
int outputNameStyle = (int)buildParametersContext.Parameters.OutputNameStyle;
|
||||
|
||||
// 1.检测路径长度
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
// NOTE:检测路径长度不要超过260字符。
|
||||
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
if (filePath.Length >= 260)
|
||||
throw new Exception($"The output bundle name is too long {filePath.Length} chars : {filePath}");
|
||||
}
|
||||
|
||||
// 2.更新构建输出的文件路径
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
if (bundleInfo.IsEncryptedFile)
|
||||
bundleInfo.PatchInfo.BuildOutputFilePath = bundleInfo.EncryptedFilePath;
|
||||
else
|
||||
bundleInfo.PatchInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
}
|
||||
|
||||
// 3.更新文件其它信息
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
string buildOutputFilePath = bundleInfo.PatchInfo.BuildOutputFilePath;
|
||||
bundleInfo.PatchInfo.ContentHash = GetBundleContentHash(bundleInfo, context);
|
||||
bundleInfo.PatchInfo.PatchFileHash = GetBundleFileHash(buildOutputFilePath, buildParametersContext);
|
||||
bundleInfo.PatchInfo.PatchFileCRC = GetBundleFileCRC(buildOutputFilePath, buildParametersContext);
|
||||
bundleInfo.PatchInfo.PatchFileSize = GetBundleFileSize(buildOutputFilePath, buildParametersContext);
|
||||
}
|
||||
|
||||
// 4.更新补丁包输出的文件路径
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
string patchFileName = PatchManifest.CreateBundleFileName(outputNameStyle, bundleInfo.BundleName, bundleInfo.PatchInfo.PatchFileHash);
|
||||
bundleInfo.PatchInfo.PatchOutputFilePath = $"{packageOutputDirectory}/{patchFileName}";
|
||||
}
|
||||
}
|
||||
|
||||
private string GetBundleContentHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
string filePath = bundleInfo.PatchInfo.BuildOutputFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
|
||||
if (parameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
var buildResult = context.GetContextObject<TaskBuilding.BuildResultContext>();
|
||||
var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName);
|
||||
if (hash.isValid)
|
||||
return hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
// 注意:当资源包的依赖列表发生变化的时候,ContentHash也会发生变化!
|
||||
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
|
||||
return value.Hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
private string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
private string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
private long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return 0;
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfc81e18e5b5f6f4b821c7427b34d349
|
||||
guid: 4882f54fbf0bcb04680fb581deae4889
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -62,6 +62,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 4. 验证Asset
|
||||
/*
|
||||
bool isPass = true;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
@@ -98,6 +99,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
BuildRunner.Log("构建结果验证成功!");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 首包资源文件的拷贝方式
|
||||
/// </summary>
|
||||
public enum ECopyBuildinFileOption
|
||||
{
|
||||
/// <summary>
|
||||
/// 不拷贝任何文件
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 先清空已有文件,然后拷贝所有文件
|
||||
/// </summary>
|
||||
ClearAndCopyAll,
|
||||
|
||||
/// <summary>
|
||||
/// 先清空已有文件,然后按照资源标签拷贝文件
|
||||
/// </summary>
|
||||
ClearAndCopyByTags,
|
||||
|
||||
/// <summary>
|
||||
/// 不清空已有文件,直接拷贝所有文件
|
||||
/// </summary>
|
||||
OnlyCopyAll,
|
||||
|
||||
/// <summary>
|
||||
/// 不清空已有文件,直接按照资源标签拷贝文件
|
||||
/// </summary>
|
||||
OnlyCopyByTags,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8d6592eded144142afcf85c79cf1ce4
|
||||
guid: 4defd475b635cdf4b87108140d3a0ad1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public interface IEncryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 检测是否需要加密
|
||||
/// </summary>
|
||||
bool Check(string bundleName);
|
||||
|
||||
/// <summary>
|
||||
/// 加密方法
|
||||
/// </summary>
|
||||
/// <param name="fileData">要加密的文件数据</param>
|
||||
/// <returns>返回加密后的字节数据</returns>
|
||||
byte[] Encrypt(byte[] fileData);
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,10 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable, AssetBundleCollectorGroup group)
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
@@ -162,7 +162,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -177,7 +177,7 @@ namespace YooAsset.Editor
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawAsset);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -187,7 +187,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (enableAddressable)
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
@@ -207,7 +207,7 @@ namespace YooAsset.Editor
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
private CollectAssetInfo CreateCollectAssetInfo(EBuildMode buildMode, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||
{
|
||||
string address = GetAddress(group, assetPath);
|
||||
string bundleName = GetBundleName(group, assetPath);
|
||||
@@ -215,7 +215,7 @@ namespace YooAsset.Editor
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<string>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||
@@ -240,13 +240,15 @@ namespace YooAsset.Editor
|
||||
return false;
|
||||
|
||||
// 忽略Unity无法识别的无效文件
|
||||
/*
|
||||
if (type == typeof(UnityEditor.DefaultAsset))
|
||||
// 注意:只对非原生文件收集器处理
|
||||
if(PackRuleName != nameof(PackRawFile))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||
return false;
|
||||
if (type == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
string fileExtension = System.IO.Path.GetExtension(assetPath);
|
||||
if (IsIgnoreFile(fileExtension))
|
||||
@@ -266,7 +268,7 @@ namespace YooAsset.Editor
|
||||
private bool IsCollectAsset(string assetPath)
|
||||
{
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
return true;
|
||||
|
||||
// 根据规则设置过滤资源文件
|
||||
@@ -285,10 +287,8 @@ namespace YooAsset.Editor
|
||||
private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)
|
||||
{
|
||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
{
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
return EditorTools.GetRegularPath(YooAssetSettings.UnityShadersBundleName).ToLower();
|
||||
}
|
||||
|
||||
// 根据规则设置获取资源包名称
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
|
||||
@@ -10,12 +10,14 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorConfig
|
||||
{
|
||||
public const string ConfigVersion = "2.0";
|
||||
public const string ConfigVersion = "2.2";
|
||||
|
||||
public const string XmlVersion = "Version";
|
||||
public const string XmlCommon = "Common";
|
||||
public const string XmlEnableAddressable = "AutoAddressable";
|
||||
public const string XmlUniqueBundleName = "UniqueBundleName";
|
||||
public const string XmlShowPackageView = "ShowPackageView";
|
||||
public const string XmlShowEditorAlias = "ShowEditorAlias";
|
||||
|
||||
public const string XmlPackage = "Package";
|
||||
public const string XmlPackageName = "PackageName";
|
||||
@@ -62,18 +64,26 @@ namespace YooAsset.Editor
|
||||
|
||||
// 读取公共配置
|
||||
bool enableAddressable = false;
|
||||
bool uniqueBundleName = false;
|
||||
bool showPackageView = false;
|
||||
bool showEditorAlias = false;
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlEnableAddressable) == false)
|
||||
throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}");
|
||||
if (commonElement.HasAttribute(XmlUniqueBundleName) == false)
|
||||
throw new Exception($"Not found attribute {XmlUniqueBundleName} in {XmlCommon}");
|
||||
if (commonElement.HasAttribute(XmlShowPackageView) == false)
|
||||
throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}");
|
||||
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
|
||||
throw new Exception($"Not found attribute {XmlShowEditorAlias} in {XmlCommon}");
|
||||
|
||||
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
|
||||
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
|
||||
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
|
||||
}
|
||||
|
||||
// 读取包裹配置
|
||||
@@ -146,7 +156,9 @@ namespace YooAsset.Editor
|
||||
// 保存配置数据
|
||||
AssetBundleCollectorSettingData.ClearAll();
|
||||
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
|
||||
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
|
||||
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
|
||||
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
|
||||
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
Debug.Log($"导入配置完毕!");
|
||||
@@ -175,7 +187,9 @@ namespace YooAsset.Editor
|
||||
// 设置公共配置
|
||||
var commonElement = xmlDoc.CreateElement(XmlCommon);
|
||||
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
|
||||
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
|
||||
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
|
||||
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
|
||||
root.AppendChild(commonElement);
|
||||
|
||||
// 设置Package配置
|
||||
@@ -269,7 +283,40 @@ namespace YooAsset.Editor
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.0");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.0 -> 2.1
|
||||
if (configVersion == "2.0")
|
||||
{
|
||||
// 添加公共元素属性
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlUniqueBundleName) == false)
|
||||
commonElement.SetAttribute(XmlUniqueBundleName, "False");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.1");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// 2.1 -> 2.2
|
||||
if (configVersion == "2.1")
|
||||
{
|
||||
// 添加公共元素属性
|
||||
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||
if (commonNodeList.Count > 0)
|
||||
{
|
||||
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||
if (commonElement.HasAttribute(XmlShowEditorAlias) == false)
|
||||
commonElement.SetAttribute(XmlShowEditorAlias, "False");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "2.2");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace YooAsset.Editor
|
||||
// 收集打包资源
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(buildMode, enableAddressable, this);
|
||||
var temper = collector.GetAllCollectAssets(command, this);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
@@ -94,7 +94,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (enableAddressable)
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
|
||||
@@ -56,14 +56,14 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, bool enableAddressable)
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets(buildMode, enableAddressable);
|
||||
var temper = group.GetAllCollectAssets(command);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
@@ -74,7 +74,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (enableAddressable)
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
HashSet<string> adressTemper = new HashSet<string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace YooAsset.Editor
|
||||
public class AssetBundleCollectorSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否显示包裹视图
|
||||
/// 是否显示包裹列表视图
|
||||
/// </summary>
|
||||
public bool ShowPackageView = false;
|
||||
|
||||
@@ -18,6 +18,17 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示编辑器别名
|
||||
/// </summary>
|
||||
public bool ShowEditorAlias = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 包裹列表
|
||||
/// </summary>
|
||||
@@ -76,37 +87,43 @@ namespace YooAsset.Editor
|
||||
Debug.LogWarning($"Not found package : {packageName}");
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build Package name is null or mepty !");
|
||||
throw new Exception("Build package name is null or mepty !");
|
||||
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
{
|
||||
return package.GetAllCollectAssets(buildMode, EnableAddressable);
|
||||
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
|
||||
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
return collectResult;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"Not found collector pacakge : {packageName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有包裹收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllPackageAssets(EBuildMode buildMode)
|
||||
public List<CollectResult> GetAllPackageAssets(EBuildMode buildMode)
|
||||
{
|
||||
List<CollectAssetInfo> result = new List<CollectAssetInfo>(1000);
|
||||
List<CollectResult> collectResultList = new List<CollectResult>(1000);
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
var temper = package.GetAllCollectAssets(buildMode, EnableAddressable);
|
||||
result.AddRange(temper);
|
||||
CollectCommand command = new CollectCommand(buildMode, EnableAddressable);
|
||||
CollectResult collectResult = new CollectResult(package.PackageName, EnableAddressable, UniqueBundleName);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
collectResultList.Add(collectResult);
|
||||
}
|
||||
return result;
|
||||
return collectResultList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,92 +38,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetActiveRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
names.Add(pair.Key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<string> GetAddressRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
{
|
||||
names.Add(pair.Key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<string> GetPackRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
{
|
||||
names.Add(pair.Key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<string> GetFilterRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (var pair in _cacheFilterRuleTypes)
|
||||
{
|
||||
names.Add(pair.Key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
if (pair.Key == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
{
|
||||
if (pair.Key == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
{
|
||||
if (pair.Key == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cacheFilterRuleTypes)
|
||||
{
|
||||
if (pair.Key == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置文件
|
||||
/// </summary>
|
||||
@@ -146,6 +60,7 @@ namespace YooAsset.Editor
|
||||
typeof(PackCollector),
|
||||
typeof(PackGroup),
|
||||
typeof(PackRawFile),
|
||||
typeof(PackShaderVariants)
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||
@@ -266,7 +181,92 @@ namespace YooAsset.Editor
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
// 实例类相关
|
||||
public static List<RuleDisplayName> GetActiveRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetAddressRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetPackRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetFilterRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheFilterRuleTypes)
|
||||
{
|
||||
RuleDisplayName ruleName = new RuleDisplayName();
|
||||
ruleName.ClassName = pair.Key;
|
||||
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
|
||||
names.Add(ruleName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
private static string GetRuleDisplayName(string name, Type type)
|
||||
{
|
||||
var attribute = EditorAttribute.GetAttribute<DisplayNameAttribute>(type);
|
||||
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
|
||||
return attribute.DisplayName;
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||
@@ -347,14 +347,25 @@ namespace YooAsset.Editor
|
||||
Setting.EnableAddressable = enableAddressable;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyUniqueBundleName(bool uniqueBundleName)
|
||||
{
|
||||
Setting.UniqueBundleName = uniqueBundleName;
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void ModifyShowEditorAlias(bool showAlias)
|
||||
{
|
||||
Setting.ShowEditorAlias = showAlias;
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
// 资源包裹编辑相关
|
||||
public static void CreatePackage(string packageName)
|
||||
public static AssetBundleCollectorPackage CreatePackage(string packageName)
|
||||
{
|
||||
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
|
||||
package.PackageName = packageName;
|
||||
Setting.Packages.Add(package);
|
||||
IsDirty = true;
|
||||
return package;
|
||||
}
|
||||
public static void RemovePackage(AssetBundleCollectorPackage package)
|
||||
{
|
||||
@@ -376,12 +387,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 资源分组编辑相关
|
||||
public static void CreateGroup(AssetBundleCollectorPackage package, string groupName)
|
||||
public static AssetBundleCollectorGroup CreateGroup(AssetBundleCollectorPackage package, string groupName)
|
||||
{
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.GroupName = groupName;
|
||||
package.Groups.Add(group);
|
||||
IsDirty = true;
|
||||
return group;
|
||||
}
|
||||
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
|
||||
{
|
||||
|
||||
@@ -20,13 +20,15 @@ namespace YooAsset.Editor
|
||||
|
||||
private Button _saveButton;
|
||||
private List<string> _collectorTypeList;
|
||||
private List<string> _activeRuleList;
|
||||
private List<string> _addressRuleList;
|
||||
private List<string> _packRuleList;
|
||||
private List<string> _filterRuleList;
|
||||
|
||||
private List<RuleDisplayName> _activeRuleList;
|
||||
private List<RuleDisplayName> _addressRuleList;
|
||||
private List<RuleDisplayName> _packRuleList;
|
||||
private List<RuleDisplayName> _filterRuleList;
|
||||
|
||||
private Toggle _showPackageToogle;
|
||||
private Toggle _enableAddressableToogle;
|
||||
private Toggle _uniqueBundleNameToogle;
|
||||
private Toggle _showEditorAliasToggle;
|
||||
|
||||
private VisualElement _packageContainer;
|
||||
private ListView _packageListView;
|
||||
@@ -41,7 +43,7 @@ namespace YooAsset.Editor
|
||||
|
||||
private VisualElement _collectorContainer;
|
||||
private ScrollView _collectorScrollView;
|
||||
private PopupField<string> _activeRulePopupField;
|
||||
private PopupField<RuleDisplayName> _activeRulePopupField;
|
||||
|
||||
private int _lastModifyPackageIndex = 0;
|
||||
private int _lastModifyGroupIndex = 0;
|
||||
@@ -87,6 +89,19 @@ namespace YooAsset.Editor
|
||||
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
||||
RefreshWindow();
|
||||
});
|
||||
_uniqueBundleNameToogle = root.Q<Toggle>("UniqueBundleName");
|
||||
_uniqueBundleNameToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleCollectorSettingData.ModifyUniqueBundleName(evt.newValue);
|
||||
RefreshWindow();
|
||||
});
|
||||
|
||||
_showEditorAliasToggle = root.Q<Toggle>("ShowEditorAlias");
|
||||
_showEditorAliasToggle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleCollectorSettingData.ModifyShowEditorAlias(evt.newValue);
|
||||
RefreshWindow();
|
||||
});
|
||||
|
||||
// 配置修复按钮
|
||||
var fixBtn = root.Q<Button>("FixButton");
|
||||
@@ -180,6 +195,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
selectGroup.GroupName = evt.newValue;
|
||||
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
|
||||
FillGroupViewData();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -193,6 +209,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
selectGroup.GroupDesc = evt.newValue;
|
||||
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
|
||||
FillGroupViewData();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -227,21 +244,23 @@ namespace YooAsset.Editor
|
||||
// 分组激活规则
|
||||
var activeRuleContainer = root.Q("ActiveRuleContainer");
|
||||
{
|
||||
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
|
||||
_activeRulePopupField = new PopupField<RuleDisplayName>("Active Rule", _activeRuleList, 0);
|
||||
_activeRulePopupField.name = "ActiveRuleMaskField";
|
||||
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
activeRuleContainer.Add(_activeRulePopupField);
|
||||
_activeRulePopupField.formatListItemCallback = FormatListItemCallback;
|
||||
_activeRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||
_activeRulePopupField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||
if (selectPackage != null && selectGroup != null)
|
||||
{
|
||||
selectGroup.ActiveRuleName = evt.newValue;
|
||||
selectGroup.ActiveRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyGroup(selectPackage, selectGroup);
|
||||
FillGroupViewData();
|
||||
}
|
||||
});
|
||||
activeRuleContainer.Add(_activeRulePopupField);
|
||||
}
|
||||
|
||||
// 刷新窗体
|
||||
@@ -281,6 +300,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
_showPackageToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowPackageView);
|
||||
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
|
||||
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
|
||||
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
|
||||
|
||||
_groupContainer.visible = false;
|
||||
_collectorContainer.visible = false;
|
||||
|
||||
@@ -289,6 +311,7 @@ namespace YooAsset.Editor
|
||||
private void FixBtn_clicked()
|
||||
{
|
||||
AssetBundleCollectorSettingData.FixFile();
|
||||
RefreshWindow();
|
||||
}
|
||||
private void ExportBtn_clicked()
|
||||
{
|
||||
@@ -311,6 +334,20 @@ namespace YooAsset.Editor
|
||||
{
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
private string FormatListItemCallback(RuleDisplayName ruleDisplayName)
|
||||
{
|
||||
if (_showEditorAliasToggle.value)
|
||||
return ruleDisplayName.DisplayName;
|
||||
else
|
||||
return ruleDisplayName.ClassName;
|
||||
}
|
||||
private string FormatSelectedValueCallback(RuleDisplayName ruleDisplayName)
|
||||
{
|
||||
if (_showEditorAliasToggle.value)
|
||||
return ruleDisplayName.DisplayName;
|
||||
else
|
||||
return ruleDisplayName.ClassName;
|
||||
}
|
||||
|
||||
// 包裹列表相关
|
||||
private void FillPackageViewData()
|
||||
@@ -324,7 +361,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
_packageListView.selectedIndex = _lastModifyPackageIndex;
|
||||
}
|
||||
|
||||
|
||||
if (_showPackageToogle.value)
|
||||
_packageContainer.style.display = DisplayStyle.Flex;
|
||||
else
|
||||
@@ -400,7 +437,7 @@ namespace YooAsset.Editor
|
||||
_groupListView.itemsSource = selectPackage.Groups;
|
||||
_groupListView.Rebuild();
|
||||
|
||||
if(_lastModifyGroupIndex >=0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
|
||||
if (_lastModifyGroupIndex >= 0 && _lastModifyGroupIndex < _groupListView.itemsSource.Count)
|
||||
{
|
||||
_groupListView.selectedIndex = _lastModifyGroupIndex;
|
||||
}
|
||||
@@ -450,7 +487,7 @@ namespace YooAsset.Editor
|
||||
|
||||
_collectorContainer.visible = true;
|
||||
_lastModifyGroupIndex = _groupListView.selectedIndex;
|
||||
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
|
||||
_activeRulePopupField.SetValueWithoutNotify(GetActiveRuleIndex(selectGroup.ActiveRuleName));
|
||||
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
||||
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
||||
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
||||
@@ -554,21 +591,21 @@ namespace YooAsset.Editor
|
||||
}
|
||||
if (_enableAddressableToogle.value)
|
||||
{
|
||||
var popupField = new PopupField<string>(_addressRuleList, 0);
|
||||
var popupField = new PopupField<RuleDisplayName>(_addressRuleList, 0);
|
||||
popupField.name = "PopupField1";
|
||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
popupField.style.width = 200;
|
||||
elementBottom.Add(popupField);
|
||||
}
|
||||
{
|
||||
var popupField = new PopupField<string>(_packRuleList, 0);
|
||||
var popupField = new PopupField<RuleDisplayName>(_packRuleList, 0);
|
||||
popupField.name = "PopupField2";
|
||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
popupField.style.width = 150;
|
||||
popupField.style.width = 230;
|
||||
elementBottom.Add(popupField);
|
||||
}
|
||||
{
|
||||
var popupField = new PopupField<string>(_filterRuleList, 0);
|
||||
var popupField = new PopupField<RuleDisplayName>(_filterRuleList, 0);
|
||||
popupField.name = "PopupField3";
|
||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
popupField.style.width = 150;
|
||||
@@ -666,13 +703,15 @@ namespace YooAsset.Editor
|
||||
});
|
||||
|
||||
// Address Rule
|
||||
var popupField1 = element.Q<PopupField<string>>("PopupField1");
|
||||
var popupField1 = element.Q<PopupField<RuleDisplayName>>("PopupField1");
|
||||
if (popupField1 != null)
|
||||
{
|
||||
popupField1.index = GetAddressRuleIndex(collector.AddressRuleName);
|
||||
popupField1.formatListItemCallback = FormatListItemCallback;
|
||||
popupField1.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||
popupField1.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
collector.AddressRuleName = evt.newValue;
|
||||
collector.AddressRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
@@ -682,11 +721,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// Pack Rule
|
||||
var popupField2 = element.Q<PopupField<string>>("PopupField2");
|
||||
var popupField2 = element.Q<PopupField<RuleDisplayName>>("PopupField2");
|
||||
popupField2.index = GetPackRuleIndex(collector.PackRuleName);
|
||||
popupField2.formatListItemCallback = FormatListItemCallback;
|
||||
popupField2.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||
popupField2.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
collector.PackRuleName = evt.newValue;
|
||||
collector.PackRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
@@ -695,11 +736,13 @@ namespace YooAsset.Editor
|
||||
});
|
||||
|
||||
// Filter Rule
|
||||
var popupField3 = element.Q<PopupField<string>>("PopupField3");
|
||||
var popupField3 = element.Q<PopupField<RuleDisplayName>>("PopupField3");
|
||||
popupField3.index = GetFilterRuleIndex(collector.FilterRuleName);
|
||||
popupField3.formatListItemCallback = FormatListItemCallback;
|
||||
popupField3.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||
popupField3.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
collector.FilterRuleName = evt.newValue;
|
||||
collector.FilterRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
@@ -733,8 +776,8 @@ namespace YooAsset.Editor
|
||||
|
||||
try
|
||||
{
|
||||
bool enableAdressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, enableAdressable, group);
|
||||
CollectCommand command = new CollectCommand(EBuildMode.DryRunBuild, _enableAddressableToogle.value);
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
@@ -805,7 +848,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
for (int i = 0; i < _addressRuleList.Count; i++)
|
||||
{
|
||||
if (_addressRuleList[i] == ruleName)
|
||||
if (_addressRuleList[i].ClassName == ruleName)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
@@ -814,7 +857,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
for (int i = 0; i < _packRuleList.Count; i++)
|
||||
{
|
||||
if (_packRuleList[i] == ruleName)
|
||||
if (_packRuleList[i].ClassName == ruleName)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
@@ -823,11 +866,20 @@ namespace YooAsset.Editor
|
||||
{
|
||||
for (int i = 0; i < _filterRuleList.Count; i++)
|
||||
{
|
||||
if (_filterRuleList[i] == ruleName)
|
||||
if (_filterRuleList[i].ClassName == ruleName)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private RuleDisplayName GetActiveRuleIndex(string ruleName)
|
||||
{
|
||||
for (int i = 0; i < _activeRuleList.Count; i++)
|
||||
{
|
||||
if (_activeRuleList[i].ClassName == ruleName)
|
||||
return _activeRuleList[i];
|
||||
}
|
||||
return _activeRuleList[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||
<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);" />
|
||||
@@ -7,7 +7,9 @@
|
||||
</uie:Toolbar>
|
||||
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Show Editor Alias" name="ShowEditorAlias" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Unique Bundle Name" name="UniqueBundleName" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
|
||||
<ui:VisualElement name="PackageContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
|
||||
@@ -50,5 +50,13 @@ namespace YooAsset.Editor
|
||||
AssetTags = assetTags;
|
||||
IsRawAsset = isRawAsset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称追加包裹名
|
||||
/// </summary>
|
||||
public void BundleNameAppendPackageName(string packageName)
|
||||
{
|
||||
BundleName = $"{packageName.ToLower()}_{BundleName}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable { private set; get; }
|
||||
|
||||
public CollectCommand(EBuildMode buildMode, bool enableAddressable)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
EnableAddressable = enableAddressable;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e26f14db9addb4c49b4f0f520bf75d9d
|
||||
guid: b1741e85d76b28d41a4da3cd0e3e6f20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
49
Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs
Normal file
49
Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
/// </summary>
|
||||
public bool UniqueBundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 收集的资源信息列表
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> CollectAssets { private set; get; }
|
||||
|
||||
|
||||
public CollectResult(string packageName, bool enableAddressable, bool uniqueBundleName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
EnableAddressable = enableAddressable;
|
||||
UniqueBundleName = uniqueBundleName;
|
||||
}
|
||||
|
||||
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
|
||||
{
|
||||
CollectAssets = collectAssets;
|
||||
|
||||
if (UniqueBundleName)
|
||||
{
|
||||
foreach (var collectAsset in CollectAssets)
|
||||
{
|
||||
collectAsset.BundleNameAppendPackageName(PackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbbd465f929ee33408441b62d19c7d10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,9 +1,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 启用分组
|
||||
/// </summary>
|
||||
[DisplayName("启用分组")]
|
||||
public class EnableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
@@ -12,9 +10,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用分组
|
||||
/// </summary>
|
||||
[DisplayName("禁用分组")]
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 以文件名为定位地址
|
||||
/// </summary>
|
||||
[DisplayName("以文件名称为定位地址")]
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
@@ -13,9 +11,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以组名+文件名为定位地址
|
||||
/// </summary>
|
||||
[DisplayName("以分组名称+文件名称为定位地址")]
|
||||
public class AddressByGroupAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
@@ -25,9 +21,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以收集器名+文件名为定位地址
|
||||
/// </summary>
|
||||
[DisplayName("以收集器名称+文件名称为定位地址")]
|
||||
public class AddressByCollectorAndFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
|
||||
@@ -4,9 +4,7 @@ using System.IO;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集所有资源
|
||||
/// </summary>
|
||||
[DisplayName("收集所有资源")]
|
||||
public class CollectAll : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
@@ -15,9 +13,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只收集场景
|
||||
/// </summary>
|
||||
[DisplayName("收集场景")]
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
@@ -25,10 +21,8 @@ namespace YooAsset.Editor
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只收集预制体
|
||||
/// </summary>
|
||||
|
||||
[DisplayName("收集预制体")]
|
||||
public class CollectPrefab : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
@@ -37,15 +31,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只收集精灵类型的资源
|
||||
/// </summary>
|
||||
[DisplayName("收集精灵类型的纹理")]
|
||||
public class CollectSprite : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||
if(mainAssetType == typeof(Texture2D))
|
||||
if (mainAssetType == typeof(Texture2D))
|
||||
{
|
||||
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||
@@ -60,9 +52,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只收集着色器变种收集文件
|
||||
/// </summary>
|
||||
[DisplayName("收集着色器变种集合")]
|
||||
public class CollectShaderVariants : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 以文件路径作为资源包名
|
||||
/// 注意:每个文件独自打资源包
|
||||
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image/backgroud.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view/main.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("以文件路径作为资源包名")]
|
||||
public class PackSeparately : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
@@ -23,10 +23,10 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 以父类文件夹路径作为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("以父类文件夹路径作为资源包名")]
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
public static PackDirectory StaticPackRule = new PackDirectory();
|
||||
@@ -42,9 +42,10 @@ namespace YooAsset.Editor
|
||||
/// 以收集器路径下顶级文件夹为资源包名
|
||||
/// 注意:文件夹下所有文件打进一个资源包
|
||||
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop.bundle"
|
||||
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop.bundle"
|
||||
/// </summary>
|
||||
[DisplayName("以收集器路径下顶级文件夹为资源包名")]
|
||||
public class PackTopDirectory : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
@@ -70,12 +71,22 @@ namespace YooAsset.Editor
|
||||
/// 以收集器路径作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("以收集器路径作为资源包名")]
|
||||
public class PackCollector : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
string bundleName = StringUtility.RemoveExtension(data.CollectPath);
|
||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
||||
string collectPath = data.CollectPath;
|
||||
if (AssetDatabase.IsValidFolder(collectPath))
|
||||
{
|
||||
string bundleName = collectPath;
|
||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
||||
}
|
||||
else
|
||||
{
|
||||
string bundleName = StringUtility.RemoveExtension(collectPath);
|
||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +94,7 @@ namespace YooAsset.Editor
|
||||
/// 以分组名称作为资源包名
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
[DisplayName("以分组名称作为资源包名")]
|
||||
public class PackGroup : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
@@ -92,9 +104,10 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件打包模式
|
||||
/// 打包原生文件
|
||||
/// 注意:原生文件打包支持:图片,音频,视频,文本
|
||||
/// </summary>
|
||||
[DisplayName("打包原生文件")]
|
||||
public class PackRawFile : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
@@ -113,14 +126,15 @@ namespace YooAsset.Editor
|
||||
if (depends.Length != 1)
|
||||
throw new Exception($"{nameof(PackRawFile)} is not support estension : {extension}");
|
||||
|
||||
string bundleName = StringUtility.RemoveExtension(data.AssetPath);
|
||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_');
|
||||
string bundleName = data.AssetPath;
|
||||
return EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 着色器变种收集文件
|
||||
/// 打包着色器变种集合
|
||||
/// </summary>
|
||||
[DisplayName("打包着色器变种集合")]
|
||||
public class PackShaderVariants : IPackRule
|
||||
{
|
||||
public string GetBundleName(PackRuleData data)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class RuleDisplayName
|
||||
{
|
||||
public string ClassName;
|
||||
public string DisplayName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df712711c3830af419b7ada8fee53dda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -73,6 +73,10 @@ namespace YooAsset.Editor
|
||||
var sampleBtn = root.Q<Button>("SampleButton");
|
||||
sampleBtn.clicked += SampleBtn_onClick;
|
||||
|
||||
// 导出按钮
|
||||
var exportBtn = root.Q<Button>("ExportButton");
|
||||
exportBtn.clicked += ExportBtn_clicked;
|
||||
|
||||
// 用户列表菜单
|
||||
_playerName = root.Q<Label>("PlayerName");
|
||||
_playerName.text = "Editor player";
|
||||
@@ -251,6 +255,32 @@ namespace YooAsset.Editor
|
||||
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
|
||||
RemoteDebuggerInRuntime.EditorRequestDebugReport();
|
||||
}
|
||||
private void ExportBtn_clicked()
|
||||
{
|
||||
if (_currentReport == null)
|
||||
{
|
||||
Debug.LogWarning("Debug report is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
string resultPath = EditorTools.OpenFolderPanel("Export JSON", "Assets/");
|
||||
if (resultPath != null)
|
||||
{
|
||||
// 注意:排序保证生成配置的稳定性
|
||||
foreach (var packageData in _currentReport.PackageDatas)
|
||||
{
|
||||
packageData.ProviderInfos.Sort();
|
||||
foreach (var providerInfo in packageData.ProviderInfos)
|
||||
{
|
||||
providerInfo.DependBundleInfos.Sort();
|
||||
}
|
||||
}
|
||||
|
||||
string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json";
|
||||
string fileContent = JsonUtility.ToJson(_currentReport, true);
|
||||
FileUtility.CreateFile(filePath, fileContent);
|
||||
}
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<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: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="ExportButton" 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 name="FrameToolbar">
|
||||
<ui:SliderInt picking-mode="Ignore" label="Frame:" value="42" high-value="100" name="FrameSlider" style="flex-grow: 1;" />
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace YooAsset.Editor
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerAssetListViewer>();
|
||||
if (_visualAsset == null)
|
||||
return;
|
||||
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -72,15 +72,24 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private List<DebugProviderInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||
{
|
||||
var result = new List<DebugProviderInfo>(debugReport.ProviderInfos.Count);
|
||||
foreach (var providerInfo in debugReport.ProviderInfos)
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(1000);
|
||||
foreach (var packageData in debugReport.PackageDatas)
|
||||
{
|
||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
||||
var tempList = new List<DebugProviderInfo>(packageData.ProviderInfos.Count);
|
||||
foreach (var providerInfo in packageData.ProviderInfos)
|
||||
{
|
||||
if (providerInfo.AssetPath.Contains(searchKeyWord) == false)
|
||||
continue;
|
||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
||||
{
|
||||
if (providerInfo.AssetPath.Contains(searchKeyWord) == false)
|
||||
continue;
|
||||
}
|
||||
|
||||
providerInfo.PackageName = packageData.PackageName;
|
||||
tempList.Add(providerInfo);
|
||||
}
|
||||
result.Add(providerInfo);
|
||||
|
||||
tempList.Sort();
|
||||
result.AddRange(tempList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -102,12 +111,22 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
|
||||
// 资源列表相关
|
||||
// 顶部列表相关
|
||||
private VisualElement MakeAssetListViewItem()
|
||||
{
|
||||
VisualElement element = new VisualElement();
|
||||
element.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label0";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 150;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label1";
|
||||
@@ -144,7 +163,7 @@ namespace YooAsset.Editor
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 100;
|
||||
label.style.width = 150;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
@@ -154,6 +173,16 @@ namespace YooAsset.Editor
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 100;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label6";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 120;
|
||||
element.Add(label);
|
||||
}
|
||||
@@ -165,6 +194,10 @@ namespace YooAsset.Editor
|
||||
var sourceData = _assetListView.itemsSource as List<DebugProviderInfo>;
|
||||
var providerInfo = sourceData[index];
|
||||
|
||||
// Package Name
|
||||
var label0 = element.Q<Label>("Label0");
|
||||
label0.text = providerInfo.PackageName;
|
||||
|
||||
// Asset Path
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = providerInfo.AssetPath;
|
||||
@@ -177,19 +210,23 @@ namespace YooAsset.Editor
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = providerInfo.SpawnTime;
|
||||
|
||||
// Ref Count
|
||||
// Loading Time
|
||||
var label4 = element.Q<Label>("Label4");
|
||||
label4.text = providerInfo.RefCount.ToString();
|
||||
label4.text = providerInfo.LoadingTime.ToString();
|
||||
|
||||
// Ref Count
|
||||
var label5 = element.Q<Label>("Label5");
|
||||
label5.text = providerInfo.RefCount.ToString();
|
||||
|
||||
// Status
|
||||
StyleColor textColor;
|
||||
if (providerInfo.Status == (int)ProviderBase.EStatus.Fail)
|
||||
if (providerInfo.Status == ProviderBase.EStatus.Failed.ToString())
|
||||
textColor = new StyleColor(Color.yellow);
|
||||
else
|
||||
textColor = label1.style.color;
|
||||
var label5 = element.Q<Label>("Label5");
|
||||
label5.text = providerInfo.Status.ToString();
|
||||
label5.style.color = textColor;
|
||||
var label6 = element.Q<Label>("Label6");
|
||||
label6.text = providerInfo.Status.ToString();
|
||||
label6.style.color = textColor;
|
||||
}
|
||||
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
@@ -200,7 +237,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
// 依赖列表相关
|
||||
// 底部列表相关
|
||||
private VisualElement MakeDependListViewItem()
|
||||
{
|
||||
VisualElement element = new VisualElement();
|
||||
@@ -255,11 +292,11 @@ namespace YooAsset.Editor
|
||||
var label4 = element.Q<Label>("Label4");
|
||||
label4.text = bundleInfo.Status.ToString();
|
||||
}
|
||||
private void FillDependListView(DebugProviderInfo providerInfo)
|
||||
private void FillDependListView(DebugProviderInfo selectedProviderInfo)
|
||||
{
|
||||
_dependListView.Clear();
|
||||
_dependListView.ClearSelection();
|
||||
_dependListView.itemsSource = providerInfo.DependBundleInfos;
|
||||
_dependListView.itemsSource = selectedProviderInfo.DependBundleInfos;
|
||||
_dependListView.Rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
|
||||
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||
<uie:ToolbarButton text="Package Name" display-tooltip-when-elided="true" name="TopBar0" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Spawn Scene" display-tooltip-when-elided="true" name="TopBar2" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Spawn Time" display-tooltip-when-elided="true" name="TopBar3" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar4" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar5" style="width: 120px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Loading Time (ms)" display-tooltip-when-elided="true" name="TopBar4" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar5" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar6" style="width: 120px; -unity-text-align: middle-left;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -27,14 +27,14 @@ namespace YooAsset.Editor
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerBundleListViewer>();
|
||||
if (_visualAsset == null)
|
||||
return;
|
||||
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 资源包列表
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeAssetListViewItem;
|
||||
_bundleListView.bindItem = BindAssetListViewItem;
|
||||
_bundleListView.makeItem = MakeBundleListViewItem;
|
||||
_bundleListView.bindItem = BindBundleListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
#else
|
||||
@@ -46,7 +46,7 @@ namespace YooAsset.Editor
|
||||
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||
_usingListView.bindItem = BindIncludeListViewItem;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清空页面
|
||||
/// </summary>
|
||||
@@ -72,21 +72,33 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||
{
|
||||
Dictionary<string, DebugBundleInfo> result = new Dictionary<string, DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
||||
foreach (var providerInfo in debugReport.ProviderInfos)
|
||||
List<DebugBundleInfo> result = new List<DebugBundleInfo>(1000);
|
||||
foreach (var pakcageData in debugReport.PackageDatas)
|
||||
{
|
||||
foreach (var bundleInfo in providerInfo.DependBundleInfos)
|
||||
Dictionary<string, DebugBundleInfo> tempDic = new Dictionary<string, DebugBundleInfo>(1000);
|
||||
foreach (var providerInfo in pakcageData.ProviderInfos)
|
||||
{
|
||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
||||
foreach (var bundleInfo in providerInfo.DependBundleInfos)
|
||||
{
|
||||
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
||||
continue;
|
||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
||||
{
|
||||
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tempDic.ContainsKey(bundleInfo.BundleName) == false)
|
||||
{
|
||||
bundleInfo.PackageName = pakcageData.PackageName;
|
||||
tempDic.Add(bundleInfo.BundleName, bundleInfo);
|
||||
}
|
||||
}
|
||||
if (result.ContainsKey(bundleInfo.BundleName) == false)
|
||||
result.Add(bundleInfo.BundleName, bundleInfo);
|
||||
}
|
||||
|
||||
var tempList = tempDic.Values.ToList();
|
||||
tempList.Sort();
|
||||
result.AddRange(tempList);
|
||||
}
|
||||
return result.Values.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,11 +119,21 @@ namespace YooAsset.Editor
|
||||
|
||||
|
||||
// 顶部列表相关
|
||||
private VisualElement MakeAssetListViewItem()
|
||||
private VisualElement MakeBundleListViewItem()
|
||||
{
|
||||
VisualElement element = new VisualElement();
|
||||
element.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label0";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 150;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label1";
|
||||
@@ -144,11 +166,15 @@ namespace YooAsset.Editor
|
||||
|
||||
return element;
|
||||
}
|
||||
private void BindAssetListViewItem(VisualElement element, int index)
|
||||
private void BindBundleListViewItem(VisualElement element, int index)
|
||||
{
|
||||
var sourceData = _bundleListView.itemsSource as List<DebugBundleInfo>;
|
||||
var bundleInfo = sourceData[index];
|
||||
|
||||
// Package Name
|
||||
var label0 = element.Q<Label>("Label0");
|
||||
label0.text = bundleInfo.PackageName;
|
||||
|
||||
// Bundle Name
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = bundleInfo.BundleName;
|
||||
@@ -159,7 +185,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// Status
|
||||
StyleColor textColor;
|
||||
if (bundleInfo.Status == (int)AssetBundleLoaderBase.EStatus.Failed)
|
||||
if (bundleInfo.Status == BundleLoaderBase.EStatus.Failed.ToString())
|
||||
textColor = new StyleColor(Color.yellow);
|
||||
else
|
||||
textColor = label1.style.color;
|
||||
@@ -172,7 +198,7 @@ namespace YooAsset.Editor
|
||||
foreach (var item in objs)
|
||||
{
|
||||
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
||||
FillUsingListView(bundleInfo.BundleName);
|
||||
FillUsingListView(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,17 +285,23 @@ namespace YooAsset.Editor
|
||||
var label5 = element.Q<Label>("Label5");
|
||||
label5.text = providerInfo.Status.ToString();
|
||||
}
|
||||
private void FillUsingListView(string bundleName)
|
||||
{
|
||||
private void FillUsingListView(DebugBundleInfo selectedBundleInfo)
|
||||
{
|
||||
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
||||
foreach (var providerInfo in _debugReport.ProviderInfos)
|
||||
foreach (var packageData in _debugReport.PackageDatas)
|
||||
{
|
||||
foreach (var bundleInfo in providerInfo.DependBundleInfos)
|
||||
if (packageData.PackageName == selectedBundleInfo.PackageName)
|
||||
{
|
||||
if (bundleInfo.BundleName == bundleName)
|
||||
foreach (var providerInfo in packageData.ProviderInfos)
|
||||
{
|
||||
source.Add(providerInfo);
|
||||
continue;
|
||||
foreach (var bundleInfo in providerInfo.DependBundleInfos)
|
||||
{
|
||||
if (bundleInfo.BundleName == selectedBundleInfo.BundleName)
|
||||
{
|
||||
source.Add(providerInfo);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
|
||||
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||
<uie:ToolbarButton text="Package Name" display-tooltip-when-elided="true" name="TopBar0" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace YooAsset.Editor
|
||||
return;
|
||||
|
||||
_reportFilePath = selectFilePath;
|
||||
string jsonData = FileUtility.ReadFile(_reportFilePath);
|
||||
string jsonData = FileUtility.ReadAllText(_reportFilePath);
|
||||
_buildReport = BuildReport.Deserialize(jsonData);
|
||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
|
||||
private ToolbarButton _topBar1;
|
||||
private ToolbarButton _topBar2;
|
||||
private ToolbarButton _topBar3;
|
||||
private ToolbarButton _topBar4;
|
||||
private ToolbarButton _topBar5;
|
||||
private ToolbarButton _bottomBar1;
|
||||
private ListView _bundleListView;
|
||||
private ListView _includeListView;
|
||||
@@ -53,11 +53,11 @@ namespace YooAsset.Editor
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
||||
_topBar4 = _root.Q<ToolbarButton>("TopBar4");
|
||||
_topBar5 = _root.Q<ToolbarButton>("TopBar5");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
_topBar3.clicked += TopBar3_clicked;
|
||||
_topBar4.clicked += TopBar4_clicked;
|
||||
_topBar5.clicked += TopBar4_clicked;
|
||||
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
@@ -144,7 +144,7 @@ namespace YooAsset.Editor
|
||||
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
|
||||
_topBar2.text = "Size";
|
||||
_topBar3.text = "Hash";
|
||||
_topBar4.text = "Tags";
|
||||
_topBar5.text = "Tags";
|
||||
|
||||
if (_sortMode == ESortMode.BundleName)
|
||||
{
|
||||
@@ -163,9 +163,9 @@ namespace YooAsset.Editor
|
||||
else if (_sortMode == ESortMode.BundleTags)
|
||||
{
|
||||
if (_descendingSort)
|
||||
_topBar4.text = "Tags ↓";
|
||||
_topBar5.text = "Tags ↓";
|
||||
else
|
||||
_topBar4.text = "Tags ↑";
|
||||
_topBar5.text = "Tags ↑";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,6 +231,16 @@ namespace YooAsset.Editor
|
||||
label.name = "Label5";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 150;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label6";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
label.style.flexGrow = 1f;
|
||||
label.style.width = 80;
|
||||
element.Add(label);
|
||||
@@ -255,9 +265,13 @@ namespace YooAsset.Editor
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = bundleInfo.FileHash;
|
||||
|
||||
// Tags
|
||||
// LoadMethod
|
||||
var label5 = element.Q<Label>("Label5");
|
||||
label5.text = bundleInfo.GetTagsString();
|
||||
label5.text = bundleInfo.LoadMethod.ToString();
|
||||
|
||||
// Tags
|
||||
var label6 = element.Q<Label>("Label6");
|
||||
label6.text = bundleInfo.GetTagsString();
|
||||
}
|
||||
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
@@ -271,7 +285,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
|
||||
{
|
||||
if (bundleInfo.IsRawFile())
|
||||
if (bundleInfo.IsRawFile)
|
||||
return;
|
||||
|
||||
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar4" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="LoadMethod" display-tooltip-when-elided="true" name="TopBar4" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace YooAsset.Editor
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterSummaryViewer>();
|
||||
if (_visualAsset == null)
|
||||
return;
|
||||
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace YooAsset.Editor
|
||||
public void FillViewData(BuildReport buildReport)
|
||||
{
|
||||
_buildReport = buildReport;
|
||||
|
||||
|
||||
_items.Clear();
|
||||
|
||||
_items.Add(new ItemWrapper("YooAsset版本", buildReport.Summary.YooVersion));
|
||||
@@ -66,9 +66,11 @@ namespace YooAsset.Editor
|
||||
_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.BuildPackage}"));
|
||||
_items.Add(new ItemWrapper("包裹名称", buildReport.Summary.BuildPackageName));
|
||||
_items.Add(new ItemWrapper("包裹版本", buildReport.Summary.BuildPackageVersion));
|
||||
|
||||
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
|
||||
_items.Add(new ItemWrapper("资源包名唯一化", $"{buildReport.Summary.UniqueBundleName}"));
|
||||
_items.Add(new ItemWrapper("加密服务类名称", $"{buildReport.Summary.EncryptionServicesClassName}"));
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
|
||||
36
Assets/YooAsset/Editor/EditorAttribute.cs
Normal file
36
Assets/YooAsset/Editor/EditorAttribute.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器显示名字
|
||||
/// </summary>
|
||||
public class DisplayNameAttribute : Attribute
|
||||
{
|
||||
public string DisplayName;
|
||||
|
||||
public DisplayNameAttribute(string name)
|
||||
{
|
||||
this.DisplayName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditorAttribute
|
||||
{
|
||||
internal static T GetAttribute<T>(Type type) where T : Attribute
|
||||
{
|
||||
return (T)type.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
|
||||
internal static T GetAttribute<T>(MethodInfo methodInfo) where T : Attribute
|
||||
{
|
||||
return (T)methodInfo.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
|
||||
internal static T GetAttribute<T>(FieldInfo field) where T : Attribute
|
||||
{
|
||||
return (T)field.GetCustomAttribute(typeof(T), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Editor/EditorAttribute.cs.meta
Normal file
11
Assets/YooAsset/Editor/EditorAttribute.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92d5f73b21059af43b7f56165b7acd63
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,7 +8,14 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 停靠窗口类型集合
|
||||
/// </summary>
|
||||
public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleCollectorWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)};
|
||||
public static readonly Type[] DockedWindowTypes =
|
||||
{
|
||||
typeof(AssetBundleBuilderWindow),
|
||||
typeof(AssetBundleCollectorWindow),
|
||||
typeof(AssetBundleDebuggerWindow),
|
||||
typeof(AssetBundleReporterWindow),
|
||||
typeof(ShaderVariantCollectorWindow)
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace YooAsset.Editor
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>();
|
||||
|
||||
/*
|
||||
static EditorHelper()
|
||||
{
|
||||
// 资源包收集
|
||||
@@ -51,6 +52,46 @@ namespace YooAsset.Editor
|
||||
throw new System.Exception($"Invalid YooAsset window type : {windowType}");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 加载窗口的布局文件
|
||||
/// </summary>
|
||||
public static UnityEngine.UIElements.VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class
|
||||
{
|
||||
var windowType = typeof(TWindow);
|
||||
|
||||
// 缓存里查询并加载
|
||||
if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID))
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID);
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
{
|
||||
_uxmlDic.Clear();
|
||||
throw new System.Exception($"Invalid UXML GUID : {uxmlGUID} ! Please close the window and open it again !");
|
||||
}
|
||||
var treeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
|
||||
return treeAsset;
|
||||
}
|
||||
|
||||
// 全局搜索并加载
|
||||
string[] guids = AssetDatabase.FindAssets(windowType.Name);
|
||||
if (guids.Length == 0)
|
||||
throw new System.Exception($"Not found any assets : {windowType.Name}");
|
||||
|
||||
foreach (string assetGUID in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);
|
||||
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.UIElements.VisualTreeAsset))
|
||||
{
|
||||
_uxmlDic.Add(windowType, assetGUID);
|
||||
var treeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
|
||||
return treeAsset;
|
||||
}
|
||||
}
|
||||
throw new System.Exception($"Not found UXML file : {windowType.Name}");
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -349,9 +349,9 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件移动
|
||||
/// 移动文件
|
||||
/// </summary>
|
||||
public static void FileMoveTo(string filePath, string destPath)
|
||||
public static void MoveFile(string filePath, string destPath)
|
||||
{
|
||||
if (File.Exists(destPath))
|
||||
File.Delete(destPath);
|
||||
@@ -359,7 +359,7 @@ namespace YooAsset.Editor
|
||||
FileInfo fileInfo = new FileInfo(filePath);
|
||||
fileInfo.MoveTo(destPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝文件夹
|
||||
/// 注意:包括所有子目录的文件
|
||||
|
||||
@@ -9,7 +9,8 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public static class ShaderVariantCollectionReadme
|
||||
[Serializable]
|
||||
public class ShaderVariantCollectionManifest
|
||||
{
|
||||
[Serializable]
|
||||
public class ShaderVariantElement
|
||||
@@ -44,52 +45,49 @@ namespace YooAsset.Editor
|
||||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ShaderVariantCollectionManifest
|
||||
|
||||
/// <summary>
|
||||
/// Number of shaders in this collection
|
||||
/// </summary>
|
||||
public int ShaderTotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// Number of total varians in this collection
|
||||
/// </summary>
|
||||
public int VariantTotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// Shader variants info list.
|
||||
/// </summary>
|
||||
public List<ShaderVariantInfo> ShaderVariantInfos = new List<ShaderVariantInfo>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 添加着色器变种信息
|
||||
/// </summary>
|
||||
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of shaders in this collection
|
||||
/// </summary>
|
||||
public int ShaderTotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// Number of total varians in this collection
|
||||
/// </summary>
|
||||
public int VariantTotalCount;
|
||||
|
||||
/// <summary>
|
||||
/// Shader variants info list.
|
||||
/// </summary>
|
||||
public List<ShaderVariantInfo> ShaderVariantInfos = new List<ShaderVariantInfo>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 添加着色器变种信息
|
||||
/// </summary>
|
||||
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
||||
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
||||
ShaderVariantElement element = new ShaderVariantElement();
|
||||
element.PassType = passType;
|
||||
element.Keywords = keywords;
|
||||
info.ShaderVariantElements.Add(element);
|
||||
}
|
||||
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
|
||||
{
|
||||
var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList();
|
||||
if (selectList.Count == 0)
|
||||
{
|
||||
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
||||
ShaderVariantElement element = new ShaderVariantElement();
|
||||
element.PassType = passType;
|
||||
element.Keywords = keywords;
|
||||
info.ShaderVariantElements.Add(element);
|
||||
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
||||
newInfo.AssetPath = assetPath;
|
||||
newInfo.ShaderName = shaderName;
|
||||
ShaderVariantInfos.Add(newInfo);
|
||||
return newInfo;
|
||||
}
|
||||
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
|
||||
{
|
||||
var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList();
|
||||
if (selectList.Count == 0)
|
||||
{
|
||||
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
||||
newInfo.AssetPath = assetPath;
|
||||
newInfo.ShaderName = shaderName;
|
||||
ShaderVariantInfos.Add(newInfo);
|
||||
return newInfo;
|
||||
}
|
||||
|
||||
if (selectList.Count != 1)
|
||||
throw new Exception("Should never get here !");
|
||||
if (selectList.Count != 1)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
return selectList[0];
|
||||
}
|
||||
return selectList[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace YooAsset.Editor
|
||||
// 保存结果
|
||||
ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_saveFilePath);
|
||||
|
||||
// 创建说明文件
|
||||
CreateReadme();
|
||||
// 创建清单
|
||||
CreateManifest();
|
||||
|
||||
Debug.Log($"搜集SVC完毕!");
|
||||
_completedCallback?.Invoke();
|
||||
@@ -52,7 +52,7 @@ namespace YooAsset.Editor
|
||||
throw new System.Exception("Shader variant file extension is invalid.");
|
||||
|
||||
// 注意:先删除再保存,否则ShaderVariantCollection内容将无法及时刷新
|
||||
AssetDatabase.DeleteAsset(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||
AssetDatabase.DeleteAsset(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||
EditorTools.CreateFileDirectory(saveFilePath);
|
||||
_saveFilePath = saveFilePath;
|
||||
_completedCallback = completedCallback;
|
||||
@@ -64,7 +64,7 @@ namespace YooAsset.Editor
|
||||
ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection();
|
||||
|
||||
// 创建临时测试场景
|
||||
CreateTemperScene();
|
||||
CreateTempScene();
|
||||
|
||||
// 收集着色器变种
|
||||
var materials = GetAllMaterials();
|
||||
@@ -76,9 +76,8 @@ namespace YooAsset.Editor
|
||||
_elapsedTime.Start();
|
||||
}
|
||||
|
||||
private static void CreateTemperScene()
|
||||
private static void CreateTempScene()
|
||||
{
|
||||
// 创建临时场景
|
||||
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||
}
|
||||
private static List<Material> GetAllMaterials()
|
||||
@@ -87,9 +86,14 @@ namespace YooAsset.Editor
|
||||
List<string> allAssets = new List<string>(1000);
|
||||
|
||||
// 获取所有打包的资源
|
||||
List<CollectAssetInfo> allCollectInfos = AssetBundleCollectorSettingData.Setting.GetAllPackageAssets(EBuildMode.DryRunBuild);
|
||||
List<string> collectAssets = allCollectInfos.Select(t => t.AssetPath).ToList();
|
||||
foreach (var assetPath in collectAssets)
|
||||
List<CollectAssetInfo> allCollectAssetInfos = new List<CollectAssetInfo>();
|
||||
List<CollectResult> collectResults = AssetBundleCollectorSettingData.Setting.GetAllPackageAssets(EBuildMode.DryRunBuild);
|
||||
foreach (var collectResult in collectResults)
|
||||
{
|
||||
allCollectAssetInfos.AddRange(collectResult.CollectAssets);
|
||||
}
|
||||
List<string> allAssetPath = allCollectAssetInfos.Select(t => t.AssetPath).ToList();
|
||||
foreach (var assetPath in allAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(assetPath, true);
|
||||
foreach (var depend in depends)
|
||||
@@ -97,7 +101,7 @@ namespace YooAsset.Editor
|
||||
if (allAssets.Contains(depend) == false)
|
||||
allAssets.Add(depend);
|
||||
}
|
||||
EditorTools.DisplayProgressBar("获取所有打包资源", ++progressValue, collectAssets.Count);
|
||||
EditorTools.DisplayProgressBar("获取所有打包资源", ++progressValue, allAssetPath.Count);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
@@ -181,17 +185,17 @@ namespace YooAsset.Editor
|
||||
go.transform.position = position;
|
||||
go.name = $"Sphere_{index}|{material.name}";
|
||||
}
|
||||
private static void CreateReadme()
|
||||
private static void CreateManifest()
|
||||
{
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
|
||||
ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(_saveFilePath);
|
||||
if (svc != null)
|
||||
{
|
||||
var wrapper = ShaderVariantCollectionReadme.Extract(svc);
|
||||
string jsonContents = JsonUtility.ToJson(wrapper, true);
|
||||
string savePath = _saveFilePath.Replace(".shadervariants", "Manifest.json");
|
||||
File.WriteAllText(savePath, jsonContents);
|
||||
var wrapper = ShaderVariantCollectionManifest.Extract(svc);
|
||||
string jsonData = JsonUtility.ToJson(wrapper, true);
|
||||
string savePath = _saveFilePath.Replace(".shadervariants", ".json");
|
||||
File.WriteAllText(savePath, jsonData);
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
|
||||
@@ -1,61 +1,82 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class ShaderVariantCollectionWindow : EditorWindow
|
||||
public class ShaderVariantCollectorWindow : EditorWindow
|
||||
{
|
||||
static ShaderVariantCollectionWindow _thisInstance;
|
||||
|
||||
[MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
|
||||
static void ShowWindow()
|
||||
public static void ShowExample()
|
||||
{
|
||||
if (_thisInstance == null)
|
||||
{
|
||||
_thisInstance = GetWindow<ShaderVariantCollectionWindow>("着色器变种收集工具");
|
||||
_thisInstance.minSize = new Vector2(800, 600);
|
||||
}
|
||||
_thisInstance.Show();
|
||||
ShaderVariantCollectorWindow window = GetWindow<ShaderVariantCollectorWindow>("着色器变种收集工具", true, EditorDefine.DockedWindowTypes);
|
||||
window.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
private ShaderVariantCollection _selectSVC;
|
||||
private Button _collectButton;
|
||||
private TextField _collectOutputField;
|
||||
private Label _currentShaderCountField;
|
||||
private Label _currentVariantCountField;
|
||||
|
||||
private void OnGUI()
|
||||
public void CreateGUI()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
ShaderVariantCollectorSettingData.Setting.SavePath = EditorGUILayout.TextField("收集文件保存路径", ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||
|
||||
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
|
||||
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
||||
EditorGUILayout.LabelField($"CurrentShaderCount : {currentShaderCount}");
|
||||
EditorGUILayout.LabelField($"CurrentVariantCount : {currentVariantCount}");
|
||||
|
||||
// 搜集变种
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
|
||||
try
|
||||
{
|
||||
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath, null);
|
||||
}
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 查询
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("查询", GUILayout.MaxWidth(80)))
|
||||
{
|
||||
string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "shadervariants");
|
||||
if (string.IsNullOrEmpty(resultPath))
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<ShaderVariantCollectorWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
string assetPath = EditorTools.AbsolutePathToAssetPath(resultPath);
|
||||
_selectSVC = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(assetPath);
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 文件输出目录
|
||||
_collectOutputField = root.Q<TextField>("CollectOutput");
|
||||
_collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||
_collectOutputField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
ShaderVariantCollectorSettingData.Setting.SavePath = _collectOutputField.value;
|
||||
});
|
||||
|
||||
_currentShaderCountField = root.Q<Label>("CurrentShaderCount");
|
||||
_currentVariantCountField = root.Q<Label>("CurrentVariantCount");
|
||||
|
||||
// 变种收集按钮
|
||||
_collectButton = root.Q<Button>("CollectButton");
|
||||
_collectButton.clicked += CollectButton_clicked;
|
||||
|
||||
//RefreshWindow();
|
||||
}
|
||||
if (_selectSVC != null)
|
||||
catch (Exception e)
|
||||
{
|
||||
EditorGUILayout.LabelField($"ShaderCount : {_selectSVC.shaderCount}");
|
||||
EditorGUILayout.LabelField($"VariantCount : {_selectSVC.variantCount}");
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
private void Update()
|
||||
{
|
||||
ShaderVariantCollectorSettingData.SaveFile();
|
||||
if (_currentShaderCountField != null)
|
||||
{
|
||||
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
|
||||
_currentShaderCountField.text = $"Current Shader Count : {currentShaderCount}";
|
||||
}
|
||||
|
||||
if (_currentVariantCountField != null)
|
||||
{
|
||||
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
||||
_currentVariantCountField.text = $"Current Variant Count : {currentVariantCount}";
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectButton_clicked()
|
||||
{
|
||||
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
<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;" />
|
||||
<ui:VisualElement name="BuildContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="文件保存路径" name="CollectOutput" />
|
||||
<ui:Label text="Current Shader Count" display-tooltip-when-elided="true" name="CurrentShaderCount" />
|
||||
<ui:Label text="Current Variant Count" display-tooltip-when-elided="true" name="CurrentVariantCount" />
|
||||
<ui:Button text="开始搜集" display-tooltip-when-elided="true" name="CollectButton" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bff4878063eaf04dab8713e1e662ac5
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -8,13 +8,11 @@ namespace YooAsset
|
||||
{
|
||||
internal class AssetSystemImpl
|
||||
{
|
||||
private static string SceneRunningPackage = string.Empty;
|
||||
|
||||
private readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
|
||||
private readonly List<BundleLoaderBase> _loaders = new List<BundleLoaderBase>(1000);
|
||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
||||
private readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||
private readonly static Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||
private static long _sceneCreateCount = 0;
|
||||
|
||||
private long _sceneCreateCount = 0;
|
||||
private bool _simulationOnEditor;
|
||||
private int _loadingMaxNumber;
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
@@ -71,10 +69,19 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void DestroyAll()
|
||||
{
|
||||
_loaders.Clear();
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
_providers.Clear();
|
||||
_sceneHandles.Clear();
|
||||
|
||||
foreach (var loader in _loaders)
|
||||
{
|
||||
loader.Destroy(true);
|
||||
}
|
||||
_loaders.Clear();
|
||||
|
||||
ClearSceneHandle();
|
||||
DecryptionServices = null;
|
||||
BundleServices = null;
|
||||
}
|
||||
@@ -83,6 +90,15 @@ namespace YooAsset
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// </summary>
|
||||
public void UnloadUnusedAssets()
|
||||
{
|
||||
// 注意:资源包之间可能存在多层深层嵌套,需要多次循环释放。
|
||||
int loopCount = 10;
|
||||
for (int i = 0; i < loopCount; i++)
|
||||
{
|
||||
UnloadUnusedAssetsInternal();
|
||||
}
|
||||
}
|
||||
private void UnloadUnusedAssetsInternal()
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
{
|
||||
@@ -99,12 +115,12 @@ namespace YooAsset
|
||||
{
|
||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||
{
|
||||
AssetBundleLoaderBase loader = _loaders[i];
|
||||
BundleLoaderBase loader = _loaders[i];
|
||||
loader.TryDestroyAllProviders();
|
||||
}
|
||||
for (int i = _loaders.Count - 1; i >= 0; i--)
|
||||
{
|
||||
AssetBundleLoaderBase loader = _loaders[i];
|
||||
BundleLoaderBase loader = _loaders[i];
|
||||
if (loader.CanDestroy())
|
||||
{
|
||||
loader.Destroy(false);
|
||||
@@ -123,13 +139,14 @@ namespace YooAsset
|
||||
{
|
||||
provider.Destroy();
|
||||
}
|
||||
_providers.Clear();
|
||||
|
||||
foreach (var loader in _loaders)
|
||||
{
|
||||
loader.Destroy(true);
|
||||
}
|
||||
|
||||
_providers.Clear();
|
||||
_loaders.Clear();
|
||||
ClearSceneHandle();
|
||||
|
||||
// 注意:调用底层接口释放所有资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
@@ -142,24 +159,12 @@ namespace YooAsset
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<SceneOperationHandle>();
|
||||
}
|
||||
|
||||
// 注意:场景只允许运行在一个资源包内
|
||||
if (string.IsNullOrEmpty(SceneRunningPackage))
|
||||
{
|
||||
SceneRunningPackage = BundleServices.GetPackageName();
|
||||
}
|
||||
if (BundleServices.GetPackageName() != SceneRunningPackage)
|
||||
{
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
string error = $"Scene are allowed to running within only {SceneRunningPackage}";
|
||||
completedProvider.SetCompleted(error);
|
||||
return completedProvider.CreateHandle<SceneOperationHandle>();
|
||||
}
|
||||
|
||||
// 如果加载的是主场景,则卸载所有缓存的场景
|
||||
if (sceneMode == LoadSceneMode.Single)
|
||||
{
|
||||
@@ -179,6 +184,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
var handle = provider.CreateHandle<SceneOperationHandle>();
|
||||
handle.PackageName = BundleServices.GetPackageName();
|
||||
_sceneHandles.Add(providerGUID, handle);
|
||||
return handle;
|
||||
}
|
||||
@@ -190,6 +196,7 @@ namespace YooAsset
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load asset ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<AssetOperationHandle>();
|
||||
@@ -216,6 +223,7 @@ namespace YooAsset
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
|
||||
@@ -235,6 +243,33 @@ namespace YooAsset
|
||||
return provider.CreateHandle<SubAssetsOperationHandle>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载原生文件
|
||||
/// </summary>
|
||||
public RawFileOperationHandle LoadRawFileAsync(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<RawFileOperationHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseRawFileProvider(this, providerGUID, assetInfo);
|
||||
else
|
||||
provider = new BundledRawFileProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
}
|
||||
return provider.CreateHandle<RawFileOperationHandle>();
|
||||
}
|
||||
|
||||
internal void UnloadSubScene(ProviderBase provider)
|
||||
{
|
||||
string providerGUID = provider.ProviderGUID;
|
||||
@@ -260,19 +295,39 @@ namespace YooAsset
|
||||
// 卸载未被使用的资源(包括场景)
|
||||
UnloadUnusedAssets();
|
||||
}
|
||||
internal void ClearSceneHandle()
|
||||
{
|
||||
// 释放资源包下的所有场景
|
||||
if (BundleServices.IsServicesValid())
|
||||
{
|
||||
string packageName = BundleServices.GetPackageName();
|
||||
List<string> removeList = new List<string>();
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
if (valuePair.Value.PackageName == packageName)
|
||||
{
|
||||
removeList.Add(valuePair.Key);
|
||||
}
|
||||
}
|
||||
foreach (var key in removeList)
|
||||
{
|
||||
_sceneHandles.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal AssetBundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
|
||||
internal BundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo bundleInfo = BundleServices.GetBundleInfo(assetInfo);
|
||||
return CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
}
|
||||
internal List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
|
||||
internal List<BundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo[] depends = BundleServices.GetAllDependBundleInfos(assetInfo);
|
||||
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>(depends.Length);
|
||||
List<BundleLoaderBase> result = new List<BundleLoaderBase>(depends.Length);
|
||||
foreach (var bundleInfo in depends)
|
||||
{
|
||||
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
BundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
result.Add(dependLoader);
|
||||
}
|
||||
return result;
|
||||
@@ -285,10 +340,10 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
private AssetBundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
||||
private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
||||
{
|
||||
// 如果加载器已经存在
|
||||
AssetBundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.Bundle.BundleName);
|
||||
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleInfo.Bundle.BundleName);
|
||||
if (loader != null)
|
||||
return loader;
|
||||
|
||||
@@ -296,18 +351,21 @@ namespace YooAsset
|
||||
#if UNITY_WEBGL
|
||||
loader = new AssetBundleWebLoader(this, bundleInfo);
|
||||
#else
|
||||
loader = new AssetBundleFileLoader(this, bundleInfo);
|
||||
if (bundleInfo.Bundle.IsRawFile)
|
||||
loader = new RawBundleFileLoader(this, bundleInfo);
|
||||
else
|
||||
loader = new AssetBundleFileLoader(this, bundleInfo);
|
||||
#endif
|
||||
|
||||
_loaders.Add(loader);
|
||||
return loader;
|
||||
}
|
||||
private AssetBundleLoaderBase TryGetAssetBundleLoader(string bundleName)
|
||||
private BundleLoaderBase TryGetAssetBundleLoader(string bundleName)
|
||||
{
|
||||
AssetBundleLoaderBase loader = null;
|
||||
BundleLoaderBase loader = null;
|
||||
for (int i = 0; i < _loaders.Count; i++)
|
||||
{
|
||||
AssetBundleLoaderBase temp = _loaders[i];
|
||||
BundleLoaderBase temp = _loaders[i];
|
||||
if (temp.MainBundleInfo.Bundle.BundleName.Equals(bundleName))
|
||||
{
|
||||
loader = temp;
|
||||
@@ -338,12 +396,12 @@ namespace YooAsset
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
DebugProviderInfo providerInfo = new DebugProviderInfo();
|
||||
providerInfo.PackageName = BundleServices.GetPackageName();
|
||||
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
|
||||
providerInfo.SpawnScene = provider.SpawnScene;
|
||||
providerInfo.SpawnTime = provider.SpawnTime;
|
||||
providerInfo.LoadingTime = provider.LoadingTime;
|
||||
providerInfo.RefCount = provider.RefCount;
|
||||
providerInfo.Status = (int)provider.Status;
|
||||
providerInfo.Status = provider.Status.ToString();
|
||||
providerInfo.DependBundleInfos = new List<DebugBundleInfo>();
|
||||
result.Add(providerInfo);
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class AssetOperationHandle : OperationHandleBase
|
||||
public sealed class AssetOperationHandle : OperationHandleBase, IDisposable
|
||||
{
|
||||
private System.Action<AssetOperationHandle> _callback;
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace YooAsset
|
||||
{
|
||||
add
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
@@ -31,42 +32,18 @@ namespace YooAsset
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(AssetOperationHandle)} is invalid");
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
public UnityEngine.Object AssetObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
return null;
|
||||
return Provider.AssetObject;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
@@ -79,6 +56,38 @@ namespace YooAsset
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
/// </summary>
|
||||
public UnityEngine.Object AssetObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
return Provider.AssetObject;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TAsset">资源类型</typeparam>
|
||||
public TAsset GetAssetObject<TAsset>() where TAsset : UnityEngine.Object
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
return Provider.AssetObject as TAsset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步初始化游戏对象
|
||||
@@ -87,7 +96,7 @@ namespace YooAsset
|
||||
/// <returns></returns>
|
||||
public GameObject InstantiateSync(Transform parent = null)
|
||||
{
|
||||
return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent, false);
|
||||
return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,7 +107,7 @@ namespace YooAsset
|
||||
/// <param name="parent">父类对象</param>
|
||||
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
|
||||
{
|
||||
return InstantiateSyncInternal(position, rotation, parent, true);
|
||||
return InstantiateSyncInternal(position, rotation, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,7 +116,7 @@ namespace YooAsset
|
||||
/// <param name="parent">父类对象</param>
|
||||
public InstantiateOperation InstantiateAsync(Transform parent = null)
|
||||
{
|
||||
return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent, false);
|
||||
return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,37 +127,23 @@ namespace YooAsset
|
||||
/// <param name="parent">父类对象</param>
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
|
||||
{
|
||||
return InstantiateAsyncInternal(position, rotation, parent, true);
|
||||
return InstantiateAsyncInternal(position, rotation, parent);
|
||||
}
|
||||
|
||||
|
||||
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||
private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent)
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
if (Provider.AssetObject == null)
|
||||
return null;
|
||||
|
||||
GameObject result;
|
||||
if (setPositionRotation)
|
||||
{
|
||||
if (parent == null)
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation);
|
||||
else
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent == null)
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject);
|
||||
else
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
|
||||
}
|
||||
return result;
|
||||
GameObject clone = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
||||
return clone;
|
||||
}
|
||||
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent)
|
||||
{
|
||||
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
|
||||
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -14,7 +15,6 @@ namespace YooAsset
|
||||
}
|
||||
internal abstract void InvokeCallback();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息
|
||||
/// </summary>
|
||||
@@ -30,11 +30,11 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return EOperationStatus.None;
|
||||
if (Provider.Status == ProviderBase.EStatus.Fail)
|
||||
if (Provider.Status == ProviderBase.EStatus.Failed)
|
||||
return EOperationStatus.Failed;
|
||||
else if (Provider.Status == ProviderBase.EStatus.Success)
|
||||
else if (Provider.Status == ProviderBase.EStatus.Succeed)
|
||||
return EOperationStatus.Succeed;
|
||||
else
|
||||
return EOperationStatus.None;
|
||||
@@ -48,7 +48,7 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return string.Empty;
|
||||
return Provider.LastError;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return 0;
|
||||
return Provider.Progress;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
return Provider.IsDone;
|
||||
}
|
||||
@@ -84,6 +84,20 @@ namespace YooAsset
|
||||
/// 句柄是否有效
|
||||
/// </summary>
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Provider != null && Provider.IsDestroyed == false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 句柄是否有效
|
||||
/// </summary>
|
||||
internal bool IsValidWithWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -102,26 +116,12 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 句柄是否有效
|
||||
/// </summary>
|
||||
public bool IsValidNoWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Provider != null && Provider.IsDestroyed == false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放句柄
|
||||
/// </summary>
|
||||
internal void ReleaseInternal()
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
Provider = null;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class RawFileOperationHandle : OperationHandleBase, IDisposable
|
||||
{
|
||||
private System.Action<RawFileOperationHandle> _callback;
|
||||
|
||||
internal RawFileOperationHandle(ProviderBase provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
{
|
||||
_callback?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 完成委托
|
||||
/// </summary>
|
||||
public event System.Action<RawFileOperationHandle> Completed
|
||||
{
|
||||
add
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
else
|
||||
_callback += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(RawFileOperationHandle)} is invalid");
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的二进制数据
|
||||
/// </summary>
|
||||
public byte[] GetRawFileData()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
if (File.Exists(filePath) == false)
|
||||
return null;
|
||||
return File.ReadAllBytes(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的文本数据
|
||||
/// </summary>
|
||||
public string GetRawFileText()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
if (File.Exists(filePath) == false)
|
||||
return null;
|
||||
return File.ReadAllText(filePath, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的路径
|
||||
/// </summary>
|
||||
public string GetRawFilePath()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return string.Empty;
|
||||
return Provider.RawFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8420ba734d425a4ba9f19173d74503c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
public class SceneOperationHandle : OperationHandleBase
|
||||
{
|
||||
{
|
||||
private System.Action<SceneOperationHandle> _callback;
|
||||
internal string PackageName { set; get; }
|
||||
|
||||
internal SceneOperationHandle(ProviderBase provider) : base(provider)
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace YooAsset
|
||||
{
|
||||
add
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
@@ -30,7 +31,7 @@ namespace YooAsset
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneOperationHandle)} is invalid");
|
||||
_callback -= value;
|
||||
}
|
||||
@@ -43,7 +44,7 @@ namespace YooAsset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return new Scene();
|
||||
return Provider.SceneObject;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool ActivateScene()
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (SceneObject.IsValid() && SceneObject.isLoaded)
|
||||
@@ -73,7 +74,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IsMainScene()
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
@@ -98,7 +99,7 @@ namespace YooAsset
|
||||
public UnloadSceneOperation UnloadAsync()
|
||||
{
|
||||
// 如果句柄无效
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
{
|
||||
string error = $"{nameof(SceneOperationHandle)} is invalid.";
|
||||
var operation = new UnloadSceneOperation(error);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class SubAssetsOperationHandle : OperationHandleBase
|
||||
public sealed class SubAssetsOperationHandle : OperationHandleBase, IDisposable
|
||||
{
|
||||
private System.Action<SubAssetsOperationHandle> _callback;
|
||||
|
||||
@@ -21,7 +22,7 @@ namespace YooAsset
|
||||
{
|
||||
add
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
@@ -30,31 +31,18 @@ namespace YooAsset
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SubAssetsOperationHandle)} is invalid");
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValid == false)
|
||||
return null;
|
||||
return Provider.AllAssetObjects;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
@@ -67,6 +55,27 @@ namespace YooAsset
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
return Provider.AllAssetObjects;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取子资源对象
|
||||
@@ -75,7 +84,7 @@ namespace YooAsset
|
||||
/// <param name="assetName">子资源对象名称</param>
|
||||
public TObject GetSubAssetObject<TObject>(string assetName) where TObject : UnityEngine.Object
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
|
||||
foreach (var assetObject in Provider.AllAssetObjects)
|
||||
@@ -94,7 +103,7 @@ namespace YooAsset
|
||||
/// <typeparam name="TObject">子资源对象类型</typeparam>
|
||||
public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object
|
||||
{
|
||||
if (IsValid == false)
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
|
||||
List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);
|
||||
|
||||
@@ -6,24 +6,27 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class AssetBundleFileLoader : AssetBundleLoaderBase
|
||||
internal sealed class AssetBundleFileLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None = 0,
|
||||
Download,
|
||||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
LoadFile,
|
||||
CheckLoadFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private string _fileLoadPath;
|
||||
private bool _isWaitForAsyncComplete = false;
|
||||
private bool _isShowWaitForAsyncError = false;
|
||||
private DownloaderBase _unpacker;
|
||||
private DownloaderBase _downloader;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
private FileStream _fileStream;
|
||||
|
||||
|
||||
public AssetBundleFileLoader(AssetSystemImpl impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
@@ -43,17 +46,31 @@ namespace YooAsset
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
EBundleLoadMethod loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.LoadFromMemory || loadMethod == EBundleLoadMethod.LoadFromStream)
|
||||
{
|
||||
_steps = ESteps.Unpack;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
}
|
||||
#else
|
||||
_steps = ESteps.LoadFile;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -87,47 +104,106 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 加载AssetBundle
|
||||
// 3. 内置文件解压
|
||||
if (_steps == ESteps.Unpack)
|
||||
{
|
||||
int failedTryAgain = 1;
|
||||
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
|
||||
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckUnpack;
|
||||
}
|
||||
|
||||
// 4.检测内置文件解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_unpacker.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _unpacker.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadFile)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||
if (System.IO.File.Exists(_fileLoadPath) == false)
|
||||
if (System.IO.File.Exists(FileLoadPath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Not found assetBundle file : {_fileLoadPath}";
|
||||
LastError = $"Not found assetBundle file : {FileLoadPath}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Load assetBundle file
|
||||
if (MainBundleInfo.Bundle.IsEncrypted)
|
||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.Normal)
|
||||
{
|
||||
if (Impl.DecryptionServices == null)
|
||||
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.Bundle.BundleName}");
|
||||
|
||||
DecryptionFileInfo fileInfo = new DecryptionFileInfo();
|
||||
fileInfo.BundleName = MainBundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileHash = MainBundleInfo.Bundle.FileHash;
|
||||
ulong offset = Impl.DecryptionServices.GetFileOffset(fileInfo);
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
|
||||
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath);
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath, 0, offset);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath);
|
||||
if (Impl.DecryptionServices == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"{nameof(IDecryptionServices)} is null : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
|
||||
DecryptFileInfo fileInfo = new DecryptFileInfo();
|
||||
fileInfo.BundleName = MainBundleInfo.Bundle.BundleName;
|
||||
fileInfo.FilePath = FileLoadPath;
|
||||
|
||||
if (loadMethod == EBundleLoadMethod.LoadFromFileOffset)
|
||||
{
|
||||
ulong offset = Impl.DecryptionServices.LoadFromFileOffset(fileInfo);
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath, 0, offset);
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath, 0, offset);
|
||||
}
|
||||
else if (loadMethod == EBundleLoadMethod.LoadFromMemory)
|
||||
{
|
||||
byte[] fileData = Impl.DecryptionServices.LoadFromMemory(fileInfo);
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromMemory(fileData);
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromMemoryAsync(fileData);
|
||||
}
|
||||
else if (loadMethod == EBundleLoadMethod.LoadFromStream)
|
||||
{
|
||||
_fileStream = Impl.DecryptionServices.LoadFromStream(fileInfo);
|
||||
uint managedReadBufferSize = Impl.DecryptionServices.GetManagedReadBufferSize();
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromStream(_fileStream, 0, managedReadBufferSize);
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromStreamAsync(_fileStream, 0, managedReadBufferSize);
|
||||
}
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 4. 检测AssetBundle加载结果
|
||||
// 6. 检测AssetBundle加载结果
|
||||
if (_steps == ESteps.CheckLoadFile)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
@@ -177,6 +253,21 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public override void Destroy(bool forceDestroy)
|
||||
{
|
||||
base.Destroy(forceDestroy);
|
||||
|
||||
if (_fileStream != null)
|
||||
{
|
||||
_fileStream.Close();
|
||||
_fileStream.Dispose();
|
||||
_fileStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
@@ -187,6 +278,14 @@ namespace YooAsset
|
||||
int frame = 1000;
|
||||
while (true)
|
||||
{
|
||||
// 文件解压
|
||||
if (_unpacker != null)
|
||||
{
|
||||
_unpacker.Update();
|
||||
if (_unpacker.IsDone() == false)
|
||||
continue;
|
||||
}
|
||||
|
||||
// 保险机制
|
||||
// 注意:如果需要从WEB端下载资源,可能会触发保险机制!
|
||||
frame--;
|
||||
|
||||
@@ -7,7 +7,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class AssetBundleWebLoader : AssetBundleLoaderBase
|
||||
internal sealed class AssetBundleWebLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
@@ -17,20 +17,19 @@ namespace YooAsset
|
||||
LoadCacheFile,
|
||||
CheckLoadCacheFile,
|
||||
LoadWebFile,
|
||||
CheckLoadWebFile,
|
||||
CheckLoadWebFile,
|
||||
TryLoadWebFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private float _tryTimer = 0;
|
||||
private string _fileLoadPath;
|
||||
private bool _isShowWaitForAsyncError = false;
|
||||
private DownloaderBase _downloader;
|
||||
private UnityWebRequest _webRequest;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
|
||||
|
||||
|
||||
public AssetBundleWebLoader(AssetSystemImpl impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
@@ -48,17 +47,17 @@ namespace YooAsset
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.LoadWebFile;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadCacheFile;
|
||||
_fileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,31 +96,29 @@ namespace YooAsset
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||
if (System.IO.File.Exists(_fileLoadPath) == false)
|
||||
if (System.IO.File.Exists(FileLoadPath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Not found assetBundle file : {_fileLoadPath}";
|
||||
LastError = $"Not found assetBundle file : {FileLoadPath}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Load assetBundle file
|
||||
if (MainBundleInfo.Bundle.IsEncrypted)
|
||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.Normal)
|
||||
{
|
||||
if (Impl.DecryptionServices == null)
|
||||
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.Bundle.BundleName}");
|
||||
|
||||
DecryptionFileInfo fileInfo = new DecryptionFileInfo();
|
||||
fileInfo.BundleName = MainBundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileHash = MainBundleInfo.Bundle.FileHash;
|
||||
ulong offset = Impl.DecryptionServices.GetFileOffset(fileInfo);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath, 0, offset);
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(_fileLoadPath);
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"WebGL not support encrypted bundle file : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
_steps = ESteps.CheckLoadCacheFile;
|
||||
}
|
||||
@@ -165,7 +162,8 @@ namespace YooAsset
|
||||
// 5. 从WEB网站获取AssetBundle文件
|
||||
if (_steps == ESteps.LoadWebFile)
|
||||
{
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_fileLoadPath, Hash128.Parse(MainBundleInfo.Bundle.FileHash));
|
||||
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckLoadWebFile;
|
||||
}
|
||||
@@ -182,7 +180,7 @@ namespace YooAsset
|
||||
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||
#endif
|
||||
{
|
||||
YooLogger.Warning($"Failed to get asset bundle from web : {_fileLoadPath} Error : {_webRequest.error}");
|
||||
YooLogger.Warning($"Failed to get asset bundle from web : {FileLoadPath} Error : {_webRequest.error}");
|
||||
_steps = ESteps.TryLoadWebFile;
|
||||
_tryTimer = 0;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class AssetBundleLoaderBase
|
||||
internal abstract class BundleLoaderBase
|
||||
{
|
||||
public enum EStatus
|
||||
{
|
||||
@@ -46,9 +46,10 @@ namespace YooAsset
|
||||
|
||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
||||
internal AssetBundle CacheBundle { set; get; }
|
||||
internal string FileLoadPath { set; get; }
|
||||
|
||||
|
||||
|
||||
public AssetBundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
|
||||
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
|
||||
{
|
||||
Impl = impl;
|
||||
MainBundleInfo = bundleInfo;
|
||||
@@ -89,7 +90,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public void Destroy(bool forceDestroy)
|
||||
public virtual void Destroy(bool forceDestroy)
|
||||
{
|
||||
IsDestroyed = true;
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 依赖的资源包加载器列表
|
||||
/// </summary>
|
||||
private readonly List<AssetBundleLoaderBase> _dependBundles;
|
||||
private readonly List<BundleLoaderBase> _dependBundles;
|
||||
|
||||
|
||||
public DependAssetBundleGroup(List<AssetBundleLoaderBase> dpendBundles)
|
||||
public DependAssetBundleGroup(List<BundleLoaderBase> dpendBundles)
|
||||
{
|
||||
_dependBundles = dpendBundles;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace YooAsset
|
||||
{
|
||||
foreach (var loader in _dependBundles)
|
||||
{
|
||||
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
|
||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace YooAsset
|
||||
{
|
||||
foreach (var loader in _dependBundles)
|
||||
{
|
||||
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
|
||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
return loader.LastError;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace YooAsset
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;
|
||||
bundleInfo.RefCount = loader.RefCount;
|
||||
bundleInfo.Status = (int)loader.Status;
|
||||
bundleInfo.Status = loader.Status.ToString();
|
||||
output.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// Bundle文件的加载方法
|
||||
/// </summary>
|
||||
public enum EBundleLoadMethod
|
||||
{
|
||||
/// <summary>
|
||||
/// 正常加载(不需要解密)
|
||||
/// </summary>
|
||||
Normal = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 通过文件偏移来解密加载
|
||||
/// </summary>
|
||||
LoadFromFileOffset = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 通过文件内存来解密加载
|
||||
/// </summary>
|
||||
LoadFromMemory = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 通过文件流来解密加载
|
||||
/// </summary>
|
||||
LoadFromStream = 3,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e32c14ed62806b4189d20ad48ce7631
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,171 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleFileLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Download,
|
||||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
CheckFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private bool _isShowWaitForAsyncError = false;
|
||||
private DownloaderBase _unpacker;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
|
||||
public RawBundleFileLoader(AssetSystemImpl impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
#if UNITY_ANDROID || UNITY_WEBGL
|
||||
_steps = ESteps.Unpack;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
#else
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 下载远端文件
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 2. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 解压内置文件
|
||||
if (_steps == ESteps.Unpack)
|
||||
{
|
||||
int failedTryAgain = 1;
|
||||
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
|
||||
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckUnpack;
|
||||
}
|
||||
|
||||
// 4. 检测解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_unpacker.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _unpacker.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检测结果
|
||||
if (_steps == ESteps.CheckFile)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
if (File.Exists(FileLoadPath))
|
||||
{
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Raw file not found : {FileLoadPath}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
int frame = 1000;
|
||||
while (true)
|
||||
{
|
||||
// 文件解压
|
||||
if (_unpacker != null)
|
||||
{
|
||||
_unpacker.Update();
|
||||
if (_unpacker.IsDone() == false)
|
||||
continue;
|
||||
}
|
||||
|
||||
// 保险机制
|
||||
// 注意:如果需要从WEB端下载资源,可能会触发保险机制!
|
||||
frame--;
|
||||
if (frame == 0)
|
||||
{
|
||||
if (_isShowWaitForAsyncError == false)
|
||||
{
|
||||
_isShowWaitForAsyncError = true;
|
||||
YooLogger.Error($"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.Bundle.BundleName} from remote with sync load method !");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 驱动流程
|
||||
Update();
|
||||
|
||||
// 完成后退出
|
||||
if (IsDone())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa39f24727abe514093f18787c0c7e27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,7 +15,6 @@ namespace YooAsset
|
||||
private readonly Vector3 _position;
|
||||
private readonly Quaternion _rotation;
|
||||
private readonly Transform _parent;
|
||||
private readonly bool _setPositionRotation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
@@ -24,13 +23,12 @@ namespace YooAsset
|
||||
public GameObject Result = null;
|
||||
|
||||
|
||||
internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||
internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent)
|
||||
{
|
||||
_handle = handle;
|
||||
_position = position;
|
||||
_rotation = rotation;
|
||||
_parent = parent;
|
||||
_setPositionRotation = setPositionRotation;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
@@ -43,7 +41,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.Clone)
|
||||
{
|
||||
if (_handle.IsValid == false)
|
||||
if (_handle.IsValidWithWarning == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -62,24 +60,36 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if(_setPositionRotation)
|
||||
{
|
||||
if (_parent == null)
|
||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
|
||||
else
|
||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_parent == null)
|
||||
Result = Object.Instantiate(_handle.AssetObject as GameObject);
|
||||
else
|
||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _parent);
|
||||
}
|
||||
// 实例化游戏对象
|
||||
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消实例化对象操作
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"User cancelled !";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步实例化结束
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
_handle.WaitForAsyncComplete();
|
||||
Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,447 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 原生文件操作
|
||||
/// </summary>
|
||||
public abstract class RawFileOperation : AsyncOperationBase
|
||||
{
|
||||
internal readonly BundleInfo _bundleInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的拷贝路径
|
||||
/// </summary>
|
||||
public string CopyPath { private set; get; }
|
||||
|
||||
|
||||
internal RawFileOperation(BundleInfo bundleInfo, string copyPath)
|
||||
{
|
||||
_bundleInfo = bundleInfo;
|
||||
CopyPath = copyPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public abstract string GetCachePath();
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的二进制数据
|
||||
/// </summary>
|
||||
public byte[] LoadFileData()
|
||||
{
|
||||
string filePath = GetCachePath();
|
||||
if (File.Exists(filePath) == false)
|
||||
return null;
|
||||
return File.ReadAllBytes(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的文本数据
|
||||
/// </summary>
|
||||
public string LoadFileText()
|
||||
{
|
||||
string filePath = GetCachePath();
|
||||
if (File.Exists(filePath) == false)
|
||||
return string.Empty;
|
||||
return File.ReadAllText(filePath, System.Text.Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发生错误的原生文件操作
|
||||
/// </summary>
|
||||
internal sealed class CompletedRawFileOperation : RawFileOperation
|
||||
{
|
||||
private readonly string _error;
|
||||
internal CompletedRawFileOperation(string error, string copyPath) : base(null, copyPath)
|
||||
{
|
||||
_error = error;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _error;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public override string GetCachePath()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟运行的原生文件操作
|
||||
/// </summary>
|
||||
internal sealed class EditorPlayModeRawFileOperation : RawFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
CheckAndCopyFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal EditorPlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
|
||||
{
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 1. 准备工作
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromEditor)
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
return; // 模拟实现异步操作
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 检测并拷贝原生文件
|
||||
if (_steps == ESteps.CheckAndCopyFile)
|
||||
{
|
||||
// 如果不需要保存文件
|
||||
if (string.IsNullOrEmpty(CopyPath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果原生文件已经存在,则将其删除
|
||||
if (File.Exists(CopyPath))
|
||||
{
|
||||
File.Delete(CopyPath);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileUtility.CreateFileDirectory(CopyPath);
|
||||
File.Copy(GetCachePath(), CopyPath, true);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = e.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public override string GetCachePath()
|
||||
{
|
||||
if (_bundleInfo == null)
|
||||
return string.Empty;
|
||||
return _bundleInfo.EditorAssetPath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离线模式的原生文件操作
|
||||
/// </summary>
|
||||
internal sealed class OfflinePlayModeRawFileOperation : RawFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
DownloadBuildinFile,
|
||||
CheckDownload,
|
||||
CheckAndCopyFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
public OfflinePlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
|
||||
{
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 1. 准备工作
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Bundle info is invalid : {_bundleInfo.Bundle.BundleName}";
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.DownloadBuildinFile;
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 下载文件
|
||||
if (_steps == ESteps.DownloadBuildinFile)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
var bundleInfo = PatchHelper.ConvertToUnpackInfo(_bundleInfo.Bundle);
|
||||
_downloader = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 3. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
Progress = _downloader.DownloadProgress;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 检测并拷贝原生文件
|
||||
if (_steps == ESteps.CheckAndCopyFile)
|
||||
{
|
||||
// 如果不需要保存文件
|
||||
if (string.IsNullOrEmpty(CopyPath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果原生文件已经存在,则验证其完整性
|
||||
if (File.Exists(CopyPath))
|
||||
{
|
||||
var verifyResult = CacheSystem.VerifyContentInternal(CopyPath, _bundleInfo.Bundle.FileSize, _bundleInfo.Bundle.FileCRC, EVerifyLevel.High);
|
||||
if (verifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Delete(CopyPath);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileUtility.CreateFileDirectory(CopyPath);
|
||||
File.Copy(GetCachePath(), CopyPath, true);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = e.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public override string GetCachePath()
|
||||
{
|
||||
if (_bundleInfo == null)
|
||||
return string.Empty;
|
||||
return _bundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 联机模式的原生文件操作
|
||||
/// </summary>
|
||||
internal sealed class HostPlayModeRawFileOperation : RawFileOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
DownloadWebFile,
|
||||
DownloadBuildinFile,
|
||||
CheckDownload,
|
||||
CheckAndCopyFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
internal HostPlayModeRawFileOperation(BundleInfo bundleInfo, string copyPath) : base(bundleInfo, copyPath)
|
||||
{
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 1. 准备工作
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.None)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Bundle info is invalid : {_bundleInfo.Bundle.BundleName}";
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.DownloadWebFile;
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.DownloadBuildinFile;
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(_bundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 下载远端文件
|
||||
if (_steps == ESteps.DownloadWebFile)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
_downloader = DownloadSystem.BeginDownload(_bundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 3. 下载内置文件
|
||||
if (_steps == ESteps.DownloadBuildinFile)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
var bundleInfo = PatchHelper.ConvertToUnpackInfo(_bundleInfo.Bundle);
|
||||
_downloader = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 4. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
Progress = _downloader.DownloadProgress;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检测并拷贝原生文件
|
||||
if (_steps == ESteps.CheckAndCopyFile)
|
||||
{
|
||||
// 如果不需要保存文件
|
||||
if (string.IsNullOrEmpty(CopyPath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果原生文件已经存在,则验证其完整性
|
||||
if (File.Exists(CopyPath))
|
||||
{
|
||||
var verifyResult = CacheSystem.VerifyContentInternal(CopyPath, _bundleInfo.Bundle.FileSize, _bundleInfo.Bundle.FileCRC, EVerifyLevel.High);
|
||||
if (verifyResult == EVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Delete(CopyPath);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileUtility.CreateFileDirectory(CopyPath);
|
||||
File.Copy(GetCachePath(), CopyPath, true);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = e.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public override string GetCachePath()
|
||||
{
|
||||
if (_bundleInfo == null)
|
||||
return string.Empty;
|
||||
return _bundleInfo.Bundle.CachedFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -46,15 +48,15 @@ namespace YooAsset
|
||||
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = OwnerBundle.LastError;
|
||||
InvokeCompletion();
|
||||
return;
|
||||
@@ -64,8 +66,9 @@ namespace YooAsset
|
||||
{
|
||||
if (OwnerBundle.IsDestroyed)
|
||||
throw new System.Exception("Should never get here !");
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
@@ -112,8 +115,8 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
Status = AssetObject == null ? EStatus.Failed : EStatus.Succeed;
|
||||
if (Status == EStatus.Failed)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
|
||||
@@ -3,12 +3,12 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class BundledProvider : ProviderBase
|
||||
{
|
||||
protected AssetBundleLoaderBase OwnerBundle { private set; get; }
|
||||
internal abstract class BundledProvider : ProviderBase
|
||||
{
|
||||
protected BundleLoaderBase OwnerBundle { private set; get; }
|
||||
protected DependAssetBundleGroup DependBundleGroup { private set; get; }
|
||||
|
||||
public BundledProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||
public BundledProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||
{
|
||||
OwnerBundle = impl.CreateOwnerAssetBundleLoader(assetInfo);
|
||||
OwnerBundle.Reference();
|
||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.Bundle.BundleName;
|
||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||
bundleInfo.Status = (int)OwnerBundle.Status;
|
||||
bundleInfo.Status = OwnerBundle.Status.ToString();
|
||||
output.Add(bundleInfo);
|
||||
|
||||
DependBundleGroup.GetBundleDebugInfos(output);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class BundledRawFileProvider : BundledProvider
|
||||
{
|
||||
public override float Progress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDone)
|
||||
return 1f;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public BundledRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
Status = EStatus.CheckBundle;
|
||||
}
|
||||
|
||||
if (Status == EStatus.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = OwnerBundle.LastError;
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
RawFilePath = OwnerBundle.FileLoadPath;
|
||||
Status = EStatus.Succeed;
|
||||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a00889582fd95446b103af1074fa6ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -32,6 +32,8 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -50,15 +52,15 @@ namespace YooAsset
|
||||
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = OwnerBundle.LastError;
|
||||
InvokeCompletion();
|
||||
return;
|
||||
@@ -81,7 +83,7 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load scene : {_sceneName}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
@@ -96,8 +98,8 @@ namespace YooAsset
|
||||
if (SceneObject.IsValid() && _activateOnLoad)
|
||||
SceneManager.SetActiveScene(SceneObject);
|
||||
|
||||
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
|
||||
if(Status == EStatus.Fail)
|
||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||
if (Status == EStatus.Failed)
|
||||
{
|
||||
LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace YooAsset
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
DebugRecording();
|
||||
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
@@ -46,15 +48,15 @@ namespace YooAsset
|
||||
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = OwnerBundle.LastError;
|
||||
InvokeCompletion();
|
||||
return;
|
||||
@@ -102,8 +104,8 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
Status = AllAssetObjects == null ? EStatus.Failed : EStatus.Succeed;
|
||||
if (Status == EStatus.Failed)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace YooAsset
|
||||
{
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = error;
|
||||
InvokeCompletion();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
@@ -59,8 +59,8 @@ namespace YooAsset
|
||||
// 2. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
Status = AssetObject == null ? EStatus.Failed : EStatus.Succeed;
|
||||
if (Status == EStatus.Failed)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DatabaseRawFileProvider : ProviderBase
|
||||
{
|
||||
public override float Progress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDone)
|
||||
return 1f;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseRawFileProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
Status = EStatus.Checking;
|
||||
|
||||
// 注意:模拟异步加载效果提前返回
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
return;
|
||||
}
|
||||
|
||||
if(Status == EStatus.Checking)
|
||||
{
|
||||
RawFilePath = MainAssetInfo.AssetPath;
|
||||
Status = EStatus.Succeed;
|
||||
InvokeCompletion();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user