mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 18:50:10 +00:00
Compare commits
71 Commits
2.0.3-prev
...
2.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc5f0b151b | ||
|
|
dd5bcc3d9d | ||
|
|
80188ae6e6 | ||
|
|
05e77dc166 | ||
|
|
b9b8f8e170 | ||
|
|
c9cc09cbed | ||
|
|
bef90bf3b8 | ||
|
|
a369efa429 | ||
|
|
370329b07d | ||
|
|
e743a15fbc | ||
|
|
10c8b52092 | ||
|
|
1461b91a94 | ||
|
|
b5ffd5005a | ||
|
|
f06bd83dc3 | ||
|
|
a1450ee78a | ||
|
|
4c619778c3 | ||
|
|
4e8840cd93 | ||
|
|
0a709f741a | ||
|
|
ef8229981e | ||
|
|
2a5a2626a4 | ||
|
|
f4ddaedbf4 | ||
|
|
42104eb944 | ||
|
|
fadc8e6fd6 | ||
|
|
81747462b1 | ||
|
|
c01adad2a0 | ||
|
|
e598d60439 | ||
|
|
929cd23f35 | ||
|
|
d1aca5b675 | ||
|
|
b67868868d | ||
|
|
af3bf8448c | ||
|
|
4170c60f0c | ||
|
|
0a7a883aae | ||
|
|
88a1184877 | ||
|
|
c7329fcab5 | ||
|
|
6eb9a90a03 | ||
|
|
7586882a97 | ||
|
|
6f13c021b9 | ||
|
|
5f30c92d44 | ||
|
|
3e6c55d981 | ||
|
|
de36f984d7 | ||
|
|
95328fe1a6 | ||
|
|
1fb78185ff | ||
|
|
58f9aea979 | ||
|
|
4d4bb1e34f | ||
|
|
6e1978ec10 | ||
|
|
d8a8afba5e | ||
|
|
6e6f425bdd | ||
|
|
9ebe92f832 | ||
|
|
cbdb84a69f | ||
|
|
67b2b886a8 | ||
|
|
2838289650 | ||
|
|
4b68362fb8 | ||
|
|
e8e7696a4d | ||
|
|
82b2a5cc20 | ||
|
|
2332765932 | ||
|
|
552d689317 | ||
|
|
5e2d82d071 | ||
|
|
727f356eea | ||
|
|
544832c46a | ||
|
|
5c1d316d67 | ||
|
|
267ec77c37 | ||
|
|
c2a7106221 | ||
|
|
0e29e9823d | ||
|
|
47962424eb | ||
|
|
505d23ca07 | ||
|
|
d4fcb868d8 | ||
|
|
6dd1f43445 | ||
|
|
2626cb6750 | ||
|
|
81a98ded8a | ||
|
|
930f02765d | ||
|
|
a4ffa580b7 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -20,7 +20,6 @@
|
||||
/Assets/StreamingAssets.meta
|
||||
/Assets/Samples
|
||||
/Assets/Samples.meta
|
||||
/Packages
|
||||
/UserSettings
|
||||
|
||||
|
||||
|
||||
@@ -2,75 +2,118 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.0.3-preview] - 2023-10-27
|
||||
## [2.1.2] - 2024-05-16
|
||||
|
||||
SBP库依赖版本升级至2.1.3
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#180) Fixed an issue with invalid encryption task in the build pipeline.
|
||||
- (#185) Fixed subscene unload error when the scene is not loaded.
|
||||
- (#190) Fixed webgl platform compile error.
|
||||
|
||||
### Improvements
|
||||
|
||||
- The asset load method add the priority parameter.
|
||||
- The async operation class add the priority field.
|
||||
- (#236) 修复了资源配置界面AutoCollectShader复选框没有刷新的问题。
|
||||
- (#244) 修复了导入器在安卓平台导入本地下载的资源失败的问题。
|
||||
- (#268) 修复了挂起场景未解除状态前无法卸载的问题。
|
||||
- (#269) 优化场景挂起流程,支持中途取消挂起操作。
|
||||
- (#276) 修复了HostPlayMode模式下,如果内置清单是最新版本,每次运行都会触发拷贝行为。
|
||||
- (#289) 修复了Unity2019版本脚本IWebRequester编译报错。
|
||||
- (#295) 解决了在安卓移动平台,华为和三星真机上有极小概率加载资源包失败 : Unable to open archive file
|
||||
|
||||
### Added
|
||||
|
||||
- The InitializeParameters calss add new parameter : AutoDestroyAssetProvider
|
||||
- 新增GetAllCacheFileInfosOperation()获取缓存文件信息的方法。
|
||||
|
||||
- 新增LoadSceneSync()同步加载场景的方法。
|
||||
|
||||
- 新增IIgnoreRule接口,资源收集流程可以自定义。
|
||||
|
||||
- 新增IWechatQueryServices接口,用于微信平台本地文件查询。
|
||||
|
||||
后续将会通过虚拟文件系统来支持!
|
||||
|
||||
### Changed
|
||||
|
||||
- 调整了UnloadSceneOperation代码里场景的卸载顺序。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 优化了资源清单的解析过程。
|
||||
- 移除资源包名里的空格字符。
|
||||
- 支持华为鸿蒙系统。
|
||||
|
||||
## [2.1.1] - 2024-01-17
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#224) 修复了编辑器模式打包时 SimulateBuild 报错的问题。
|
||||
- (#223) 修复了资源构建界面读取配置导致的报错问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 支持共享资源打包规则,可以定制化独立的构建规则。
|
||||
|
||||
```c#
|
||||
public class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 自动销毁不再使用的资源提供者
|
||||
/// 是否启用共享资源打包
|
||||
/// </summary>
|
||||
public bool AutoDestroyAssetProvider = false;
|
||||
public bool EnableSharePackRule = false;
|
||||
}
|
||||
```
|
||||
|
||||
- Resource package add TryUnloadUnusedAsset function.
|
||||
- 微信小游戏平台,资源下载器支持底层缓存查询。
|
||||
|
||||
## [2.1.0] - 2023-12-27
|
||||
|
||||
升级了 Scriptable build pipeline (SBP) 的版本,来解决图集引用的精灵图片冗余问题。
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#195) 修复了在EditorPlayMode模式下,AssetHandle.GetDownloadStatus()发生异常的问题。
|
||||
- (#201) 修复了断点续传失效的问题。
|
||||
- (#202) 修复了打包参数FileNameStyle设置为BundleName后,IQueryServices会一直返回true的问题。
|
||||
- (#205) 修复了HybridCLR插件里创建资源下载器触发的异常。
|
||||
- (#210) 修复了DownloaderOperation在未开始下载前,内部的PackageName为空的问题。
|
||||
- (#220) 修复了资源收集界面关闭后,撤回操作还会生效的问题。
|
||||
- 修复了下载器合并后重新计算下载字节数不正确的问题。
|
||||
|
||||
### Improvements
|
||||
|
||||
- (#198) 资源收集界面禁用的分组不再检测合法性。
|
||||
- (#203) 资源构建类容许自定义打包的输出目录。
|
||||
- 资源构建报告增加未依赖的资源信息列表。
|
||||
|
||||
### Changed
|
||||
|
||||
- IBuildinQueryServices和IDeliveryQueryServices查询方法变更。
|
||||
|
||||
```c#
|
||||
public interface IBuildinQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
||||
/// 查询是否为应用程序内置的资源文件
|
||||
/// </summary>
|
||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
}
|
||||
|
||||
public interface IDeliveryQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为开发者分发的资源文件
|
||||
/// </summary>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Removed
|
||||
|
||||
- The InitializeParameters calss remove the parameter : LoadingMaxTimeSlice
|
||||
- (#212) 移除了构建报告里的资源冗余信息列表。
|
||||
|
||||
## [2.0.2-preview] - 2023-10-17
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed the mistaken code in the build window.
|
||||
- Fixed an issue where auto collect shaders was not effective for dependent resources.
|
||||
|
||||
### Improvements
|
||||
|
||||
- Add error code for exception output during package building.
|
||||
|
||||
## [2.0.1-preview] - 2023-10-11
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#175) Fixed a bug where the url path of mac platform contains spaces, which would cause the request error.
|
||||
- (#177) Fixed the inability to load main asset object after loading the sub asset.
|
||||
- (#178) Fixed the error when initializing resource package that prompted not initialized.
|
||||
- (#179) Fixed issue with SBP build pipeline packaging reporting errors.
|
||||
|
||||
### Added
|
||||
|
||||
- Resource downloader add combine function.
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 合并其它下载器
|
||||
/// </summary>
|
||||
/// <param name="downloader">合并的下载器</param>
|
||||
public void Combine(DownloaderOperation downloader);
|
||||
```
|
||||
|
||||
## [2.0.0-preview] - 2023-10-07
|
||||
|
||||
This is the preview version.
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace YooAsset.Editor
|
||||
public static class AssetBundleBuilderHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取默认的输出根路录
|
||||
/// 获取默认的输出根目录
|
||||
/// </summary>
|
||||
public static string GetDefaultBuildOutputRoot()
|
||||
{
|
||||
|
||||
@@ -26,19 +26,9 @@ namespace YooAsset.Editor
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// </summary>
|
||||
public string AssetGUID { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType { private set; get; }
|
||||
public AssetInfo AssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源的分类标签
|
||||
@@ -52,25 +42,19 @@ namespace YooAsset.Editor
|
||||
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
||||
|
||||
|
||||
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath)
|
||||
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
AssetInfo = assetInfo;
|
||||
}
|
||||
public BuildAssetInfo(string assetPath)
|
||||
public BuildAssetInfo(AssetInfo assetInfo)
|
||||
{
|
||||
CollectorType = ECollectorType.None;
|
||||
BundleName = string.Empty;
|
||||
Address = string.Empty;
|
||||
AssetPath = assetPath;
|
||||
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
AssetInfo = assetInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,13 +70,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置为统一的着色器包名
|
||||
/// 设置资源包名称
|
||||
/// </summary>
|
||||
public void SetShaderBundleName(string packageName, bool uniqueBundleName)
|
||||
public void SetBundleName(string bundleName)
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
BundleName = shaderPackRuleResult.GetBundleName(packageName, uniqueBundleName);
|
||||
if (HasBundleName())
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
BundleName = bundleName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -137,17 +122,6 @@ namespace YooAsset.Editor
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否为冗余资源
|
||||
/// </summary>
|
||||
public bool IsRedundancyAsset()
|
||||
{
|
||||
if (HasBundleName())
|
||||
return false;
|
||||
|
||||
return _referenceBundleNames.Count > 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取关联资源包的数量
|
||||
/// </summary>
|
||||
|
||||
@@ -82,12 +82,12 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 添加一个打包资源
|
||||
/// </summary>
|
||||
public void PackAsset(BuildAssetInfo assetInfo)
|
||||
public void PackAsset(BuildAssetInfo buildAsset)
|
||||
{
|
||||
if (IsContainsAsset(assetInfo.AssetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {assetInfo.AssetPath}");
|
||||
if (IsContainsAsset(buildAsset.AssetInfo.AssetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {buildAsset.AssetInfo.AssetPath}");
|
||||
|
||||
MainAssets.Add(assetInfo);
|
||||
MainAssets.Add(buildAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,9 +95,9 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IsContainsAsset(string assetPath)
|
||||
{
|
||||
foreach (var assetInfo in MainAssets)
|
||||
foreach (var buildAsset in MainAssets)
|
||||
{
|
||||
if (assetInfo.AssetPath == assetPath)
|
||||
if (buildAsset.AssetInfo.AssetPath == assetPath)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string[] GetAllMainAssetPaths()
|
||||
{
|
||||
return MainAssets.Select(t => t.AssetPath).ToArray();
|
||||
return MainAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,17 +120,17 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var packAssets = GetAllMainAssetPaths();
|
||||
List<string> result = new List<string>(packAssets);
|
||||
foreach (var assetInfo in MainAssets)
|
||||
foreach (var buildAsset in MainAssets)
|
||||
{
|
||||
if (assetInfo.AllDependAssetInfos == null)
|
||||
if (buildAsset.AllDependAssetInfos == null)
|
||||
continue;
|
||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||
foreach (var dependAssetInfo in buildAsset.AllDependAssetInfos)
|
||||
{
|
||||
// 注意:依赖资源里只添加零依赖资源和冗余资源
|
||||
if (dependAssetInfo.HasBundleName() == false)
|
||||
{
|
||||
if (result.Contains(dependAssetInfo.AssetPath) == false)
|
||||
result.Add(dependAssetInfo.AssetPath);
|
||||
if (result.Contains(dependAssetInfo.AssetInfo.AssetPath) == false)
|
||||
result.Add(dependAssetInfo.AssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
|
||||
{
|
||||
// 注意:我们不在支持AssetBundle的变种机制
|
||||
// 注意:我们不再支持AssetBundle的变种机制
|
||||
AssetBundleBuild build = new AssetBundleBuild();
|
||||
build.assetBundleName = BundleName;
|
||||
build.assetBundleVariant = string.Empty;
|
||||
|
||||
@@ -14,10 +14,9 @@ namespace YooAsset.Editor
|
||||
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
/// 未被依赖的资源列表
|
||||
/// </summary>
|
||||
public readonly List<ReportRedundancyInfo> RedundancyInfos = new List<ReportRedundancyInfo>(1000);
|
||||
|
||||
public readonly List<ReportIndependAsset> IndependAssets = new List<ReportIndependAsset>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 参与构建的资源总数
|
||||
|
||||
@@ -47,6 +47,11 @@ namespace YooAsset.Editor
|
||||
public string PackageVersion;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用共享资源打包
|
||||
/// </summary>
|
||||
public bool EnableSharePackRule = false;
|
||||
|
||||
/// <summary>
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
@@ -161,7 +166,7 @@ namespace YooAsset.Editor
|
||||
/// 获取构建管线的输出目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetPipelineOutputDirectory()
|
||||
public virtual string GetPipelineOutputDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
|
||||
{
|
||||
@@ -173,7 +178,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取本次构建的补丁输出目录
|
||||
/// </summary>
|
||||
public string GetPackageOutputDirectory()
|
||||
public virtual string GetPackageOutputDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageOutputDirectory))
|
||||
{
|
||||
@@ -185,7 +190,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取本次构建的补丁根目录
|
||||
/// </summary>
|
||||
public string GetPackageRootDirectory()
|
||||
public virtual string GetPackageRootDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageRootDirectory))
|
||||
{
|
||||
@@ -197,7 +202,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取内置资源的根目录
|
||||
/// </summary>
|
||||
public string GetBuildinRootDirectory()
|
||||
public virtual string GetBuildinRootDirectory()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_buildinRootDirectory))
|
||||
{
|
||||
|
||||
@@ -105,8 +105,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
PackageAsset packageAsset = new PackageAsset();
|
||||
packageAsset.Address = buildMapContext.Command.EnableAddressable ? assetInfo.Address : string.Empty;
|
||||
packageAsset.AssetPath = assetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetPath = assetInfo.AssetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
|
||||
result.Add(packageAsset);
|
||||
|
||||
@@ -31,16 +31,18 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildMode = buildParameters.BuildMode;
|
||||
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
|
||||
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
|
||||
|
||||
// 收集器配置
|
||||
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
|
||||
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
|
||||
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
|
||||
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
|
||||
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
|
||||
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ?
|
||||
"null" : buildParameters.EncryptionServices.GetType().FullName;
|
||||
|
||||
// 构建参数
|
||||
buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
|
||||
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
|
||||
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline))
|
||||
{
|
||||
var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
|
||||
@@ -107,8 +109,8 @@ namespace YooAsset.Editor
|
||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||
}
|
||||
|
||||
// 冗余资源列表
|
||||
buildReport.RedundancyInfos = new List<ReportRedundancyInfo>(buildMapContext.RedundancyInfos);
|
||||
// 其它资源列表
|
||||
buildReport.IndependAssets = new List<ReportIndependAsset>(buildMapContext.IndependAssets);
|
||||
|
||||
// 序列化文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
@@ -140,11 +142,11 @@ namespace YooAsset.Editor
|
||||
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
|
||||
{
|
||||
BuildAssetInfo findAssetInfo = null;
|
||||
foreach (var assetInfo in bundleInfo.MainAssets)
|
||||
foreach (var buildAsset in bundleInfo.MainAssets)
|
||||
{
|
||||
if (assetInfo.AssetPath == assetPath)
|
||||
if (buildAsset.AssetInfo.AssetPath == assetPath)
|
||||
{
|
||||
findAssetInfo = assetInfo;
|
||||
findAssetInfo = buildAsset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -154,7 +156,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
|
||||
{
|
||||
result.Add(dependAssetInfo.AssetPath);
|
||||
result.Add(dependAssetInfo.AssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
|
||||
{
|
||||
BuildMapContext context = new BuildMapContext();
|
||||
var buildMode = buildParameters.BuildMode;
|
||||
var packageName = buildParameters.PackageName;
|
||||
|
||||
@@ -21,103 +22,107 @@ namespace YooAsset.Editor
|
||||
|
||||
// 1. 获取所有收集器收集的资源
|
||||
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
List<CollectAssetInfo> allCollectAssetInfos = collectResult.CollectAssets;
|
||||
List<CollectAssetInfo> allCollectAssets = collectResult.CollectAssets;
|
||||
|
||||
// 2. 剔除未被引用的依赖项资源
|
||||
RemoveZeroReferenceAssets(allCollectAssetInfos);
|
||||
RemoveZeroReferenceAssets(context, allCollectAssets);
|
||||
|
||||
// 3. 录入所有收集器主动收集的资源
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetPath) == false)
|
||||
if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetInfo.AssetPath))
|
||||
{
|
||||
throw new Exception($"Should never get here !");
|
||||
}
|
||||
|
||||
if (collectAssetInfo.CollectorType != ECollectorType.MainAssetCollector)
|
||||
{
|
||||
if (collectAssetInfo.AssetTags.Count > 0)
|
||||
{
|
||||
collectAssetInfo.AssetTags.Clear();
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetPath}");
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetInfo.AssetPath}");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
}
|
||||
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath);
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetInfo);
|
||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||
allBuildAssetInfos.Add(collectAssetInfo.AssetPath, buildAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Should never get here !");
|
||||
}
|
||||
allBuildAssetInfos.Add(collectAssetInfo.AssetInfo.AssetPath, buildAssetInfo);
|
||||
}
|
||||
|
||||
// 4. 录入所有收集资源依赖的其它资源
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
string bundleName = collectAssetInfo.BundleName;
|
||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(dependAssetPath))
|
||||
if (allBuildAssetInfos.ContainsKey(dependAsset.AssetPath))
|
||||
{
|
||||
allBuildAssetInfos[dependAssetPath].AddReferenceBundleName(bundleName);
|
||||
allBuildAssetInfos[dependAsset.AssetPath].AddReferenceBundleName(bundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAsset);
|
||||
buildAssetInfo.AddReferenceBundleName(bundleName);
|
||||
allBuildAssetInfos.Add(dependAssetPath, buildAssetInfo);
|
||||
allBuildAssetInfos.Add(dependAsset.AssetPath, buildAssetInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 填充所有收集资源的依赖列表
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.TryGetValue(dependAssetPath, out BuildAssetInfo value))
|
||||
if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out BuildAssetInfo value))
|
||||
dependAssetInfos.Add(value);
|
||||
else
|
||||
throw new Exception("Should never get here !");
|
||||
}
|
||||
allBuildAssetInfos[collectAssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos);
|
||||
allBuildAssetInfos[collectAssetInfo.AssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos);
|
||||
}
|
||||
|
||||
// 6. 自动收集所有依赖的着色器
|
||||
if (collectResult.Command.AutoCollectShaders)
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
string shaderBundleName = shaderPackRuleResult.GetBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
|
||||
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
|
||||
{
|
||||
if (buildAssetInfo.CollectorType == ECollectorType.None)
|
||||
{
|
||||
if (buildAssetInfo.AssetType == typeof(UnityEngine.Shader) || buildAssetInfo.AssetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
if (buildAssetInfo.AssetInfo.IsShaderAsset())
|
||||
{
|
||||
buildAssetInfo.SetShaderBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
|
||||
buildAssetInfo.SetBundleName(shaderBundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 记录关键信息
|
||||
BuildMapContext context = new BuildMapContext();
|
||||
context.AssetFileCount = allBuildAssetInfos.Count;
|
||||
context.Command = collectResult.Command;
|
||||
|
||||
// 8. 记录冗余资源
|
||||
// 7. 计算共享资源的包名
|
||||
if (buildParameters.EnableSharePackRule)
|
||||
{
|
||||
PreProcessPackShareBundle(buildParameters, collectResult.Command, allBuildAssetInfos);
|
||||
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
|
||||
{
|
||||
if (buildAssetInfo.IsRedundancyAsset())
|
||||
if (buildAssetInfo.HasBundleName() == false)
|
||||
{
|
||||
var redundancyInfo = new ReportRedundancyInfo();
|
||||
redundancyInfo.AssetPath = buildAssetInfo.AssetPath;
|
||||
redundancyInfo.AssetType = buildAssetInfo.AssetType.Name;
|
||||
redundancyInfo.AssetGUID = buildAssetInfo.AssetGUID;
|
||||
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetPath);
|
||||
redundancyInfo.Number = buildAssetInfo.GetReferenceBundleCount();
|
||||
context.RedundancyInfos.Add(redundancyInfo);
|
||||
PackRuleResult packRuleResult = GetShareBundleName(buildAssetInfo);
|
||||
if (packRuleResult.IsValid())
|
||||
{
|
||||
string shareBundleName = packRuleResult.GetShareBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
|
||||
buildAssetInfo.SetBundleName(shareBundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
PostProcessPackShareBundle();
|
||||
}
|
||||
|
||||
// 8. 记录关键信息
|
||||
context.AssetFileCount = allBuildAssetInfos.Count;
|
||||
context.Command = collectResult.Command;
|
||||
|
||||
// 9. 移除不参与构建的资源
|
||||
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
|
||||
@@ -128,7 +133,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
foreach (var removeValue in removeBuildList)
|
||||
{
|
||||
allBuildAssetInfos.Remove(removeValue.AssetPath);
|
||||
allBuildAssetInfos.Remove(removeValue.AssetInfo.AssetPath);
|
||||
}
|
||||
|
||||
// 10. 构建资源列表
|
||||
@@ -145,35 +150,35 @@ namespace YooAsset.Editor
|
||||
|
||||
return context;
|
||||
}
|
||||
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
|
||||
private void RemoveZeroReferenceAssets(BuildMapContext context, List<CollectAssetInfo> allCollectAssets)
|
||||
{
|
||||
// 1. 检测是否任何存在依赖资源
|
||||
if (allCollectAssetInfos.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false)
|
||||
// 1. 检测依赖资源收集器是否存在
|
||||
if (allCollectAssets.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false)
|
||||
return;
|
||||
|
||||
// 2. 获取所有主资源的依赖资源集合
|
||||
HashSet<string> allDependAsset = new HashSet<string>();
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAsset in allCollectAssets)
|
||||
{
|
||||
var collectorType = collectAssetInfo.CollectorType;
|
||||
var collectorType = collectAsset.CollectorType;
|
||||
if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector)
|
||||
{
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAsset.DependAssets)
|
||||
{
|
||||
if (allDependAsset.Contains(dependAsset) == false)
|
||||
allDependAsset.Add(dependAsset);
|
||||
if (allDependAsset.Contains(dependAsset.AssetPath) == false)
|
||||
allDependAsset.Add(dependAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 找出所有零引用的依赖资源集合
|
||||
List<CollectAssetInfo> removeList = new List<CollectAssetInfo>();
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
var collectorType = collectAssetInfo.CollectorType;
|
||||
if (collectorType == ECollectorType.DependAssetCollector)
|
||||
{
|
||||
if (allDependAsset.Contains(collectAssetInfo.AssetPath) == false)
|
||||
if (allDependAsset.Contains(collectAssetInfo.AssetInfo.AssetPath) == false)
|
||||
removeList.Add(collectAssetInfo);
|
||||
}
|
||||
}
|
||||
@@ -181,10 +186,44 @@ namespace YooAsset.Editor
|
||||
// 4. 移除所有零引用的依赖资源
|
||||
foreach (var removeValue in removeList)
|
||||
{
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetPath}");
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetInfo.AssetPath}");
|
||||
BuildLogger.Warning(warning);
|
||||
allCollectAssetInfos.Remove(removeValue);
|
||||
|
||||
var independAsset = new ReportIndependAsset();
|
||||
independAsset.AssetPath = removeValue.AssetInfo.AssetPath;
|
||||
independAsset.AssetGUID = removeValue.AssetInfo.AssetGUID;
|
||||
independAsset.AssetType = removeValue.AssetInfo.AssetType.ToString();
|
||||
independAsset.FileSize = FileUtility.GetFileSize(removeValue.AssetInfo.AssetPath);
|
||||
context.IndependAssets.Add(independAsset);
|
||||
|
||||
allCollectAssets.Remove(removeValue);
|
||||
}
|
||||
}
|
||||
|
||||
#region 共享资源打包规则
|
||||
/// <summary>
|
||||
/// 共享资源打包前置处理
|
||||
/// </summary>
|
||||
protected virtual void PreProcessPackShareBundle(BuildParameters buildParameters, CollectCommand command, Dictionary<string, BuildAssetInfo> allBuildAssetInfos)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 共享资源打包后置处理
|
||||
/// </summary>
|
||||
protected virtual void PostProcessPackShareBundle()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取共享资源包名称
|
||||
/// </summary>
|
||||
protected virtual PackRuleResult GetShareBundleName(BuildAssetInfo buildAssetInfo)
|
||||
{
|
||||
string bundleName = Path.GetDirectoryName(buildAssetInfo.AssetInfo.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
|
||||
bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
|
||||
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo.PackageSourceFilePath, buildParametersContext);
|
||||
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo.PackageSourceFilePath, buildParametersContext);
|
||||
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo.PackageSourceFilePath, buildParametersContext);
|
||||
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext);
|
||||
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext);
|
||||
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext);
|
||||
}
|
||||
|
||||
// 4.更新补丁包输出的文件路径
|
||||
@@ -62,9 +62,9 @@ namespace YooAsset.Editor
|
||||
|
||||
protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext);
|
||||
protected abstract long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
|
||||
protected string GetFilePathTempHash(string filePath)
|
||||
{
|
||||
@@ -74,5 +74,23 @@ namespace YooAsset.Editor
|
||||
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
|
||||
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
|
||||
}
|
||||
protected long GetBundleTempSize(BuildBundleInfo bundleInfo)
|
||||
{
|
||||
long tempSize = 0;
|
||||
|
||||
var assetPaths = bundleInfo.GetAllMainAssetPaths();
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
long size = FileUtility.GetFileSize(assetPath);
|
||||
tempSize += size;
|
||||
}
|
||||
|
||||
if (tempSize == 0)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
return tempSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,27 +60,30 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return 0;
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,17 @@ namespace YooAsset.Editor
|
||||
public class BuiltinBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is BuiltinBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace YooAsset.Editor
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
foreach (var assetInfo in bundleInfo.MainAssets)
|
||||
foreach (var buildAsset in bundleInfo.MainAssets)
|
||||
{
|
||||
EditorTools.CopyFile(assetInfo.AssetPath, dest, true);
|
||||
EditorTools.CopyFile(buildAsset.AssetInfo.AssetPath, dest, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace YooAsset.Editor
|
||||
// 检测基础构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测不被支持的参数
|
||||
if (buildParameters.EnableSharePackRule)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportSharePackRule, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support share pack rule !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 检测不被支持的构建模式
|
||||
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
{
|
||||
|
||||
@@ -32,27 +32,30 @@ namespace YooAsset.Editor
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return 0;
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
@@ -10,10 +10,17 @@ namespace YooAsset.Editor
|
||||
public class RawFileBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is RawFileBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
|
||||
@@ -60,27 +60,30 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return 0;
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Build.Content;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEditor.Build.Pipeline.Injector;
|
||||
using UnityEditor.Build.Pipeline.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.Build.Pipeline.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Ref https://zhuanlan.zhihu.com/p/586918159
|
||||
/// </summary>
|
||||
public class RemoveSpriteAtlasRedundancy : IBuildTask
|
||||
{
|
||||
public int Version => 1;
|
||||
|
||||
[InjectContext]
|
||||
IBundleWriteData writeDataParam;
|
||||
|
||||
public ReturnCode Run()
|
||||
{
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
BundleWriteData writeData = (BundleWriteData)writeDataParam;
|
||||
|
||||
// 图集引用的精灵图片集合
|
||||
HashSet<GUID> spriteGuids = new HashSet<GUID>();
|
||||
foreach (var pair in writeData.FileToObjects)
|
||||
{
|
||||
foreach (ObjectIdentifier objectIdentifier in pair.Value)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
|
||||
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(SpriteAtlas))
|
||||
{
|
||||
var spritePaths = AssetDatabase.GetDependencies(assetPath, false);
|
||||
foreach (string spritePath in spritePaths)
|
||||
{
|
||||
GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
|
||||
spriteGuids.Add(spriteGuild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除图集引用的精力图片对象
|
||||
foreach (var pair in writeData.FileToObjects)
|
||||
{
|
||||
List<ObjectIdentifier> objectIdentifiers = pair.Value;
|
||||
for (int i = objectIdentifiers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
ObjectIdentifier objectIdentifier = objectIdentifiers[i];
|
||||
if (spriteGuids.Contains(objectIdentifier.guid))
|
||||
{
|
||||
if (objectIdentifier.localIdentifierInFile == 2800000)
|
||||
{
|
||||
// 删除图集散图的冗余纹理
|
||||
objectIdentifiers.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,11 @@ namespace UnityEditor.Build.Pipeline.Tasks
|
||||
#endif
|
||||
buildTasks.Add(new CalculateAssetDependencyData());
|
||||
buildTasks.Add(new StripUnusedSpriteSources());
|
||||
buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName));
|
||||
buildTasks.Add(new CreateBuiltInBundle(builtInShaderBundleName));
|
||||
buildTasks.Add(new PostDependencyCallback());
|
||||
|
||||
// Packing
|
||||
buildTasks.Add(new GenerateBundlePacking());
|
||||
buildTasks.Add(new RemoveSpriteAtlasRedundancy()); // Fix for SpriteAtlas Redundancy
|
||||
buildTasks.Add(new UpdateBundleObjectLayout());
|
||||
buildTasks.Add(new GenerateBundleCommands());
|
||||
buildTasks.Add(new GenerateSubAssetPathMaps());
|
||||
|
||||
@@ -7,10 +7,17 @@ namespace YooAsset.Editor
|
||||
public class ScriptableBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is ScriptableBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace YooAsset.Editor
|
||||
PackageOutputDirectoryExists = 115,
|
||||
RecommendScriptBuildPipeline = 130,
|
||||
BuildPipelineNotSupportBuildMode = 140,
|
||||
BuildPipelineNotSupportSharePackRule = 141,
|
||||
|
||||
// TaskGetBuildMap
|
||||
RemoveInvalidTags = 200,
|
||||
@@ -29,6 +30,7 @@ namespace YooAsset.Editor
|
||||
CharactersOverTheLimit = 400,
|
||||
NotFoundUnityBundleHash = 401,
|
||||
NotFoundUnityBundleCRC = 402,
|
||||
BundleTempSizeIsZero = 403,
|
||||
|
||||
// TaskVerifyBuildResult
|
||||
UnintendedBuildBundle = 500,
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace YooAsset.Editor
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
var buildModeList = GetSupportBuildModes();
|
||||
int defaultIndex = buildModeList.FindIndex(x => x.Equals(buildMode));
|
||||
if (defaultIndex < 0)
|
||||
defaultIndex = (int)(EBuildMode)buildModeList[0];
|
||||
_buildModeField = new PopupField<Enum>(buildModeList, defaultIndex);
|
||||
_buildModeField.label = "Build Mode";
|
||||
_buildModeField.style.width = StyleWidth;
|
||||
@@ -83,6 +85,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline);
|
||||
int defaultIndex = encryptionClassTypes.FindIndex(x => x.FullName.Equals(encyptionClassName));
|
||||
if (defaultIndex < 0)
|
||||
defaultIndex = 0;
|
||||
_encryptionField = new PopupField<Type>(encryptionClassTypes, defaultIndex);
|
||||
_encryptionField.label = "Encryption";
|
||||
_encryptionField.style.width = StyleWidth;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ִ<>й<EFBFBD><D0B9><EFBFBD>
|
||||
/// 执行构建
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
@@ -36,6 +36,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -20,7 +20,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ִ<>й<EFBFBD><D0B9><EFBFBD>
|
||||
/// 执行构建
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
|
||||
@@ -148,18 +148,29 @@ namespace YooAsset.Editor
|
||||
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||
|
||||
// 收集打包资源
|
||||
// 收集打包资源路径
|
||||
List<string> findAssets =new List<string>();
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
string[] findResult = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
findAssets.AddRange(findResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
findAssets.Add(assetPath);
|
||||
}
|
||||
|
||||
// 收集打包资源信息
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath))
|
||||
var assetInfo = new AssetInfo(assetPath);
|
||||
if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo))
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath);
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetInfo);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -168,20 +179,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测可寻址地址是否重复
|
||||
if (command.EnableAddressable)
|
||||
@@ -192,7 +189,7 @@ namespace YooAsset.Editor
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
@@ -211,61 +208,33 @@ namespace YooAsset.Editor
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源收集类
|
||||
/// </summary>
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
string address = GetAddress(command, group, assetPath);
|
||||
string bundleName = GetBundleName(command, group, assetPath);
|
||||
string address = GetAddress(command, group, assetInfo);
|
||||
string bundleName = GetBundleName(command, group, assetInfo);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetInfo, assetTags);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<string>();
|
||||
collectAssetInfo.DependAssets = new List<AssetInfo>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetPath);
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetInfo.AssetPath);
|
||||
|
||||
return collectAssetInfo;
|
||||
}
|
||||
private bool IsValidateAsset(CollectCommand command, string assetPath)
|
||||
{
|
||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetPath))
|
||||
return false;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(LightingDataAsset))
|
||||
return false;
|
||||
|
||||
// 忽略Unity引擎无法识别的文件
|
||||
if (command.IgnoreDefaultType)
|
||||
{
|
||||
if (assetType == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string fileExtension = System.IO.Path.GetExtension(assetPath);
|
||||
if (DefaultFilterRule.IsIgnoreFile(fileExtension))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath)
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
// 根据规则设置过滤资源文件
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
}
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.EnableAddressable == false)
|
||||
return string.Empty;
|
||||
@@ -274,15 +243,14 @@ namespace YooAsset.Editor
|
||||
return string.Empty;
|
||||
|
||||
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return adressValue;
|
||||
}
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.AutoCollectShaders)
|
||||
{
|
||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
if (assetInfo.IsShaderAsset())
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
@@ -292,7 +260,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 获取其它资源打包规则结果
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||
@@ -302,18 +270,19 @@ namespace YooAsset.Editor
|
||||
tags.AddRange(temper);
|
||||
return tags;
|
||||
}
|
||||
private List<string> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
List<AssetInfo> result = new List<AssetInfo>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
continue;
|
||||
|
||||
if (IsValidateAsset(command, assetPath))
|
||||
result.Add(assetPath);
|
||||
AssetInfo assetInfo = new AssetInfo(assetPath);
|
||||
if (command.IgnoreRule.IsIgnore(assetInfo) == false)
|
||||
result.Add(assetInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorConfig
|
||||
{
|
||||
public const string ConfigVersion = "v2.0.0";
|
||||
public const string ConfigVersion = "v2.1";
|
||||
|
||||
public const string XmlVersion = "Version";
|
||||
public const string XmlCommon = "Common";
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
|
||||
public const string XmlEnableAddressable = "AutoAddressable";
|
||||
public const string XmlLocationToLower = "LocationToLower";
|
||||
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
|
||||
public const string XmlIgnoreDefaultType = "IgnoreDefaultType";
|
||||
public const string XmlIgnoreRuleName = "IgnoreRuleName";
|
||||
|
||||
public const string XmlGroup = "Group";
|
||||
public const string XmlGroupActiveRule = "GroupActiveRule";
|
||||
@@ -101,7 +101,7 @@ namespace YooAsset.Editor
|
||||
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
|
||||
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
|
||||
package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false;
|
||||
package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
|
||||
packages.Add(package);
|
||||
|
||||
// 读取分组配置
|
||||
@@ -213,7 +213,7 @@ namespace YooAsset.Editor
|
||||
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
|
||||
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
|
||||
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
|
||||
packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString());
|
||||
packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
|
||||
root.AppendChild(packageElement);
|
||||
|
||||
// 设置分组配置
|
||||
@@ -258,6 +258,23 @@ namespace YooAsset.Editor
|
||||
if (configVersion == ConfigVersion)
|
||||
return true;
|
||||
|
||||
// v2.0.0 -> v2.1
|
||||
if (configVersion == "v2.0.0")
|
||||
{
|
||||
// 读取包裹配置
|
||||
var packageNodeList = root.GetElementsByTagName(XmlPackage);
|
||||
foreach (var packageNode in packageNodeList)
|
||||
{
|
||||
XmlElement packageElement = packageNode as XmlElement;
|
||||
if (packageElement.HasAttribute(XmlIgnoreRuleName) == false)
|
||||
packageElement.SetAttribute(XmlIgnoreRuleName, nameof(NormalIgnoreRule));
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "v2.1");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ namespace YooAsset.Editor
|
||||
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
return;
|
||||
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
@@ -84,12 +89,12 @@ namespace YooAsset.Editor
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(command, this);
|
||||
foreach (var assetInfo in temper)
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath} in group : {GroupName}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,12 +102,12 @@ namespace YooAsset.Editor
|
||||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
foreach (var collectAssetPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
if (collectAssetPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string address = collectAssetPair.Value.Address;
|
||||
string assetPath = collectAssetPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IncludeAssetGUID = false;
|
||||
|
||||
/// <summary>
|
||||
/// 忽略Unity引擎无法识别的文件
|
||||
/// </summary>
|
||||
public bool IgnoreDefaultType = true;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
|
||||
/// </summary>
|
||||
public bool AutoCollectShaders = true;
|
||||
|
||||
/// <summary>
|
||||
/// 资源忽略规则名
|
||||
/// </summary>
|
||||
public string IgnoreRuleName = nameof(NormalIgnoreRule);
|
||||
|
||||
/// <summary>
|
||||
/// 分组列表
|
||||
/// </summary>
|
||||
@@ -56,6 +56,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
if (string.IsNullOrEmpty(IgnoreRuleName))
|
||||
{
|
||||
throw new Exception($"{nameof(IgnoreRuleName)} is null or empty !");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AssetBundleCollectorSettingData.HasIgnoreRuleName(IgnoreRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IIgnoreRule)} class type : {IgnoreRuleName} in package : {PackageName}");
|
||||
}
|
||||
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
group.CheckConfigError();
|
||||
@@ -68,6 +78,14 @@ namespace YooAsset.Editor
|
||||
public bool FixConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
|
||||
if (string.IsNullOrEmpty(IgnoreRuleName))
|
||||
{
|
||||
Debug.LogWarning($"Set the {nameof(IgnoreRuleName)} to {nameof(NormalIgnoreRule)}");
|
||||
IgnoreRuleName = nameof(NormalIgnoreRule);
|
||||
isFixed = true;
|
||||
}
|
||||
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
if (group.FixConfigError())
|
||||
@@ -75,6 +93,7 @@ namespace YooAsset.Editor
|
||||
isFixed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return isFixed;
|
||||
}
|
||||
|
||||
@@ -89,12 +108,12 @@ namespace YooAsset.Editor
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets(command);
|
||||
foreach (var assetInfo in temper)
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +126,7 @@ namespace YooAsset.Editor
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool UniqueBundleName = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 包裹列表
|
||||
/// </summary>
|
||||
@@ -100,13 +99,13 @@ namespace YooAsset.Editor
|
||||
package.CheckConfigError();
|
||||
|
||||
// 创建资源收集命令
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
package.EnableAddressable,
|
||||
package.LocationToLower,
|
||||
package.IncludeAssetGUID,
|
||||
package.IgnoreDefaultType,
|
||||
package.AutoCollectShaders,
|
||||
UniqueBundleName);
|
||||
UniqueBundleName, ignoreRule);
|
||||
|
||||
// 获取收集的资源集合
|
||||
CollectResult collectResult = new CollectResult(command);
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace YooAsset.Editor
|
||||
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
|
||||
|
||||
/// <summary>
|
||||
/// 配置数据是否被修改
|
||||
/// </summary>
|
||||
@@ -129,6 +132,29 @@ namespace YooAsset.Editor
|
||||
_cacheActiveRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
|
||||
// IIgnoreRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheIgnoreRuleTypes.Clear();
|
||||
_cacheIgnoreRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(NormalIgnoreRule),
|
||||
typeof(RawFileIgnoreRule),
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheIgnoreRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AssetBundleCollectorSetting _setting = null;
|
||||
@@ -165,6 +191,7 @@ namespace YooAsset.Editor
|
||||
if (isFixed)
|
||||
{
|
||||
IsDirty = true;
|
||||
Debug.Log("Fix package config error done !");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +252,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<RuleDisplayName> GetIgnoreRuleNames()
|
||||
{
|
||||
List<RuleDisplayName> names = new List<RuleDisplayName>();
|
||||
foreach (var pair in _cacheIgnoreRuleTypes)
|
||||
{
|
||||
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 = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
|
||||
@@ -250,6 +289,10 @@ namespace YooAsset.Editor
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
public static bool HasIgnoreRuleName(string ruleName)
|
||||
{
|
||||
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
|
||||
}
|
||||
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
@@ -319,6 +362,23 @@ namespace YooAsset.Editor
|
||||
throw new Exception($"{nameof(IFilterRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IIgnoreRule GetIgnoreRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IIgnoreRule)Activator.CreateInstance(type);
|
||||
_cacheIgnoreRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IIgnoreRule)} is invalid:{ruleName}");
|
||||
}
|
||||
}
|
||||
|
||||
// 公共参数编辑相关
|
||||
public static void ModifyShowPackageView(bool showPackageView)
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace YooAsset.Editor
|
||||
private List<RuleDisplayName> _addressRuleList;
|
||||
private List<RuleDisplayName> _packRuleList;
|
||||
private List<RuleDisplayName> _filterRuleList;
|
||||
private List<RuleDisplayName> _ignoreRuleList;
|
||||
|
||||
private VisualElement _helpBoxContainer;
|
||||
|
||||
@@ -39,8 +40,8 @@ namespace YooAsset.Editor
|
||||
private Toggle _enableAddressableToogle;
|
||||
private Toggle _locationToLowerToogle;
|
||||
private Toggle _includeAssetGUIDToogle;
|
||||
private Toggle _ignoreDefaultTypeToogle;
|
||||
private Toggle _autoCollectShadersToogle;
|
||||
private PopupField<RuleDisplayName> _ignoreRulePopupField;
|
||||
|
||||
private VisualElement _packageContainer;
|
||||
private ListView _packageListView;
|
||||
@@ -65,9 +66,6 @@ namespace YooAsset.Editor
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
Undo.undoRedoPerformed -= RefreshWindow;
|
||||
Undo.undoRedoPerformed += RefreshWindow;
|
||||
|
||||
try
|
||||
{
|
||||
_collectorTypeList = new List<string>()
|
||||
@@ -80,6 +78,7 @@ namespace YooAsset.Editor
|
||||
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||
_ignoreRuleList = AssetBundleCollectorSettingData.GetIgnoreRuleNames();
|
||||
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
@@ -154,17 +153,6 @@ namespace YooAsset.Editor
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
_ignoreDefaultTypeToogle = root.Q<Toggle>("IgnoreDefaultType");
|
||||
_ignoreDefaultTypeToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
if (selectPackage != null)
|
||||
{
|
||||
selectPackage.IgnoreDefaultType = evt.newValue;
|
||||
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
_autoCollectShadersToogle = root.Q<Toggle>("AutoCollectShaders");
|
||||
_autoCollectShadersToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
@@ -176,6 +164,25 @@ namespace YooAsset.Editor
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
{
|
||||
_ignoreRulePopupField = new PopupField<RuleDisplayName>(_ignoreRuleList, 0);
|
||||
_ignoreRulePopupField.label = "File Ignore Rule";
|
||||
_ignoreRulePopupField.name = "IgnoreRulePopupField";
|
||||
_ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
_ignoreRulePopupField.style.width = 300;
|
||||
_ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
|
||||
_ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
|
||||
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
if(selectPackage != null)
|
||||
{
|
||||
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
|
||||
}
|
||||
});
|
||||
_setting2Container.Add(_ignoreRulePopupField);
|
||||
}
|
||||
|
||||
// 配置修复按钮
|
||||
var fixBtn = root.Q<Button>("FixButton");
|
||||
@@ -347,6 +354,15 @@ namespace YooAsset.Editor
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
public void OnEnable()
|
||||
{
|
||||
Undo.undoRedoPerformed += RefreshWindow;
|
||||
}
|
||||
public void OnDisable()
|
||||
{
|
||||
if (Undo.undoRedoPerformed != null)
|
||||
Undo.undoRedoPerformed -= RefreshWindow;
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
// 注意:清空所有撤销操作
|
||||
@@ -469,7 +485,8 @@ namespace YooAsset.Editor
|
||||
_enableAddressableToogle.SetValueWithoutNotify(selectPackage.EnableAddressable);
|
||||
_locationToLowerToogle.SetValueWithoutNotify(selectPackage.LocationToLower);
|
||||
_includeAssetGUIDToogle.SetValueWithoutNotify(selectPackage.IncludeAssetGUID);
|
||||
_ignoreDefaultTypeToogle.SetValueWithoutNotify(selectPackage.IgnoreDefaultType);
|
||||
_autoCollectShadersToogle.SetValueWithoutNotify(selectPackage.AutoCollectShaders);
|
||||
_ignoreRulePopupField.SetValueWithoutNotify(GetIgnoreRuleIndex(selectPackage.IgnoreRuleName));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -963,7 +980,7 @@ namespace YooAsset.Editor
|
||||
|
||||
if (collector.IsValid() == false)
|
||||
{
|
||||
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
|
||||
collector.CheckConfigError();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -973,14 +990,15 @@ namespace YooAsset.Editor
|
||||
|
||||
try
|
||||
{
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
|
||||
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild,
|
||||
_packageNameTxt.value,
|
||||
_enableAddressableToogle.value,
|
||||
_locationToLowerToogle.value,
|
||||
_includeAssetGUIDToogle.value,
|
||||
_ignoreDefaultTypeToogle.value,
|
||||
_autoCollectShadersToogle.value,
|
||||
_uniqueBundleNameToogle.value);
|
||||
_uniqueBundleNameToogle.value,
|
||||
ignoreRule);
|
||||
collector.CheckConfigError();
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
@@ -991,15 +1009,15 @@ namespace YooAsset.Editor
|
||||
|
||||
if (collectAssetInfos != null)
|
||||
{
|
||||
foreach (var collectAssetInfo in collectAssetInfos)
|
||||
foreach (var collectAsset in collectAssetInfos)
|
||||
{
|
||||
VisualElement elementRow = new VisualElement();
|
||||
elementRow.style.flexDirection = FlexDirection.Row;
|
||||
foldout.Add(elementRow);
|
||||
|
||||
string showInfo = collectAssetInfo.AssetPath;
|
||||
string showInfo = collectAsset.AssetInfo.AssetPath;
|
||||
if (_enableAddressableToogle.value)
|
||||
showInfo = $"[{collectAssetInfo.Address}] {collectAssetInfo.AssetPath}";
|
||||
showInfo = $"[{collectAsset.Address}] {collectAsset.AssetInfo.AssetPath}";
|
||||
|
||||
var label = new Label();
|
||||
label.text = showInfo;
|
||||
@@ -1071,6 +1089,15 @@ namespace YooAsset.Editor
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private RuleDisplayName GetIgnoreRuleIndex(string ruleName)
|
||||
{
|
||||
for (int i = 0; i < _ignoreRuleList.Count; i++)
|
||||
{
|
||||
if (_ignoreRuleList[i].ClassName == ruleName)
|
||||
return _ignoreRuleList[i];
|
||||
}
|
||||
return _ignoreRuleList[0];
|
||||
}
|
||||
private RuleDisplayName GetActiveRuleIndex(string ruleName)
|
||||
{
|
||||
for (int i = 0; i < _activeRuleList.Count; i++)
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Ignore Default Type" name="IgnoreDefaultType" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -21,9 +21,9 @@ namespace YooAsset.Editor
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
public AssetInfo AssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
@@ -33,15 +33,15 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 依赖的资源列表
|
||||
/// </summary>
|
||||
public List<string> DependAssets = new List<string>();
|
||||
public List<AssetInfo> DependAssets = new List<AssetInfo>();
|
||||
|
||||
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, List<string> assetTags)
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo, List<string> assetTags)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
AssetInfo = assetInfo;
|
||||
AssetTags = assetTags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 忽略Unity引擎无法识别的文件
|
||||
/// </summary>
|
||||
public bool IgnoreDefaultType { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
@@ -48,17 +43,24 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string ShadersBundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 忽略规则实例
|
||||
/// </summary>
|
||||
public IIgnoreRule IgnoreRule { private set; get; }
|
||||
|
||||
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool autoCollectShaders, bool uniqueBundleName)
|
||||
|
||||
public CollectCommand(EBuildMode buildMode, string packageName,
|
||||
bool enableAddressable, bool locationToLower, bool includeAssetGUID,
|
||||
bool autoCollectShaders, bool uniqueBundleName, IIgnoreRule ignoreRule)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
PackageName = packageName;
|
||||
EnableAddressable = enableAddressable;
|
||||
LocationToLower = locationToLower;
|
||||
IncludeAssetGUID = includeAssetGUID;
|
||||
IgnoreDefaultType = ignoreDefaultType;
|
||||
AutoCollectShaders = autoCollectShaders;
|
||||
UniqueBundleName = uniqueBundleName;
|
||||
IgnoreRule = ignoreRule;
|
||||
|
||||
// 着色器统一全名称
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源忽略规则接口
|
||||
/// </summary>
|
||||
public interface IIgnoreRule
|
||||
{
|
||||
bool IsIgnore(AssetInfo assetInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a72c4edf1a81c9942a9d43e9d2a77b53
|
||||
guid: bd55753dbb880fa449bf4e37b33d8ba7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -28,19 +28,41 @@ namespace YooAsset.Editor
|
||||
_bundleExtension = bundleExtension;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结果是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
return string.IsNullOrEmpty(_bundleName) == false && string.IsNullOrEmpty(_bundleExtension) == false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包全名称
|
||||
/// </summary>
|
||||
public string GetBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
fullName = $"{bundleName}.{_bundleExtension}";
|
||||
return fullName.ToLower();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取共享资源包全名称
|
||||
/// </summary>
|
||||
public string GetShareBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
fullName = $"share_{bundleName}.{_bundleExtension}";
|
||||
return fullName.ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,22 +6,6 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class DefaultFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 忽略的文件类型
|
||||
/// </summary>
|
||||
private readonly static HashSet<string> _ignoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
|
||||
/// <summary>
|
||||
/// 查询是否为忽略文件
|
||||
/// </summary>
|
||||
public static bool IsIgnoreFile(string fileExtension)
|
||||
{
|
||||
return _ignoreFileExtensions.Contains(fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集所有资源")]
|
||||
public class CollectAll : IFilterRule
|
||||
{
|
||||
@@ -70,6 +54,15 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集着色器")]
|
||||
public class CollectShader : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".shader";
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("收集着色器变种集合")]
|
||||
public class CollectShaderVariants : IFilterRule
|
||||
{
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class DefaultIgnoreRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 忽略的文件类型
|
||||
/// </summary>
|
||||
public readonly static HashSet<string> IgnoreFileExtensions = new HashSet<string>() { "", ".so", ".dll", ".cs", ".js", ".boo", ".meta", ".cginc", ".hlsl" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 适配常规的资源构建管线
|
||||
/// </summary>
|
||||
public class NormalIgnoreRule : IIgnoreRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为忽略文件
|
||||
/// </summary>
|
||||
public bool IsIgnore(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
|
||||
return true;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
if (assetInfo.AssetType == typeof(LightingDataAsset))
|
||||
return true;
|
||||
if (assetInfo.AssetType == typeof(LightmapParameters))
|
||||
return true;
|
||||
|
||||
// 忽略Unity引擎无法识别的文件
|
||||
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
|
||||
return true;
|
||||
}
|
||||
|
||||
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 适配原生文件构建管线
|
||||
/// </summary>
|
||||
public class RawFileIgnoreRule : IIgnoreRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为忽略文件
|
||||
/// </summary>
|
||||
public bool IsIgnore(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
|
||||
return true;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
if (assetInfo.AssetType == typeof(LightingDataAsset))
|
||||
return true;
|
||||
if (assetInfo.AssetType == typeof(LightmapParameters))
|
||||
return true;
|
||||
|
||||
return DefaultIgnoreRule.IgnoreFileExtensions.Contains(assetInfo.FileExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f01d5c82be95c8f4b93aeefc0454ae5c
|
||||
guid: b9c1900577194bb4ab49ce4332ccc4bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -147,6 +147,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打包着色器
|
||||
/// </summary>
|
||||
[DisplayName("打包着色器文件")]
|
||||
public class PackShader : IPackRule
|
||||
{
|
||||
public PackRuleResult GetPackRuleResult(PackRuleData data)
|
||||
{
|
||||
return DefaultPackRule.CreateShadersPackRuleResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打包着色器变种集合
|
||||
/// </summary>
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace YooAsset.Editor
|
||||
else
|
||||
{
|
||||
AssetBundle newBundle = AssetBundle.LoadFromFile(filePath);
|
||||
if(newBundle != null)
|
||||
if (newBundle != null)
|
||||
{
|
||||
string[] assetNames = newBundle.GetAllAssetNames();
|
||||
foreach (string name in assetNames)
|
||||
@@ -54,7 +54,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public static void UnloadAll()
|
||||
{
|
||||
foreach(var valuePair in _loadedAssetBundles)
|
||||
foreach (var valuePair in _loadedAssetBundles)
|
||||
{
|
||||
if (valuePair.Value != null)
|
||||
valuePair.Value.Unload(true);
|
||||
|
||||
@@ -35,18 +35,12 @@ namespace YooAsset.Editor
|
||||
/// 资源包视图
|
||||
/// </summary>
|
||||
BundleView,
|
||||
|
||||
/// <summary>
|
||||
/// 冗余资源试图
|
||||
/// </summary>
|
||||
Redundancy,
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private ReporterSummaryViewer _summaryViewer;
|
||||
private ReporterAssetListViewer _assetListViewer;
|
||||
private ReporterBundleListViewer _bundleListViewer;
|
||||
private ReporterRedundancyListViewer _redundancyListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private BuildReport _buildReport;
|
||||
@@ -76,7 +70,6 @@ namespace YooAsset.Editor
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.Redundancy.ToString(), ViewModeMenuAction3, ViewModeMenuFun3);
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
@@ -94,10 +87,6 @@ namespace YooAsset.Editor
|
||||
_bundleListViewer = new ReporterBundleListViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
|
||||
// 加载试图
|
||||
_redundancyListViewer = new ReporterRedundancyListViewer();
|
||||
_redundancyListViewer.InitViewer();
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.Summary;
|
||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||
@@ -125,7 +114,6 @@ namespace YooAsset.Editor
|
||||
_summaryViewer.FillViewData(_buildReport);
|
||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||
_redundancyListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
@@ -146,7 +134,6 @@ namespace YooAsset.Editor
|
||||
_summaryViewer.AttachParent(root);
|
||||
_assetListViewer.DetachParent();
|
||||
_bundleListViewer.DetachParent();
|
||||
_redundancyListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction1(DropdownMenuAction action)
|
||||
@@ -159,7 +146,6 @@ namespace YooAsset.Editor
|
||||
_summaryViewer.DetachParent();
|
||||
_assetListViewer.AttachParent(root);
|
||||
_bundleListViewer.DetachParent();
|
||||
_redundancyListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction2(DropdownMenuAction action)
|
||||
@@ -172,20 +158,6 @@ namespace YooAsset.Editor
|
||||
_summaryViewer.DetachParent();
|
||||
_assetListViewer.DetachParent();
|
||||
_bundleListViewer.AttachParent(root);
|
||||
_redundancyListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction3(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode != EViewMode.Redundancy)
|
||||
{
|
||||
_viewMode = EViewMode.Redundancy;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = EViewMode.Redundancy.ToString();
|
||||
_summaryViewer.DetachParent();
|
||||
_assetListViewer.DetachParent();
|
||||
_bundleListViewer.DetachParent();
|
||||
_redundancyListViewer.AttachParent(root);
|
||||
}
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun0(DropdownMenuAction action)
|
||||
@@ -209,13 +181,6 @@ namespace YooAsset.Editor
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun3(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode == EViewMode.Redundancy)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -28,10 +28,9 @@ namespace YooAsset.Editor
|
||||
public List<ReportBundleInfo> BundleInfos = new List<ReportBundleInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
/// 未被依赖的资源列表
|
||||
/// </summary>
|
||||
public List<ReportRedundancyInfo> RedundancyInfos = new List<ReportRedundancyInfo>();
|
||||
|
||||
public List<ReportIndependAsset> IndependAssets = new List<ReportIndependAsset>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包信息类
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ReportIndependAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public string AssetType;
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 358145d67e230b34883002b08b23cba3
|
||||
guid: 6f187b12ce298c0429119fcf194f2621
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ReportRedundancyInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public string AssetType;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// 说明:Meta文件记录的GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
|
||||
/// <summary>
|
||||
/// 冗余的资源包数量
|
||||
/// </summary>
|
||||
public int Number;
|
||||
}
|
||||
}
|
||||
@@ -58,10 +58,11 @@ namespace YooAsset.Editor
|
||||
public bool EnableAddressable;
|
||||
public bool LocationToLower;
|
||||
public bool IncludeAssetGUID;
|
||||
public bool IgnoreDefaultType;
|
||||
public bool AutoCollectShaders;
|
||||
public string IgnoreRuleName;
|
||||
|
||||
// 构建参数
|
||||
public bool EnableSharePackRule;
|
||||
public string EncryptionClassName;
|
||||
public EFileNameStyle FileNameStyle;
|
||||
public ECompressOption CompressOption;
|
||||
|
||||
@@ -1,317 +0,0 @@
|
||||
#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
|
||||
{
|
||||
internal class ReporterRedundancyListViewer
|
||||
{
|
||||
private enum ESortMode
|
||||
{
|
||||
AssetPath,
|
||||
AssetType,
|
||||
FileSize,
|
||||
Number,
|
||||
}
|
||||
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
|
||||
private ToolbarButton _topBar1;
|
||||
private ToolbarButton _topBar2;
|
||||
private ToolbarButton _topBar3;
|
||||
private ToolbarButton _topBar4;
|
||||
private ListView _assetListView;
|
||||
|
||||
private BuildReport _buildReport;
|
||||
private string _searchKeyWord;
|
||||
private ESortMode _sortMode = ESortMode.AssetPath;
|
||||
private bool _descendingSort = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化页面
|
||||
/// </summary>
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = UxmlLoader.LoadWindowUXML<ReporterRedundancyListViewer>();
|
||||
if (_visualAsset == null)
|
||||
return;
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 顶部按钮栏
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
||||
_topBar4 = _root.Q<ToolbarButton>("TopBar4");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
_topBar3.clicked += TopBar3_clicked;
|
||||
_topBar4.clicked += TopBar4_clicked;
|
||||
|
||||
// 资源列表
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充页面数据
|
||||
/// </summary>
|
||||
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
||||
{
|
||||
_buildReport = buildReport;
|
||||
_searchKeyWord = searchKeyWord;
|
||||
RefreshView();
|
||||
}
|
||||
private void RefreshView()
|
||||
{
|
||||
_assetListView.Clear();
|
||||
_assetListView.ClearSelection();
|
||||
_assetListView.itemsSource = FilterAndSortViewItems();
|
||||
_assetListView.Rebuild();
|
||||
RefreshSortingSymbol();
|
||||
}
|
||||
private List<ReportRedundancyInfo> FilterAndSortViewItems()
|
||||
{
|
||||
List<ReportRedundancyInfo> result = new List<ReportRedundancyInfo>(_buildReport.RedundancyInfos.Count);
|
||||
|
||||
// 过滤列表
|
||||
foreach (var redundancyInfo in _buildReport.RedundancyInfos)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchKeyWord) == false)
|
||||
{
|
||||
if (redundancyInfo.AssetPath.Contains(_searchKeyWord) == false)
|
||||
continue;
|
||||
}
|
||||
result.Add(redundancyInfo);
|
||||
}
|
||||
|
||||
// 排序列表
|
||||
if (_sortMode == ESortMode.AssetPath)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.AssetPath).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.AssetPath).ToList();
|
||||
}
|
||||
else if(_sortMode == ESortMode.AssetType)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.AssetType).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.AssetType).ToList();
|
||||
}
|
||||
else if (_sortMode == ESortMode.FileSize)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.FileSize).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.FileSize).ToList();
|
||||
}
|
||||
else if (_sortMode == ESortMode.Number)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.Number).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.Number).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
private void RefreshSortingSymbol()
|
||||
{
|
||||
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
|
||||
_topBar2.text = "Asset Type";
|
||||
_topBar3.text = "File Size";
|
||||
_topBar4.text = "Redundancy Num";
|
||||
|
||||
if (_sortMode == ESortMode.AssetPath)
|
||||
{
|
||||
if (_descendingSort)
|
||||
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↓";
|
||||
else
|
||||
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↑";
|
||||
}
|
||||
else if(_sortMode == ESortMode.AssetType)
|
||||
{
|
||||
if (_descendingSort)
|
||||
_topBar2.text = "Asset Type ↓";
|
||||
else
|
||||
_topBar2.text = "Asset Type ↑";
|
||||
}
|
||||
else if (_sortMode == ESortMode.FileSize)
|
||||
{
|
||||
if (_descendingSort)
|
||||
_topBar3.text = "File Size ↓";
|
||||
else
|
||||
_topBar3.text = "File Size ↑";
|
||||
}
|
||||
else if (_sortMode == ESortMode.Number)
|
||||
{
|
||||
if (_descendingSort)
|
||||
_topBar4.text = "Redundancy Num ↓";
|
||||
else
|
||||
_topBar4.text = "Redundancy Num ↑";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 挂接到父类页面上
|
||||
/// </summary>
|
||||
public void AttachParent(VisualElement parent)
|
||||
{
|
||||
parent.Add(_root);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从父类页面脱离开
|
||||
/// </summary>
|
||||
public void DetachParent()
|
||||
{
|
||||
_root.RemoveFromHierarchy();
|
||||
}
|
||||
|
||||
|
||||
// 资源列表相关
|
||||
private VisualElement MakeAssetListViewItem()
|
||||
{
|
||||
VisualElement element = new VisualElement();
|
||||
element.style.flexDirection = FlexDirection.Row;
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label1";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
label.style.flexGrow = 1f;
|
||||
label.style.width = 280;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label2";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
label.style.flexGrow = 0;
|
||||
label.style.width = 125;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label3";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
label.style.flexGrow = 0;
|
||||
label.style.width = 125;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label4";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
label.style.flexGrow = 0;
|
||||
label.style.width = 125;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
private void BindAssetListViewItem(VisualElement element, int index)
|
||||
{
|
||||
var sourceData = _assetListView.itemsSource as List<ReportRedundancyInfo>;
|
||||
var redundancyInfo = sourceData[index];
|
||||
|
||||
// Asset Path
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = redundancyInfo.AssetPath;
|
||||
|
||||
// Asset Type
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = redundancyInfo.AssetType;
|
||||
|
||||
// File Size
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = EditorUtility.FormatBytes(redundancyInfo.FileSize);
|
||||
|
||||
// Number
|
||||
var label4 = element.Q<Label>("Label4");
|
||||
label4.text = redundancyInfo.Number.ToString();
|
||||
}
|
||||
private void TopBar1_clicked()
|
||||
{
|
||||
if (_sortMode != ESortMode.AssetPath)
|
||||
{
|
||||
_sortMode = ESortMode.AssetPath;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
private void TopBar2_clicked()
|
||||
{
|
||||
if (_sortMode != ESortMode.AssetType)
|
||||
{
|
||||
_sortMode = ESortMode.AssetType;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
private void TopBar3_clicked()
|
||||
{
|
||||
if (_sortMode != ESortMode.FileSize)
|
||||
{
|
||||
_sortMode = ESortMode.FileSize;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
private void TopBar4_clicked()
|
||||
{
|
||||
if (_sortMode != ESortMode.Number)
|
||||
{
|
||||
_sortMode = ESortMode.Number;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
<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="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Asset Type" display-tooltip-when-elided="true" name="TopBar2" style="width: 125px; -unity-text-align: middle-left; flex-grow: 0; flex-shrink: 1;" />
|
||||
<uie:ToolbarButton text="File Size" display-tooltip-when-elided="true" name="TopBar3" style="width: 125px; -unity-text-align: middle-left; flex-grow: 0; flex-shrink: 1;" />
|
||||
<uie:ToolbarButton text="Redundancy Num" display-tooltip-when-elided="true" name="TopBar4" style="width: 125px; -unity-text-align: middle-left; flex-grow: 0; flex-shrink: 1;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1; flex-basis: 60px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5296d9c037ce3944b5c197cbdd78a8b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -67,16 +67,17 @@ namespace YooAsset.Editor
|
||||
_items.Add(new ItemWrapper("Package Version", buildReport.Summary.BuildPackageVersion));
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("Settings", string.Empty));
|
||||
_items.Add(new ItemWrapper("Collect Settings", string.Empty));
|
||||
_items.Add(new ItemWrapper("Unique Bundle Name", $"{buildReport.Summary.UniqueBundleName}"));
|
||||
_items.Add(new ItemWrapper("Enable Addressable", $"{buildReport.Summary.EnableAddressable}"));
|
||||
_items.Add(new ItemWrapper("Location To Lower", $"{buildReport.Summary.LocationToLower}"));
|
||||
_items.Add(new ItemWrapper("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}"));
|
||||
_items.Add(new ItemWrapper("Ignore Default Type", $"{buildReport.Summary.IgnoreDefaultType}"));
|
||||
_items.Add(new ItemWrapper("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}"));
|
||||
_items.Add(new ItemWrapper("Ignore Rule Name", $"{buildReport.Summary.IgnoreRuleName}"));
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("Build Params", string.Empty));
|
||||
_items.Add(new ItemWrapper("Enable Share Pack Rule", $"{buildReport.Summary.EnableSharePackRule}"));
|
||||
_items.Add(new ItemWrapper("Encryption Class Name", buildReport.Summary.EncryptionClassName));
|
||||
_items.Add(new ItemWrapper("FileNameStyle", $"{buildReport.Summary.FileNameStyle}"));
|
||||
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01865ad6f7c806147b6cb37f2d83bc96
|
||||
guid: 4cb0b75b2f649c64bb1d8203f2fbfeea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
58
Assets/YooAsset/Editor/Common/AssetInfo.cs
Normal file
58
Assets/YooAsset/Editor/Common/AssetInfo.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetInfo
|
||||
{
|
||||
private string _fileExtension = null;
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType;
|
||||
|
||||
/// <summary>
|
||||
/// 文件格式
|
||||
/// </summary>
|
||||
public string FileExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_fileExtension))
|
||||
_fileExtension = System.IO.Path.GetExtension(AssetPath);
|
||||
return _fileExtension;
|
||||
}
|
||||
}
|
||||
|
||||
public AssetInfo(string assetPath)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(AssetPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为着色器资源
|
||||
/// </summary>
|
||||
public bool IsShaderAsset()
|
||||
{
|
||||
if (AssetType == typeof(UnityEngine.Shader) || AssetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fbb7b27f54d3b0439a951348fd9d785
|
||||
guid: 4a2e0565919d49348b8deeb14258a985
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,36 +1,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CacheFileInfo
|
||||
public class CacheFileInfo
|
||||
{
|
||||
private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
|
||||
public string RemoteFileName { private set; get; }
|
||||
public string FilePath { private set; get; }
|
||||
public string FileCRC { private set; get; }
|
||||
public long FileSize { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 写入资源包信息
|
||||
/// </summary>
|
||||
public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
public CacheFileInfo(string remoteFileName, string filePath, string fileCRC, long fileSize)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SharedBuffer.Clear();
|
||||
SharedBuffer.WriteUTF8(dataFileCRC);
|
||||
SharedBuffer.WriteInt64(dataFileSize);
|
||||
SharedBuffer.WriteToStream(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取资源包信息
|
||||
/// </summary>
|
||||
public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||
{
|
||||
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
dataFileCRC = buffer.ReadUTF8();
|
||||
dataFileSize = buffer.ReadInt64();
|
||||
RemoteFileName = remoteFileName;
|
||||
FilePath = filePath;
|
||||
FileCRC = fileCRC;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -13,6 +10,37 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static bool DisableUnityCacheOnWebGL = false;
|
||||
|
||||
#region 资源信息文件相关
|
||||
private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
|
||||
|
||||
/// <summary>
|
||||
/// 写入资源包信息
|
||||
/// </summary>
|
||||
public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SharedBuffer.Clear();
|
||||
SharedBuffer.WriteUTF8(dataFileCRC);
|
||||
SharedBuffer.WriteInt64(dataFileSize);
|
||||
SharedBuffer.WriteToStream(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取资源包信息
|
||||
/// </summary>
|
||||
public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||
{
|
||||
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
dataFileCRC = buffer.ReadUTF8();
|
||||
dataFileSize = buffer.ReadInt64();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源文件验证相关
|
||||
/// <summary>
|
||||
/// 验证缓存文件(子线程内操作)
|
||||
/// </summary>
|
||||
@@ -34,7 +62,7 @@ namespace YooAsset
|
||||
return EVerifyResult.InfoFileNotExisted;
|
||||
|
||||
// 解析信息文件获取验证数据
|
||||
CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
|
||||
CacheHelper.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
@@ -83,7 +111,7 @@ namespace YooAsset
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string crc = HashUtility.FileCRC32(filePath);
|
||||
string crc = HashUtility.FileCRC32Safely(filePath);
|
||||
if (crc == fileCRC)
|
||||
return EVerifyResult.Succeed;
|
||||
else
|
||||
@@ -99,5 +127,6 @@ namespace YooAsset
|
||||
return EVerifyResult.Exception;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class GetAllCacheFileInfosOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
TryLoadCacheManifest,
|
||||
GetCacheFileInfos,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PersistentManager _persistent;
|
||||
private readonly CacheManager _cache;
|
||||
private readonly string _packageVersion;
|
||||
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
|
||||
private PackageManifest _manifest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
private List<CacheFileInfo> _cacheFileInfos;
|
||||
|
||||
/// <summary>
|
||||
/// 搜索结果
|
||||
/// </summary>
|
||||
public List<CacheFileInfo> Result
|
||||
{
|
||||
get { return _cacheFileInfos; }
|
||||
}
|
||||
|
||||
|
||||
internal GetAllCacheFileInfosOperation(PersistentManager persistent, CacheManager cache, string packageVersion)
|
||||
{
|
||||
_persistent = persistent;
|
||||
_cache = cache;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.TryLoadCacheManifest)
|
||||
{
|
||||
if (_tryLoadCacheManifestOp == null)
|
||||
{
|
||||
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_persistent, _packageVersion);
|
||||
OperationSystem.StartOperation(_cache.PackageName, _tryLoadCacheManifestOp);
|
||||
}
|
||||
|
||||
if (_tryLoadCacheManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_manifest = _tryLoadCacheManifestOp.Manifest;
|
||||
_steps = ESteps.GetCacheFileInfos;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _tryLoadCacheManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.GetCacheFileInfos)
|
||||
{
|
||||
var allCachedGUIDs = _cache.GetAllCachedGUIDs();
|
||||
_cacheFileInfos = new List<CacheFileInfo>(allCachedGUIDs.Count);
|
||||
for (int i = 0; i < allCachedGUIDs.Count; i++)
|
||||
{
|
||||
var cachedGUID = allCachedGUIDs[i];
|
||||
var wrapper = _cache.TryGetWrapper(cachedGUID);
|
||||
if (wrapper != null)
|
||||
{
|
||||
if (_manifest.TryGetPackageBundleByCacheGUID(cachedGUID, out var packageBundle))
|
||||
{
|
||||
var cacheFileInfo = new CacheFileInfo(packageBundle.FileName, wrapper.DataFilePath, wrapper.DataFileCRC, wrapper.DataFileSize);
|
||||
_cacheFileInfos.Add(cacheFileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d37e37f5d78ddf8468adcf2dff1edfbb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -90,12 +90,19 @@ namespace YooAsset
|
||||
string fileRootPath = chidDirectory.FullName;
|
||||
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
|
||||
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
|
||||
string dataFileExtension = FindDataFileExtension(chidDirectory);
|
||||
|
||||
// 跳过断点续传的临时文件
|
||||
if (dataFileExtension == ".temp")
|
||||
continue;
|
||||
|
||||
// 注意:根据配置需求数据文件会带文件格式
|
||||
if (_persistent.AppendFileExtension)
|
||||
{
|
||||
string fileExtension = FindFileExtension(chidDirectory);
|
||||
if (string.IsNullOrEmpty(fileExtension) == false)
|
||||
dataFilePath += fileExtension;
|
||||
if (string.IsNullOrEmpty(dataFileExtension) == false)
|
||||
dataFilePath += dataFileExtension;
|
||||
}
|
||||
|
||||
VerifyCacheFileElement element = new VerifyCacheFileElement(_cache.PackageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
|
||||
VerifyElements.Add(element);
|
||||
}
|
||||
@@ -106,14 +113,12 @@ namespace YooAsset
|
||||
|
||||
return isFindItem;
|
||||
}
|
||||
private string FindFileExtension(DirectoryInfo directoryInfo)
|
||||
private string FindDataFileExtension(DirectoryInfo directoryInfo)
|
||||
{
|
||||
string dataFileExtension = string.Empty;
|
||||
var fileInfos = directoryInfo.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".temp")
|
||||
continue;
|
||||
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
|
||||
{
|
||||
dataFileExtension = fileInfo.Extension;
|
||||
|
||||
@@ -15,11 +15,16 @@ namespace YooAsset
|
||||
#elif UNITY_IPHONE
|
||||
return StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_ANDROID
|
||||
if (path.StartsWith("jar:file://"))
|
||||
return path;
|
||||
else
|
||||
return StringUtility.Format("jar:file://{0}", path);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
return new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_OPENHARMONY
|
||||
return path;
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,12 @@ namespace YooAsset
|
||||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#if UNITY_OPENHARMONY
|
||||
return $"file://{path}";
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
@@ -176,6 +181,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
YooLogger.Log($"Save package version : {version}");
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
||||
{
|
||||
Directory.Delete(FileRootPath, true);
|
||||
}
|
||||
catch(System.Exception e)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
YooLogger.Warning($"Failed delete cache bundle folder : {e}");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void EditorRequestDebugReport()
|
||||
{
|
||||
if(UnityEditor.EditorApplication.isPlaying)
|
||||
if (UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
var report = YooAssets.GetDebugReport();
|
||||
EditorHandleDebugReportCallback?.Invoke(0, report);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace YooAsset
|
||||
if (offset > _timeout)
|
||||
{
|
||||
YooLogger.Warning($"Web file request timeout : {_requestURL}");
|
||||
if(_requester != null)
|
||||
if (_requester != null)
|
||||
_requester.Abort();
|
||||
_isAbort = true;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace YooAsset
|
||||
fileInfo.MoveTo(dataFilePath);
|
||||
|
||||
// 写入信息文件记录验证数据
|
||||
CacheFileInfo.WriteInfoToFile(infoFilePath, dataFileCRC, dataFileSize);
|
||||
CacheHelper.WriteInfoToFile(infoFilePath, dataFileCRC, dataFileSize);
|
||||
|
||||
// 记录缓存文件
|
||||
_bundleInfo.CacheRecord();
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace YooAsset
|
||||
public string RequestNetError { private set; get; }
|
||||
public long RequestHttpCode { private set; get; }
|
||||
|
||||
public AssetBundleWebRequest() { }
|
||||
public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
|
||||
{
|
||||
if (Status != ERequestStatus.None)
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace YooAsset
|
||||
public string RequestNetError { private set; get; }
|
||||
public long RequestHttpCode { private set; get; }
|
||||
|
||||
public FileGeneralRequest() { }
|
||||
public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
|
||||
{
|
||||
if (Status != ERequestStatus.None)
|
||||
@@ -98,7 +99,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_webRequest != null)
|
||||
{
|
||||
_webRequest.Dispose(); //注意:引擎底层会自动调用Abort方法
|
||||
//注意:引擎底层会自动调用Abort方法
|
||||
_webRequest.Dispose();
|
||||
_webRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace YooAsset
|
||||
private string _tempFilePath;
|
||||
private UnityWebRequest _webRequest;
|
||||
private DownloadHandlerFileRange _downloadHandle;
|
||||
private ulong _fileOriginLength;
|
||||
private ulong _fileOriginLength = 0;
|
||||
|
||||
public ERequestStatus Status { private set; get; } = ERequestStatus.None;
|
||||
public float DownloadProgress { private set; get; }
|
||||
@@ -16,6 +16,7 @@ namespace YooAsset
|
||||
public string RequestNetError { private set; get; }
|
||||
public long RequestHttpCode { private set; get; }
|
||||
|
||||
public FileResumeRequest() { }
|
||||
public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
|
||||
{
|
||||
if (Status != ERequestStatus.None)
|
||||
@@ -141,6 +142,7 @@ namespace YooAsset
|
||||
|
||||
if (_webRequest != null)
|
||||
{
|
||||
//注意:引擎底层会自动调用Abort方法
|
||||
_webRequest.Dispose();
|
||||
_webRequest = null;
|
||||
}
|
||||
|
||||
@@ -14,52 +14,52 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 任务状态
|
||||
/// </summary>
|
||||
public ERequestStatus Status { get; }
|
||||
ERequestStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度(0f~1f)
|
||||
/// </summary>
|
||||
public float DownloadProgress { get; }
|
||||
float DownloadProgress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 已经下载的总字节数
|
||||
/// </summary>
|
||||
public ulong DownloadedBytes { get; }
|
||||
ulong DownloadedBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回的网络错误
|
||||
/// </summary>
|
||||
public string RequestNetError { get; }
|
||||
string RequestNetError { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回的HTTP CODE
|
||||
/// </summary>
|
||||
public long RequestHttpCode { get; }
|
||||
long RequestHttpCode { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建任务
|
||||
/// </summary>
|
||||
public void Create(string url, BundleInfo bundleInfo, params object[] args);
|
||||
void Create(string url, BundleInfo bundleInfo, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// 更新任务
|
||||
/// </summary>
|
||||
public void Update();
|
||||
void Update();
|
||||
|
||||
/// <summary>
|
||||
/// 终止任务
|
||||
/// </summary>
|
||||
public void Abort();
|
||||
void Abort();
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成(无论成功或失败)
|
||||
/// </summary>
|
||||
public bool IsDone();
|
||||
bool IsDone();
|
||||
|
||||
/// <summary>
|
||||
/// 获取请求的对象
|
||||
/// </summary>
|
||||
public object GetRequestObject();
|
||||
object GetRequestObject();
|
||||
}
|
||||
}
|
||||
@@ -150,5 +150,10 @@ namespace YooAsset
|
||||
/// 内置资源查询服务接口
|
||||
/// </summary>
|
||||
public IBuildinQueryServices BuildinQueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 微信缓存查询服务接口
|
||||
/// </summary>
|
||||
public IWechatQueryServices WechatQueryServices = null;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace YooAsset
|
||||
internal abstract void InternalOnUpdate();
|
||||
internal virtual void InternalOnAbort() { }
|
||||
|
||||
internal void Init(string packageName)
|
||||
internal void SetPackageName(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,16 @@ namespace YooAsset
|
||||
public static void StartOperation(string packageName, AsyncOperationBase operation)
|
||||
{
|
||||
_newList.Add(operation);
|
||||
operation.Init(packageName);
|
||||
operation.SetPackageName(packageName);
|
||||
operation.SetStart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始处理异步操作类
|
||||
/// </summary>
|
||||
public static void StartOperation(AsyncOperationBase operation)
|
||||
{
|
||||
_newList.Add(operation);
|
||||
operation.SetStart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
internal void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景名称
|
||||
/// </summary>
|
||||
@@ -90,28 +100,21 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
{
|
||||
var temp = Provider as DatabaseSceneProvider;
|
||||
return temp.UnSuspendLoad();
|
||||
var provider = Provider as DatabaseSceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else if (Provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = Provider as BundledSceneProvider;
|
||||
return temp.UnSuspendLoad();
|
||||
var provider = Provider as BundledSceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,5 +174,7 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -208,22 +208,47 @@ namespace YooAsset
|
||||
// Check error
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
var result = MainBundleInfo.VerifySelf();
|
||||
if (result != EVerifyResult.Succeed)
|
||||
if (result == EVerifyResult.Succeed)
|
||||
{
|
||||
YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}");
|
||||
// 说明:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
// 大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||
byte[] fileData = FileUtility.ReadAllBytes(FileLoadPath);
|
||||
if (fileData != null && fileData.Length > 0)
|
||||
CacheBundle = AssetBundle.LoadFromMemory(fileData);
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle from memory : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}";
|
||||
YooLogger.Error(LastError);
|
||||
MainBundleInfo.CacheDiscard();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -31,6 +31,22 @@ namespace YooAsset
|
||||
{
|
||||
_error = null;
|
||||
_provider = provider;
|
||||
|
||||
// 注意:卸载场景前必须先解除挂起操作
|
||||
if (provider is DatabaseSceneProvider)
|
||||
{
|
||||
var temp = provider as DatabaseSceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else if (provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = provider as BundledSceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -54,7 +70,7 @@ namespace YooAsset
|
||||
_steps = ESteps.PrepareDone;
|
||||
}
|
||||
|
||||
if(_steps == ESteps.PrepareDone)
|
||||
if (_steps == ESteps.PrepareDone)
|
||||
{
|
||||
if (_provider.IsDone == false)
|
||||
return;
|
||||
@@ -82,7 +98,6 @@ namespace YooAsset
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
|
||||
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
@@ -91,7 +106,7 @@ namespace YooAsset
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone == false)
|
||||
return;
|
||||
|
||||
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace YooAsset
|
||||
internal sealed class BundledSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly bool _suspendLoad;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private bool _suspendLoadMode;
|
||||
|
||||
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoad = suspendLoad;
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -35,6 +35,12 @@ namespace YooAsset
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
@@ -60,11 +66,21 @@ namespace YooAsset
|
||||
// 2. 加载场景
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
// 注意:如果场景不存在则返回NULL
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。
|
||||
LoadSceneParameters parameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = SceneManager.LoadScene(MainAssetInfo.AssetPath, parameters);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:如果场景不存在异步加载方法返回NULL
|
||||
// 注意:即使是异步加载也要在当帧获取到场景对象
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
@@ -76,37 +92,55 @@ namespace YooAsset
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone)
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public bool UnSuspendLoad()
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (_asyncOperation == null)
|
||||
return false;
|
||||
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
return true;
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,14 @@ namespace YooAsset
|
||||
internal sealed class DatabaseSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private readonly bool _suspendLoad;
|
||||
private bool _suspendLoadMode;
|
||||
private AsyncOperation _asyncOperation;
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoad = suspendLoad;
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
@@ -57,12 +57,19 @@ namespace YooAsset
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
||||
loadSceneParameters.loadSceneMode = SceneMode;
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
@@ -74,13 +81,33 @@ namespace YooAsset
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone)
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
@@ -92,20 +119,18 @@ namespace YooAsset
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public bool UnSuspendLoad()
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (_asyncOperation == null)
|
||||
return false;
|
||||
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
return true;
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,9 @@ namespace YooAsset
|
||||
_failedTryAgain = failedTryAgain;
|
||||
_timeout = timeout;
|
||||
|
||||
// 设置包裹名称 (fix #210)
|
||||
SetPackageName(packageName);
|
||||
|
||||
// 统计下载信息
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
@@ -208,12 +211,18 @@ namespace YooAsset
|
||||
{
|
||||
if (_bundleInfoList != null)
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = _bundleInfoList.Count;
|
||||
foreach (var packageBundle in _bundleInfoList)
|
||||
{
|
||||
TotalDownloadBytes += packageBundle.Bundle.FileSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,7 +272,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
OperationSystem.StartOperation(_packageName, this);
|
||||
OperationSystem.StartOperation(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -332,6 +332,7 @@ namespace YooAsset
|
||||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
@@ -347,7 +348,7 @@ namespace YooAsset
|
||||
if (_cachingOperation == null)
|
||||
{
|
||||
_cachingOperation = new PackageCachingOperation(_impl.Persistent, _impl.Cache);
|
||||
OperationSystem.StartOperation(_impl.PackageName,_cachingOperation);
|
||||
OperationSystem.StartOperation(_impl.PackageName, _cachingOperation);
|
||||
}
|
||||
|
||||
Progress = _cachingOperation.Progress;
|
||||
|
||||
@@ -142,9 +142,9 @@ namespace YooAsset
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (Path.HasExtension(location))
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (ReferenceEquals(location, locationWithoutExtension) == false)
|
||||
{
|
||||
string locationWithoutExtension = PathUtility.RemoveExtension(location);
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
@@ -190,6 +190,7 @@ namespace YooAsset
|
||||
Manifest.BundleList = new List<PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic1 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic2 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic3 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
@@ -212,8 +213,8 @@ namespace YooAsset
|
||||
Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
|
||||
// 注意:原始文件可能存在相同的CacheGUID
|
||||
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
|
||||
Manifest.CacheGUIDs.Add(packageBundle.CacheGUID);
|
||||
if (Manifest.BundleDic3.ContainsKey(packageBundle.CacheGUID) == false)
|
||||
Manifest.BundleDic3.Add(packageBundle.CacheGUID, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
string fileHash = HashUtility.FileMD5(_manifestFilePath);
|
||||
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
|
||||
if (fileHash != _queryCachePackageHashOp.PackageHash)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -134,7 +134,6 @@ namespace YooAsset
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ namespace YooAsset
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
LoadCacheManifest,
|
||||
CheckDeserializeManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,12 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供CacheGUID获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
/// <summary>
|
||||
/// 资源映射集合(提供AssetPath获取PackageAsset)
|
||||
/// </summary>
|
||||
@@ -93,12 +99,6 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, string> AssetPathMapping2;
|
||||
|
||||
/// <summary>
|
||||
/// 该资源清单所有文件的缓存GUID集合
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public HashSet<string> CacheGUIDs = new HashSet<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 尝试映射为资源路径
|
||||
@@ -189,12 +189,20 @@ namespace YooAsset
|
||||
return BundleDic2.TryGetValue(fileName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByCacheGUID(string cacheGUID, out PackageBundle result)
|
||||
{
|
||||
return BundleDic3.TryGetValue(cacheGUID, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
return CacheGUIDs.Contains(cacheGUID);
|
||||
return BundleDic3.ContainsKey(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -44,10 +44,15 @@ namespace YooAsset
|
||||
{
|
||||
public static class EditorSimulateModeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器下模拟构建清单
|
||||
/// </summary>
|
||||
public static string SimulateBuild(string buildPipelineName, string packageName) { throw new System.Exception("Only support in unity editor !"); }
|
||||
public static string SimulateBuild(string buildPipelineName, string packageName)
|
||||
{
|
||||
throw new System.Exception("Only support in unity editor !");
|
||||
}
|
||||
|
||||
public static string SimulateBuild(EDefaultBuildPipeline buildPipeline, string packageName)
|
||||
{
|
||||
throw new System.Exception("Only support in unity editor !");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -75,7 +75,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_deliveryQueryServices == null)
|
||||
return false;
|
||||
return _deliveryQueryServices.Query(PackageName, packageBundle.FileName);
|
||||
return _deliveryQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ namespace YooAsset
|
||||
}
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName);
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace YooAsset
|
||||
private ResourceAssist _assist;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
private IWechatQueryServices _wechatQueryServices;
|
||||
|
||||
public readonly string PackageName;
|
||||
public DownloadManager Download
|
||||
@@ -34,11 +35,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
|
||||
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
|
||||
{
|
||||
_assist = assist;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
_wechatQueryServices = wechatQueryServices;
|
||||
|
||||
var operation = new WebPlayModeInitializationOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
@@ -65,9 +67,16 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
if (_wechatQueryServices != null)
|
||||
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName);
|
||||
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
|
||||
}
|
||||
|
||||
#region IPlayMode接口
|
||||
@@ -116,6 +125,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
@@ -137,6 +150,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
@@ -194,6 +211,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
@@ -184,7 +184,8 @@ namespace YooAsset
|
||||
var initializeParameters = parameters as WebPlayModeParameters;
|
||||
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.RemoteServices);
|
||||
initializeParameters.RemoteServices,
|
||||
initializeParameters.WechatQueryServices);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -314,28 +315,6 @@ namespace YooAsset
|
||||
return _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearUnusedCacheFilesOperation(this, _cacheMgr);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearAllCacheFilesOperation(_cacheMgr);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地包裹的版本信息
|
||||
/// </summary>
|
||||
@@ -412,6 +391,40 @@ namespace YooAsset
|
||||
_persistentMgr.DeleteSandboxPackageFolder();
|
||||
_cacheMgr.ClearAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹未使用的缓存文件
|
||||
/// </summary>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearUnusedCacheFilesOperation(this, _cacheMgr);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new ClearAllCacheFilesOperation(_cacheMgr);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定版本的缓存信息
|
||||
/// </summary>
|
||||
public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
|
||||
var operation = new GetAllCacheFileInfosOperation(_persistentMgr, _cacheMgr, packageVersion);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源信息
|
||||
@@ -590,6 +603,29 @@ namespace YooAsset
|
||||
#endregion
|
||||
|
||||
#region 场景加载
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, true, sceneMode, false, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景
|
||||
/// </summary>
|
||||
@@ -601,8 +637,7 @@ namespace YooAsset
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
return handle;
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -615,7 +650,16 @@ namespace YooAsset
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 0)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return LoadSceneInternal(assetInfo, false, sceneMode, suspendLoad, priority);
|
||||
}
|
||||
|
||||
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
|
||||
{
|
||||
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
|
||||
DebugCheckAssetLoadType(assetInfo.AssetType);
|
||||
var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
|
||||
if (waitForAsyncComplete)
|
||||
handle.WaitForAsyncComplete();
|
||||
return handle;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -6,6 +6,10 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 查询是否为应用程序内置的资源文件
|
||||
/// </summary>
|
||||
bool Query(string packageName, string fileName);
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,18 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 查询是否为开发者分发的资源文件
|
||||
/// </summary>
|
||||
bool Query(string packageName, string fileName);
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
|
||||
/// <summary>
|
||||
/// 获取分发资源文件的路径
|
||||
/// </summary>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <returns>返回资源文件的路径</returns>
|
||||
string GetFilePath(string packageName, string fileName);
|
||||
}
|
||||
}
|
||||
15
Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs
Normal file
15
Assets/YooAsset/Runtime/Services/IWechatQueryServices.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public interface IWechatQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为微信缓存的资源文件
|
||||
/// </summary>
|
||||
/// <param name="packageName">包裹名称</param>
|
||||
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
|
||||
/// <param name="fileCRC">文件哈希值</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
bool Query(string packageName, string fileName, string fileCRC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6b28ce9425f5eb4f972dcda9fd864f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -104,7 +104,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
if(BitConverter.IsLittleEndian)
|
||||
if (BitConverter.IsLittleEndian)
|
||||
return new[] { (byte)_currentCrc, (byte)(_currentCrc >> 8), (byte)(_currentCrc >> 16), (byte)(_currentCrc >> 24) };
|
||||
else
|
||||
return new[] { (byte)(_currentCrc >> 24), (byte)(_currentCrc >> 16), (byte)(_currentCrc >> 8), (byte)_currentCrc };
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 哈希工具类
|
||||
/// </summary>
|
||||
internal static class HashUtility
|
||||
public static class HashUtility
|
||||
{
|
||||
private static string ToString(byte[] hashBytes)
|
||||
{
|
||||
@@ -214,14 +214,22 @@ namespace YooAsset
|
||||
/// 获取文件的Hash值
|
||||
/// </summary>
|
||||
public static string FileSHA1(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamSHA1(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的Hash值
|
||||
/// </summary>
|
||||
public static string FileSHA1Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return FileSHA1(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Exception(e);
|
||||
@@ -266,14 +274,22 @@ namespace YooAsset
|
||||
/// 获取文件的MD5
|
||||
/// </summary>
|
||||
public static string FileMD5(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamMD5(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的MD5
|
||||
/// </summary>
|
||||
public static string FileMD5Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return FileMD5(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Exception(e);
|
||||
@@ -316,14 +332,22 @@ namespace YooAsset
|
||||
/// 获取文件的CRC32
|
||||
/// </summary>
|
||||
public static string FileCRC32(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return StreamCRC32(fs);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的CRC32
|
||||
/// </summary>
|
||||
public static string FileCRC32Safely(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return FileCRC32(filePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Exception(e);
|
||||
|
||||
@@ -156,6 +156,28 @@ namespace YooAsset
|
||||
#endregion
|
||||
|
||||
#region 场景加载
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
/// </summary>
|
||||
/// <param name="location">场景的定位地址</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneSync(location, sceneMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载场景
|
||||
/// </summary>
|
||||
/// <param name="assetInfo">场景的资源信息</param>
|
||||
/// <param name="sceneMode">场景加载模式</param>
|
||||
public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single)
|
||||
{
|
||||
DebugCheckDefaultPackageValid();
|
||||
return _defaultPackage.LoadSceneSync(assetInfo, sceneMode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景
|
||||
/// </summary>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user