mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdca693413 | ||
|
|
a2d30ca99a | ||
|
|
5c02bc2bee | ||
|
|
00ffd55fef | ||
|
|
32148821a1 | ||
|
|
60f6483a86 | ||
|
|
9b80300f19 | ||
|
|
8f02bfa3a6 | ||
|
|
93607ad62a | ||
|
|
3cbf891674 | ||
|
|
00688a65af | ||
|
|
c0099cb90c | ||
|
|
43248408fc | ||
|
|
d535500b9e | ||
|
|
9cea3e1ba9 | ||
|
|
746fa44ab8 | ||
|
|
b23d56f49c | ||
|
|
3693f1ea98 | ||
|
|
14127e8097 | ||
|
|
ad0d47bd68 | ||
|
|
b59fb0d811 | ||
|
|
0b1990f040 | ||
|
|
8deb239450 | ||
|
|
33387e8d26 | ||
|
|
9d4656a1f2 | ||
|
|
9c49d8d54a | ||
|
|
4ee6b3cdc2 | ||
|
|
d5636a71b1 | ||
|
|
b1ca47fc14 | ||
|
|
ddb35620cb | ||
|
|
a906a84721 | ||
|
|
d43d30f72f | ||
|
|
e9841a65c6 | ||
|
|
2dd3ba847e | ||
|
|
0dcbe0574c | ||
|
|
d01dce438c | ||
|
|
76929cc015 | ||
|
|
cde0f4bcd8 | ||
|
|
8dc0560537 | ||
|
|
a054740de6 | ||
|
|
029b850d6b | ||
|
|
8260653eae | ||
|
|
bd7b9b5c44 | ||
|
|
8f33a391f8 | ||
|
|
2f9d3a9f11 | ||
|
|
316294f449 | ||
|
|
09fac3bd64 | ||
|
|
2da81212b4 | ||
|
|
4cad587609 | ||
|
|
67eeae31c7 | ||
|
|
ae465a47a9 | ||
|
|
23b59f6ad6 | ||
|
|
09e3483e0a | ||
|
|
b3f4e9ae6e | ||
|
|
79efe6237d | ||
|
|
bf0f479234 | ||
|
|
ece1dab28b | ||
|
|
b913b5c20c |
@@ -2,6 +2,109 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.1.0] - 2022-06-23
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了AssetBundleCollector窗口,在切换EnableAddressable时未及时刷新界面的问题。
|
||||
- 修复了AssetBundleCollector窗口,资源过滤器CollectSprite无效的问题。
|
||||
- 修复了AssetBundleCollector窗口,无法正常预览StaticAssetCollector的资源列表的问题。
|
||||
- 修复了在离线模式下原生文件每次都从包内加载的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 变更了共享资源打包机制。
|
||||
- AssetBundleCollector窗口增加了分组禁用功能。
|
||||
- AssetBundleDebugger窗口增加了真机远程调试功能。
|
||||
- AssetBundleBuilder窗口在构建成功后自动显示构建文件夹。
|
||||
- DownloaderOperation.OnDownloadFileFailedCallback委托变更为OnDownloadErrorCallback委托。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增UpdateManifestOperation.FoundNewManifest字段。
|
||||
- 新增DownloaderOperation.OnStartDownloadFileCallback委托。
|
||||
- 新增AssetInfo.Address字段。
|
||||
- 新增YooAssets.IsInitialized字段。
|
||||
- 新增YooAssets初始化参数。
|
||||
|
||||
````c#
|
||||
/// <summary>
|
||||
/// 下载文件校验等级
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel = EVerifyLevel.High;
|
||||
````
|
||||
|
||||
- 新增YooAssets获取资源完成路径的方法。
|
||||
|
||||
````c#
|
||||
/// <summary>
|
||||
/// 获取资源路径
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <returns>如果location地址无效,则返回空字符串</returns>
|
||||
public static string GetAssetPath(string location);
|
||||
````
|
||||
|
||||
- 新增YooAssets初始化参数。
|
||||
|
||||
```c#
|
||||
/// <summary>
|
||||
/// 自动释放游戏对象所属资源句柄
|
||||
/// 说明:通过资源句柄实例化的游戏对象在销毁之后,会自动释放所属资源句柄。
|
||||
/// </summary>
|
||||
public bool AutoReleaseGameObjectHandle = false;
|
||||
```
|
||||
|
||||
## [1.0.10] - 2022-05-22
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了资源收集配置存在多个的时候,导致后续无法打开窗口的问题。
|
||||
- 修复了在编辑器模拟模式下加载精灵图片失败的问题。
|
||||
- 修复了在Unity2019版本无法识别配置文件的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 资源构建增加内置资源文件(首包资源文件)拷贝的选项。
|
||||
- 补丁下载器增加暂停方法和恢复方法。
|
||||
- 在资源收集界面,对Collector的增加和删除支持撤销和恢复操作。
|
||||
|
||||
## [1.0.9] - 2022-05-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了YooAssets.GetAssetInfos(string Tag)方法返回了无关的资源信息的问题。
|
||||
|
||||
### Changed
|
||||
|
||||
- 编辑器下的模拟运行模式,不再依赖配置里的构建版本。
|
||||
- 更新资源清单结构,资源对象类增加分类标签。
|
||||
- 优化了资源工具相关配置文件的加载方式和途径,这些配置文件可以放置在任何目录下。
|
||||
- 优化了Location无效后的错误报告方式。
|
||||
- 优化了资源包的构建参数,现在始终开启DisableLoadAssetByFileName,帮助减小运行时的内存。
|
||||
- YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
|
||||
|
||||
### Added
|
||||
|
||||
- 新增YooAssets.IsNeedDownloadFromRemote()方法。
|
||||
|
||||
````c#
|
||||
public static bool IsNeedDownloadFromRemote(string location);
|
||||
````
|
||||
|
||||
- 新增获取所有子资源对象的方法。
|
||||
|
||||
````c#
|
||||
class SubAssetsOperationHandle
|
||||
{
|
||||
public TObject[] GetSubAssetObjects<TObject>();
|
||||
}
|
||||
````
|
||||
|
||||
### Removed
|
||||
|
||||
- YooAssets.GetBundleInfo()方法已经移除。
|
||||
|
||||
## [1.0.8] - 2022-05-08
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
||||
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
||||
if (parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
|
||||
else if(parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
|
||||
}
|
||||
|
||||
@@ -54,9 +54,7 @@ namespace YooAsset.Editor
|
||||
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
||||
|
||||
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
}
|
||||
|
||||
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
{
|
||||
@@ -71,17 +69,13 @@ namespace YooAsset.Editor
|
||||
|
||||
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||
if (Parameters.AppendHash)
|
||||
opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name
|
||||
if (Parameters.DisableWriteTypeTree)
|
||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||
if (Parameters.IgnoreTypeTreeChanges)
|
||||
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
||||
if (Parameters.DisableLoadAssetByFileName)
|
||||
{
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||
}
|
||||
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||
|
||||
return opt;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace YooAsset.Editor
|
||||
public EBuildMode BuildMode = EBuildMode.ForceRebuild;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源标签
|
||||
/// 内置资源标签(首包资源标签)
|
||||
/// </summary>
|
||||
public string BuildTags = string.Empty;
|
||||
|
||||
|
||||
@@ -24,22 +24,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
// 加载配置文件
|
||||
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleBuilderSetting)}.asset";
|
||||
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(settingFilePath);
|
||||
if (_setting == null)
|
||||
{
|
||||
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {settingFilePath}");
|
||||
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
|
||||
EditorTools.CreateFileDirectory(settingFilePath);
|
||||
AssetDatabase.CreateAsset(Setting, settingFilePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
|
||||
}
|
||||
_setting = EditorHelper.LoadSettingData<AssetBundleBuilderSetting>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,28 +25,24 @@ namespace YooAsset.Editor
|
||||
private TextField _buildOutputField;
|
||||
private IntegerField _buildVersionField;
|
||||
private EnumField _buildModeField;
|
||||
private TextField _buildTagsField;
|
||||
private TextField _buildinTagsField;
|
||||
private PopupField<string> _encryptionField;
|
||||
private EnumField _compressionField;
|
||||
private Toggle _appendExtensionToggle;
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
try
|
||||
{
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
||||
@@ -78,11 +74,11 @@ namespace YooAsset.Editor
|
||||
});
|
||||
|
||||
// 内置资源标签
|
||||
_buildTagsField = root.Q<TextField>("BuildinTags");
|
||||
_buildTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||
_buildTagsField.RegisterValueChangedCallback(evt =>
|
||||
_buildinTagsField = root.Q<TextField>("BuildinTags");
|
||||
_buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||
_buildinTagsField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsField.value;
|
||||
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
|
||||
});
|
||||
|
||||
// 加密方法
|
||||
@@ -111,7 +107,7 @@ namespace YooAsset.Editor
|
||||
_compressionField = root.Q<EnumField>("Compression");
|
||||
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.style.width = 300;
|
||||
_compressionField.style.width = 300;
|
||||
_compressionField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||
@@ -143,8 +139,9 @@ namespace YooAsset.Editor
|
||||
|
||||
private void RefreshWindow()
|
||||
{
|
||||
bool enableElement = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
|
||||
_buildTagsField.SetEnabled(enableElement);
|
||||
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||
bool enableElement = buildMode == EBuildMode.ForceRebuild;
|
||||
_buildinTagsField.SetEnabled(enableElement);
|
||||
_encryptionField.SetEnabled(enableElement);
|
||||
_compressionField.SetEnabled(enableElement);
|
||||
_appendExtensionToggle.SetEnabled(enableElement);
|
||||
@@ -168,21 +165,28 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private void ExecuteBuild()
|
||||
{
|
||||
var buildMode = (EBuildMode)_buildModeField.value;
|
||||
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.BuildTarget = _buildTarget;
|
||||
buildParameters.BuildMode = (EBuildMode)_buildModeField.value;
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.BuildVersion = _buildVersionField.value;
|
||||
buildParameters.BuildinTags = _buildTagsField.value;
|
||||
buildParameters.BuildinTags = _buildinTagsField.value;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
|
||||
buildParameters.CopyBuildinTagFiles = buildMode == EBuildMode.ForceRebuild;
|
||||
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
|
||||
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
builder.Run(buildParameters);
|
||||
bool succeed = builder.Run(buildParameters);
|
||||
if (succeed)
|
||||
{
|
||||
EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加密类相关
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
|
||||
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
|
||||
buildParameters.BuildVersion = 999;
|
||||
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
private string _mainBundleName;
|
||||
private string _shareBundleName;
|
||||
private bool _isAddAssetTags = false;
|
||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
@@ -37,10 +38,15 @@ namespace YooAsset.Editor
|
||||
public bool IsShaderAsset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签列表
|
||||
/// 资源的分类标签
|
||||
/// </summary>
|
||||
public readonly List<string> AssetTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 资源包的分类标签
|
||||
/// </summary>
|
||||
public readonly List<string> BundleTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的所有资源
|
||||
/// 注意:包括零依赖资源和冗余资源(资源包名无效)
|
||||
@@ -62,9 +68,9 @@ namespace YooAsset.Editor
|
||||
else
|
||||
IsShaderAsset = false;
|
||||
}
|
||||
public BuildAssetInfo(ECollectorType collectorType, string assetPath)
|
||||
public BuildAssetInfo(string assetPath)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
CollectorType = ECollectorType.None;
|
||||
Address = string.Empty;
|
||||
AssetPath = assetPath;
|
||||
IsRawAsset = false;
|
||||
@@ -89,10 +95,15 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加资源分类标签
|
||||
/// 添加资源的分类标签
|
||||
/// 说明:原始定义的资源分类标签
|
||||
/// </summary>
|
||||
public void AddAssetTags(List<string> tags)
|
||||
{
|
||||
if (_isAddAssetTags)
|
||||
throw new Exception("Should never get here !");
|
||||
_isAddAssetTags = true;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (AssetTags.Contains(tag) == false)
|
||||
@@ -101,6 +112,21 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加资源包的分类标签
|
||||
/// 说明:传染算法统计到的分类标签
|
||||
/// </summary>
|
||||
public void AddBundleTags(List<string> tags)
|
||||
{
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (BundleTags.Contains(tag) == false)
|
||||
{
|
||||
BundleTags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名是否存在
|
||||
@@ -159,11 +185,9 @@ namespace YooAsset.Editor
|
||||
|
||||
if (_referenceBundleNames.Count > 1)
|
||||
{
|
||||
var bundleNameList = _referenceBundleNames.ToList();
|
||||
bundleNameList.Sort();
|
||||
string combineName = string.Join("|", bundleNameList);
|
||||
var combineNameHash = HashUtility.StringSHA1(combineName);
|
||||
var shareBundleName = $"share_{combineNameHash}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||
IPackRule packRule = PackDirectory.StaticPackRule;
|
||||
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
|
||||
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源标签列表
|
||||
/// 获取资源包的分类标签列表
|
||||
/// </summary>
|
||||
public string[] GetAssetTags()
|
||||
public string[] GetBundleTags()
|
||||
{
|
||||
List<string> result = new List<string>(BuildinAssets.Count);
|
||||
foreach (var assetInfo in BuildinAssets)
|
||||
{
|
||||
foreach (var assetTag in assetInfo.AssetTags)
|
||||
foreach (var assetTag in assetInfo.BundleTags)
|
||||
{
|
||||
if (result.Contains(assetTag) == false)
|
||||
result.Add(assetTag);
|
||||
|
||||
@@ -55,13 +55,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取AssetBundle内包含的标记列表
|
||||
/// 获取资源包的分类标签列表
|
||||
/// </summary>
|
||||
public string[] GetAssetTags(string bundleName)
|
||||
public string[] GetBundleTags(string bundleName)
|
||||
{
|
||||
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
return bundleInfo.GetAssetTags();
|
||||
return bundleInfo.GetBundleTags();
|
||||
}
|
||||
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
|
||||
// 1. 检测配置合法性
|
||||
AssetBundleCollectorSettingData.Setting.CheckConfigError();
|
||||
|
||||
// 2. 获取所有主动收集的资源
|
||||
// 2. 获取所有收集器收集的资源
|
||||
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
|
||||
|
||||
// 3. 剔除未被引用的依赖资源
|
||||
@@ -36,13 +36,15 @@ namespace YooAsset.Editor
|
||||
allCollectAssets.Remove(removeValue);
|
||||
}
|
||||
|
||||
// 4. 录入主动收集的资源
|
||||
// 4. 录入所有收集器收集的资源
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
|
||||
{
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
|
||||
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
|
||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -58,13 +60,13 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (buildAssetDic.ContainsKey(dependAssetPath))
|
||||
{
|
||||
buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags);
|
||||
buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
|
||||
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
|
||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
||||
}
|
||||
@@ -92,7 +94,7 @@ namespace YooAsset.Editor
|
||||
pair.Value.CalculateFullBundleName();
|
||||
}
|
||||
|
||||
// 8. 移除未参与构建的资源
|
||||
// 8. 移除不参与构建的资源
|
||||
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
|
||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
||||
public int BuildVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的标记列表
|
||||
/// 内置资源标签集合(首包资源标签)
|
||||
/// 注意:分号为分隔符
|
||||
/// </summary>
|
||||
public string BuildinTags;
|
||||
@@ -46,17 +46,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启用自动分包机制
|
||||
/// 说明:自动分包机制可以实现资源零冗余
|
||||
/// </summary>
|
||||
public bool EnableAutoCollect = true;
|
||||
|
||||
/// <summary>
|
||||
/// 追加文件扩展名
|
||||
/// </summary>
|
||||
public bool AppendFileExtension = false;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源文件到StreamingAssets目录(首包资源文件)
|
||||
/// </summary>
|
||||
public bool CopyBuildinTagFiles = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加密类
|
||||
@@ -68,11 +67,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名附加上哈希值
|
||||
/// </summary>
|
||||
public bool AppendHash = false;
|
||||
|
||||
/// <summary>
|
||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||
/// </summary>
|
||||
@@ -83,14 +77,9 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 禁用名称查找资源(可以降内存并提高加载效率)
|
||||
/// </summary>
|
||||
public bool DisableLoadAssetByFileName = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置标记列表
|
||||
/// 获取内置资源标签列表(首包资源标签)
|
||||
/// </summary>
|
||||
public List<string> GetBuildinTags()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,11 @@ namespace YooAsset.Editor
|
||||
/// 说明:Meta文件记录的GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源的分类标签
|
||||
/// </summary>
|
||||
public string[] AssetTags;
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源包名称
|
||||
|
||||
@@ -48,16 +48,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool EnableAddressable;
|
||||
|
||||
/// <summary>
|
||||
/// 启用自动分包机制
|
||||
/// </summary>
|
||||
public bool EnableAutoCollect;
|
||||
|
||||
/// <summary>
|
||||
/// 追加文件扩展名
|
||||
/// </summary>
|
||||
public bool AppendFileExtension;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源文件
|
||||
/// </summary>
|
||||
public bool CopyBuildinTagFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集着色器
|
||||
/// </summary>
|
||||
@@ -75,10 +75,8 @@ namespace YooAsset.Editor
|
||||
|
||||
// 构建参数
|
||||
public ECompressOption CompressOption;
|
||||
public bool AppendHash;
|
||||
public bool DisableWriteTypeTree;
|
||||
public bool IgnoreTypeTreeChanges;
|
||||
public bool DisableLoadAssetByFileName;
|
||||
|
||||
// 构建结果
|
||||
public int AssetFileTotalCount;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
// 注意:我们只有在强制重建的时候才会拷贝
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
if (buildParameters.Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
if (buildParameters.Parameters.CopyBuildinTagFiles)
|
||||
{
|
||||
// 清空流目录
|
||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||
|
||||
@@ -58,9 +58,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
List<PatchBundle> result = new List<PatchBundle>(1000);
|
||||
|
||||
// 内置标记列表
|
||||
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
@@ -70,7 +68,7 @@ namespace YooAsset.Editor
|
||||
string hash = GetFileHash(filePath, standardBuild);
|
||||
string crc32 = GetFileCRC(filePath, standardBuild);
|
||||
long size = GetFileSize(filePath, standardBuild);
|
||||
string[] tags = buildMapContext.GetAssetTags(bundleName);
|
||||
string[] tags = buildMapContext.GetBundleTags(bundleName);
|
||||
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
||||
bool isBuildin = IsBuildinBundle(tags, buildinTags);
|
||||
bool isRawFile = bundleInfo.IsRawFile;
|
||||
@@ -90,7 +88,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private bool IsBuildinBundle(string[] bundleTags, List<string> buildinTags)
|
||||
{
|
||||
// 注意:没有任何标记的Bundle文件默认为内置文件
|
||||
// 注意:没有任何分类标签的Bundle文件默认为内置文件
|
||||
if (bundleTags.Length == 0)
|
||||
return true;
|
||||
|
||||
@@ -141,6 +139,7 @@ namespace YooAsset.Editor
|
||||
else
|
||||
patchAsset.Address = string.Empty;
|
||||
patchAsset.AssetPath = assetInfo.AssetPath;
|
||||
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
|
||||
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
||||
result.Add(patchAsset);
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
|
||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
|
||||
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
||||
buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles;
|
||||
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
||||
@@ -50,10 +50,8 @@ namespace YooAsset.Editor
|
||||
|
||||
// 构建参数
|
||||
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
|
||||
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
|
||||
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
|
||||
|
||||
// 构建结果
|
||||
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
|
||||
@@ -75,6 +73,7 @@ namespace YooAsset.Editor
|
||||
ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
|
||||
reportAssetInfo.Address = patchAsset.Address;
|
||||
reportAssetInfo.AssetPath = patchAsset.AssetPath;
|
||||
reportAssetInfo.AssetTags = patchAsset.AssetTags;
|
||||
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
|
||||
reportAssetInfo.MainBundleName = mainBundle.BundleName;
|
||||
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;
|
||||
|
||||
@@ -87,10 +87,10 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleCollectorGroup group)
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
@@ -117,7 +117,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
||||
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -132,7 +132,7 @@ namespace YooAsset.Editor
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
||||
var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
@@ -162,13 +162,19 @@ namespace YooAsset.Editor
|
||||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||
private CollectAssetInfo CreateCollectAssetInfo(EBuildMode buildMode, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||
{
|
||||
string address = GetAddress(group, assetPath);
|
||||
string bundleName = GetBundleName(group, assetPath);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<string>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||
|
||||
return collectAssetInfo;
|
||||
}
|
||||
private bool IsValidateAsset(string assetPath)
|
||||
@@ -242,10 +248,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private List<string> GetAllDependencies(string mainAssetPath)
|
||||
{
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if(AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
||||
return new List<string>();
|
||||
|
||||
List<string> result = new List<string>();
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
foreach (string assetPath in depends)
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string AssetTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 分组激活规则
|
||||
/// </summary>
|
||||
public string ActiveRuleName = nameof(EnableGroup);
|
||||
|
||||
/// <summary>
|
||||
/// 分组的收集器列表
|
||||
/// </summary>
|
||||
@@ -36,6 +41,9 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
@@ -45,14 +53,21 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取打包收集的资源文件
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets()
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
{
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(this);
|
||||
var temper = collector.GetAllCollectAssets(buildMode, this);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
|
||||
@@ -8,8 +8,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorSetting : ScriptableObject
|
||||
{
|
||||
public static EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用可寻址资源定位
|
||||
/// </summary>
|
||||
@@ -47,14 +45,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets();
|
||||
var temper = group.GetAllCollectAssets(buildMode);
|
||||
foreach (var assetInfo in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorSettingData
|
||||
{
|
||||
private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>();
|
||||
private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>();
|
||||
|
||||
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
||||
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
||||
|
||||
@@ -35,6 +38,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetActiveRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadSettingData();
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
names.Add(pair.Key);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static List<string> GetAddressRuleNames()
|
||||
{
|
||||
if (_setting == null)
|
||||
@@ -71,6 +86,15 @@ namespace YooAsset.Editor
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cacheActiveRuleTypes)
|
||||
{
|
||||
if (pair.Key == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
foreach (var pair in _cacheAddressRuleTypes)
|
||||
@@ -105,22 +129,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
// 加载配置文件
|
||||
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleCollectorSetting)}.asset";
|
||||
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>(settingFilePath);
|
||||
if (_setting == null)
|
||||
{
|
||||
Debug.LogWarning($"Create new {nameof(AssetBundleCollectorSetting)}.asset : {settingFilePath}");
|
||||
_setting = ScriptableObject.CreateInstance<AssetBundleCollectorSetting>();
|
||||
EditorTools.CreateFileDirectory(settingFilePath);
|
||||
AssetDatabase.CreateAsset(Setting, settingFilePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Load {nameof(AssetBundleCollectorSetting)}.asset ok");
|
||||
}
|
||||
_setting = EditorHelper.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
|
||||
// IPackRule
|
||||
{
|
||||
@@ -197,6 +206,29 @@ namespace YooAsset.Editor
|
||||
_cacheAddressRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
|
||||
// IActiveRule
|
||||
{
|
||||
// 清空缓存集合
|
||||
_cacheActiveRuleTypes.Clear();
|
||||
_cacheActiveRuleInstance.Clear();
|
||||
|
||||
// 获取所有类型
|
||||
List<Type> types = new List<Type>(100)
|
||||
{
|
||||
typeof(EnableGroup),
|
||||
typeof(DisableGroup),
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
Type type = types[i];
|
||||
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
|
||||
_cacheActiveRuleTypes.Add(type.Name, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -225,6 +257,23 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 实例类相关
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IActiveRule)Activator.CreateInstance(type);
|
||||
_cacheActiveRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
||||
|
||||
@@ -19,11 +19,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
private List<string> _collectorTypeList;
|
||||
private List<string> _activeRuleList;
|
||||
private List<string> _addressRuleList;
|
||||
private List<string> _packRuleList;
|
||||
private List<string> _filterRuleList;
|
||||
private ListView _groupListView;
|
||||
private ScrollView _collectorScrollView;
|
||||
private PopupField<string> _activeRulePopupField;
|
||||
private Toggle _enableAddressableToogle;
|
||||
private Toggle _autoCollectShaderToogle;
|
||||
private TextField _shaderBundleNameTxt;
|
||||
@@ -31,37 +33,36 @@ namespace YooAsset.Editor
|
||||
private TextField _groupDescTxt;
|
||||
private TextField _groupAssetTagsTxt;
|
||||
private VisualElement _groupContainer;
|
||||
private string _lastModifyGroup = string.Empty;
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
Undo.undoRedoPerformed -= RefreshWindow;
|
||||
Undo.undoRedoPerformed += RefreshWindow;
|
||||
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
_collectorTypeList = new List<string>()
|
||||
{
|
||||
$"{nameof(ECollectorType.MainAssetCollector)}",
|
||||
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
||||
$"{nameof(ECollectorType.DependAssetCollector)}"
|
||||
};
|
||||
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleCollector/{nameof(AssetBundleCollectorWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
try
|
||||
{
|
||||
_collectorTypeList = new List<string>()
|
||||
{
|
||||
$"{nameof(ECollectorType.MainAssetCollector)}",
|
||||
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
||||
$"{nameof(ECollectorType.DependAssetCollector)}"
|
||||
};
|
||||
_activeRuleList = AssetBundleCollectorSettingData.GetActiveRuleNames();
|
||||
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 导入导出按钮
|
||||
var exportBtn = root.Q<Button>("ExportButton");
|
||||
exportBtn.clicked += ExportBtn_clicked;
|
||||
@@ -73,6 +74,7 @@ namespace YooAsset.Editor
|
||||
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
||||
RefreshWindow();
|
||||
});
|
||||
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
||||
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
||||
@@ -156,6 +158,25 @@ namespace YooAsset.Editor
|
||||
addBtn.clicked += AddCollectorBtn_clicked;
|
||||
}
|
||||
|
||||
// 分组激活规则
|
||||
var activeRuleContainer = root.Q("ActiveRuleContainer");
|
||||
{
|
||||
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
|
||||
_activeRulePopupField.name = "ActiveRuleMaskField";
|
||||
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
activeRuleContainer.Add(_activeRulePopupField);
|
||||
_activeRulePopupField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||
if (selectGroup != null)
|
||||
{
|
||||
selectGroup.ActiveRuleName = evt.newValue;
|
||||
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
|
||||
FillGroupViewData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新窗体
|
||||
RefreshWindow();
|
||||
}
|
||||
@@ -166,6 +187,9 @@ namespace YooAsset.Editor
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
// 注意:清空所有撤销操作
|
||||
Undo.ClearAll();
|
||||
|
||||
if (AssetBundleCollectorSettingData.IsDirty)
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
@@ -205,6 +229,16 @@ namespace YooAsset.Editor
|
||||
_groupListView.ClearSelection();
|
||||
_groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
|
||||
_groupListView.Rebuild();
|
||||
|
||||
for (int index = 0; index < AssetBundleCollectorSettingData.Setting.Groups.Count; index++)
|
||||
{
|
||||
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
|
||||
if (group.GroupName == _lastModifyGroup)
|
||||
{
|
||||
_groupListView.selectedIndex = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private VisualElement MakeGroupListViewItem()
|
||||
{
|
||||
@@ -231,6 +265,11 @@ namespace YooAsset.Editor
|
||||
textField1.text = group.GroupName;
|
||||
else
|
||||
textField1.text = $"{group.GroupName} ({group.GroupDesc})";
|
||||
|
||||
// 激活状态
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(group.ActiveRuleName);
|
||||
bool isActive = activeRule.IsActiveGroup();
|
||||
textField1.SetEnabled(isActive);
|
||||
}
|
||||
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
@@ -238,7 +277,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void AddGroupBtn_clicked()
|
||||
{
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset AddGroup");
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddGroup");
|
||||
AssetBundleCollectorSettingData.CreateGroup("Default Group");
|
||||
FillGroupViewData();
|
||||
}
|
||||
@@ -248,8 +287,7 @@ namespace YooAsset.Editor
|
||||
if (selectGroup == null)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset RemoveGroup");
|
||||
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveGroup");
|
||||
AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
|
||||
FillGroupViewData();
|
||||
}
|
||||
@@ -264,7 +302,9 @@ namespace YooAsset.Editor
|
||||
return;
|
||||
}
|
||||
|
||||
_lastModifyGroup = selectGroup.GroupName;
|
||||
_groupContainer.visible = true;
|
||||
_activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
|
||||
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
||||
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
||||
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
||||
@@ -512,7 +552,7 @@ namespace YooAsset.Editor
|
||||
|
||||
try
|
||||
{
|
||||
collectAssetInfos = collector.GetAllCollectAssets(group);
|
||||
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
@@ -552,6 +592,7 @@ namespace YooAsset.Editor
|
||||
if (selectGroup == null)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddCollector");
|
||||
AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
|
||||
FillCollectorViewData();
|
||||
}
|
||||
@@ -562,6 +603,8 @@ namespace YooAsset.Editor
|
||||
return;
|
||||
if (selectCollector == null)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveCollector");
|
||||
AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
|
||||
FillCollectorViewData();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 启用分组
|
||||
/// </summary>
|
||||
public class EnableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用分组
|
||||
/// </summary>
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cfd65b3b7663b247b2df16077f4ef17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -44,10 +44,19 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
if (AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath) == typeof(Sprite))
|
||||
return true;
|
||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||
if(mainAssetType == typeof(Texture2D))
|
||||
{
|
||||
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
|
||||
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
public static PackDirectory StaticPackRule = new PackDirectory();
|
||||
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
return Path.GetDirectoryName(data.AssetPath);
|
||||
|
||||
14
Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs
Normal file
14
Assets/YooAsset/Editor/AssetBundleCollector/IActiveRule.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源分组激活规则接口
|
||||
/// </summary>
|
||||
public interface IActiveRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否激活分组
|
||||
/// </summary>
|
||||
bool IsActiveGroup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aed5a1a6733b7d44ca4f6149ed5a2bb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,140 +1,205 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEditor.Networking.PlayerConnection;
|
||||
using UnityEngine.Networking.PlayerConnection;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleDebuggerWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
||||
public static void ShowExample()
|
||||
{
|
||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(800, 600);
|
||||
}
|
||||
public class AssetBundleDebuggerWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
||||
public static void ShowExample()
|
||||
{
|
||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 视图模式
|
||||
/// </summary>
|
||||
private enum EViewMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存视图
|
||||
/// </summary>
|
||||
MemoryView,
|
||||
/// <summary>
|
||||
/// 视图模式
|
||||
/// </summary>
|
||||
private enum EViewMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存视图
|
||||
/// </summary>
|
||||
MemoryView,
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象视图
|
||||
/// </summary>
|
||||
AssetView,
|
||||
/// <summary>
|
||||
/// 资源对象视图
|
||||
/// </summary>
|
||||
AssetView,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包视图
|
||||
/// </summary>
|
||||
BundleView,
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private AssetListDebuggerViewer _assetListViewer;
|
||||
private BundleListDebuggerViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private readonly DebugReport _debugReport = new DebugReport();
|
||||
private string _searchKeyWord;
|
||||
/// <summary>
|
||||
/// 资源包视图
|
||||
/// </summary>
|
||||
BundleView,
|
||||
}
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
VisualElement root = rootVisualElement;
|
||||
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
visualAsset.CloneTree(root);
|
||||
private Label _playerName;
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private DebuggerAssetListViewer _assetListViewer;
|
||||
private DebuggerBundleListViewer _bundleListViewer;
|
||||
|
||||
// 采样按钮
|
||||
var sampleBtn = root.Q<Button>("SampleButton");
|
||||
sampleBtn.clicked += SampleBtn_onClick;
|
||||
private EViewMode _viewMode;
|
||||
private DebugReport _debugReport;
|
||||
private string _searchKeyWord;
|
||||
|
||||
// 视口模式菜单
|
||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
public void CreateGUI()
|
||||
{
|
||||
try
|
||||
{
|
||||
VisualElement root = rootVisualElement;
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new AssetListDebuggerViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new BundleListDebuggerViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.AssetView;
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
_assetListViewer.AttachParent(root);
|
||||
}
|
||||
private void SampleBtn_onClick()
|
||||
{
|
||||
YooAssets.GetDebugReport(_debugReport);
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
}
|
||||
private void ViewModeMenuAction1(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode != EViewMode.AssetView)
|
||||
{
|
||||
_viewMode = EViewMode.AssetView;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
_assetListViewer.AttachParent(root);
|
||||
_bundleListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction2(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode != EViewMode.BundleView)
|
||||
{
|
||||
_viewMode = EViewMode.BundleView;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = EViewMode.BundleView.ToString();
|
||||
_assetListViewer.DetachParent();
|
||||
_bundleListViewer.AttachParent(root);
|
||||
}
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun1(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode == EViewMode.AssetView)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun2(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode == EViewMode.BundleView)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
}
|
||||
// 采样按钮
|
||||
var sampleBtn = root.Q<Button>("SampleButton");
|
||||
sampleBtn.clicked += SampleBtn_onClick;
|
||||
|
||||
// 用户列表菜单
|
||||
_playerName = root.Q<Label>("PlayerName");
|
||||
_playerName.text = "Editor player";
|
||||
|
||||
// 视口模式菜单
|
||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction, ViewModeMenuFun, EViewMode.AssetView);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction, ViewModeMenuFun, EViewMode.BundleView);
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new DebuggerAssetListViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new DebuggerBundleListViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.AssetView;
|
||||
_assetListViewer.AttachParent(root);
|
||||
|
||||
// 远程调试
|
||||
EditorConnection.instance.Initialize();
|
||||
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
|
||||
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
|
||||
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
|
||||
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
// 远程调试
|
||||
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
|
||||
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
|
||||
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
|
||||
_playerSessions.Clear();
|
||||
}
|
||||
|
||||
private void OnHandleConnectionEvent(int playerId)
|
||||
{
|
||||
Debug.Log($"Game player connection : {playerId}");
|
||||
_playerName.text = $"Connected player : {playerId}";
|
||||
}
|
||||
private void OnHandleDisconnectionEvent(int playerId)
|
||||
{
|
||||
Debug.Log($"Game player disconnection : {playerId}");
|
||||
_playerName.text = $"Disconneced player : {playerId}";
|
||||
RemovePlayerSession(playerId);
|
||||
}
|
||||
private void OnHandlePlayerMessage(MessageEventArgs args)
|
||||
{
|
||||
var debugReport = DebugReport.Deserialize(args.data);
|
||||
OnHandleDebugReport(args.playerId, debugReport);
|
||||
}
|
||||
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
|
||||
{
|
||||
var playerSession = GetOrCreatePlayerSession(playerId);
|
||||
playerSession.AddDebugReport(debugReport);
|
||||
|
||||
_debugReport = debugReport;
|
||||
_assetListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
}
|
||||
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
|
||||
{
|
||||
if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session))
|
||||
{
|
||||
return session;
|
||||
}
|
||||
else
|
||||
{
|
||||
RemotePlayerSession newSession = new RemotePlayerSession(playerId);
|
||||
_playerSessions.Add(playerId, newSession);
|
||||
return newSession;
|
||||
}
|
||||
}
|
||||
private void RemovePlayerSession(int playerId)
|
||||
{
|
||||
if (_playerSessions.ContainsKey(playerId))
|
||||
_playerSessions.Remove(playerId);
|
||||
}
|
||||
|
||||
private void SampleBtn_onClick()
|
||||
{
|
||||
// 发送采集数据的命令
|
||||
RemoteCommand command = new RemoteCommand();
|
||||
command.CommandType = (int)ERemoteCommand.SampleOnce;
|
||||
command.CommandParam = string.Empty;
|
||||
byte[] data = RemoteCommand.Serialize(command);
|
||||
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
|
||||
RemoteDebuggerInRuntime.EditorRequestDebugReport();
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
if (_debugReport != null)
|
||||
{
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction(DropdownMenuAction action)
|
||||
{
|
||||
var viewMode = (EViewMode)action.userData;
|
||||
if (_viewMode != viewMode)
|
||||
{
|
||||
_viewMode = viewMode;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = viewMode.ToString();
|
||||
_assetListViewer.AttachParent(root);
|
||||
_bundleListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun(DropdownMenuAction action)
|
||||
{
|
||||
var viewMode = (EViewMode)action.userData;
|
||||
if (_viewMode == viewMode)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex;">
|
||||
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: middle-left; padding-left: 5px;" />
|
||||
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class RemotePlayerSession
|
||||
{
|
||||
private readonly List<DebugReport> _reportList = new List<DebugReport>();
|
||||
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public int PlayerId { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 保存的报告最大数量
|
||||
/// </summary>
|
||||
public int MaxReportCount { private set; get; }
|
||||
|
||||
|
||||
public RemotePlayerSession(int playerId, int maxReportCount = 1000)
|
||||
{
|
||||
PlayerId = playerId;
|
||||
MaxReportCount = maxReportCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个调试报告
|
||||
/// </summary>
|
||||
public void AddDebugReport(DebugReport report)
|
||||
{
|
||||
if (report == null)
|
||||
Debug.LogWarning("Invalid debug report data !");
|
||||
|
||||
if (_reportList.Count >= MaxReportCount)
|
||||
_reportList.RemoveAt(0);
|
||||
_reportList.Add(report);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最近一次的报告
|
||||
/// </summary>
|
||||
public DebugReport GetLatestReport()
|
||||
{
|
||||
if (_reportList.Count == 0)
|
||||
return null;
|
||||
return _reportList[_reportList.Count - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89b4ea90b9f7e474d9e80077656ef6c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class AssetListDebuggerViewer
|
||||
internal class DebuggerAssetListViewer
|
||||
{
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
@@ -23,15 +23,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
// 加载布局文件
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerAssetListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -175,7 +171,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// Status
|
||||
StyleColor textColor;
|
||||
if (providerInfo.Status == ProviderBase.EStatus.Fail)
|
||||
if (providerInfo.Status == (int)ProviderBase.EStatus.Fail)
|
||||
textColor = new StyleColor(Color.yellow);
|
||||
else
|
||||
textColor = label1.style.color;
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class BundleListDebuggerViewer
|
||||
internal class DebuggerBundleListViewer
|
||||
{
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
@@ -24,14 +24,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerBundleListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -39,12 +35,12 @@ namespace YooAsset.Editor
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeAssetListViewItem;
|
||||
_bundleListView.bindItem = BindAssetListViewItem;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
#else
|
||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||
#endif
|
||||
|
||||
// 使用列表
|
||||
_usingListView = _root.Q<ListView>("BottomListView");
|
||||
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||
@@ -151,7 +147,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// Status
|
||||
StyleColor textColor;
|
||||
if (bundleInfo.Status == AssetBundleLoaderBase.EStatus.Failed)
|
||||
if (bundleInfo.Status == (int)AssetBundleLoaderBase.EStatus.Failed)
|
||||
textColor = new StyleColor(Color.yellow);
|
||||
else
|
||||
textColor = label1.style.color;
|
||||
@@ -1,4 +1,5 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
@@ -37,9 +38,9 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private SummaryReporterViewer _summaryViewer;
|
||||
private AssetListReporterViewer _assetListViewer;
|
||||
private BundleListReporterViewer _bundleListViewer;
|
||||
private ReporterSummaryViewer _summaryViewer;
|
||||
private ReporterAssetListViewer _assetListViewer;
|
||||
private ReporterBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private BuildReport _buildReport;
|
||||
@@ -49,49 +50,52 @@ namespace YooAsset.Editor
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
try
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleReporterWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 导入按钮
|
||||
var importBtn = root.Q<Button>("ImportButton");
|
||||
importBtn.clicked += ImportBtn_onClick;
|
||||
|
||||
// 视图模式菜单
|
||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
|
||||
// 加载视图
|
||||
_summaryViewer = new ReporterSummaryViewer();
|
||||
_summaryViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new ReporterAssetListViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new ReporterBundleListViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.Summary;
|
||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||
_summaryViewer.AttachParent(root);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 导入按钮
|
||||
var importBtn = root.Q<Button>("ImportButton");
|
||||
importBtn.clicked += ImportBtn_onClick;
|
||||
|
||||
// 视图模式菜单
|
||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
|
||||
// 加载视图
|
||||
_summaryViewer = new SummaryReporterViewer();
|
||||
_summaryViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new AssetListReporterViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new BundleListReporterViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.Summary;
|
||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||
_summaryViewer.AttachParent(root);
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class AssetListReporterViewer
|
||||
internal class ReporterAssetListViewer
|
||||
{
|
||||
private enum ESortMode
|
||||
{
|
||||
@@ -38,48 +38,36 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterAssetListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 顶部按钮栏
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
// 顶部按钮栏
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
|
||||
// 资源列表
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
// 资源列表
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
#else
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
#endif
|
||||
|
||||
// 依赖列表
|
||||
_dependListView = _root.Q<ListView>("BottomListView");
|
||||
_dependListView.makeItem = MakeDependListViewItem;
|
||||
_dependListView.bindItem = BindDependListViewItem;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
// 依赖列表
|
||||
_dependListView = _root.Q<ListView>("BottomListView");
|
||||
_dependListView.makeItem = MakeDependListViewItem;
|
||||
_dependListView.bindItem = BindDependListViewItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class BundleListReporterViewer
|
||||
internal class ReporterBundleListViewer
|
||||
{
|
||||
private enum ESortMode
|
||||
{
|
||||
@@ -42,58 +42,46 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterBundleListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
_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;
|
||||
// 顶部按钮栏
|
||||
_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;
|
||||
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
|
||||
// 资源包列表
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeBundleListViewItem;
|
||||
_bundleListView.bindItem = BindBundleListViewItem;
|
||||
// 资源包列表
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeBundleListViewItem;
|
||||
_bundleListView.bindItem = BindBundleListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
|
||||
#else
|
||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||
#endif
|
||||
|
||||
// 包含列表
|
||||
_includeListView = _root.Q<ListView>("BottomListView");
|
||||
_includeListView.makeItem = MakeIncludeListViewItem;
|
||||
_includeListView.bindItem = BindIncludeListViewItem;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
// 包含列表
|
||||
_includeListView = _root.Q<ListView>("BottomListView");
|
||||
_includeListView.makeItem = MakeIncludeListViewItem;
|
||||
_includeListView.bindItem = BindIncludeListViewItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充页面数据
|
||||
/// </summary>
|
||||
public void FillViewData( BuildReport buildReport, string reprotFilePath, string searchKeyWord)
|
||||
public void FillViewData(BuildReport buildReport, string reprotFilePath, string searchKeyWord)
|
||||
{
|
||||
_buildReport = buildReport;
|
||||
_reportFilePath = reprotFilePath;
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class SummaryReporterViewer
|
||||
internal class ReporterSummaryViewer
|
||||
{
|
||||
private class ItemWrapper
|
||||
{
|
||||
@@ -37,14 +37,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetSourcePath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterSummaryViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(SummaryReporterViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -71,8 +67,8 @@ namespace YooAsset.Editor
|
||||
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
|
||||
|
||||
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
|
||||
_items.Add(new ItemWrapper("启用自动分包机制", $"{buildReport.Summary.EnableAutoCollect}"));
|
||||
_items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}"));
|
||||
_items.Add(new ItemWrapper("拷贝内置资源文件", $"{buildReport.Summary.CopyBuildinTagFiles}"));
|
||||
_items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}"));
|
||||
_items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}"));
|
||||
_items.Add(new ItemWrapper("加密服务类名称", $"{buildReport.Summary.EncryptionServicesClassName}"));
|
||||
@@ -80,10 +76,8 @@ namespace YooAsset.Editor
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("构建参数", string.Empty));
|
||||
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
|
||||
_items.Add(new ItemWrapper("AppendHash", $"{buildReport.Summary.AppendHash}"));
|
||||
_items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}"));
|
||||
_items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}"));
|
||||
_items.Add(new ItemWrapper("DisableLoadAssetByFileName", $"{buildReport.Summary.DisableLoadAssetByFileName}"));
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("构建结果", string.Empty));
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
#if UNITY_2019
|
||||
public static partial class UnityEngine_UIElements_ListView_Extension
|
||||
{
|
||||
@@ -20,4 +21,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
91
Assets/YooAsset/Editor/EditorHelper.cs
Normal file
91
Assets/YooAsset/Editor/EditorHelper.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EditorHelper
|
||||
{
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>();
|
||||
|
||||
static EditorHelper()
|
||||
{
|
||||
// 资源包收集
|
||||
_uxmlDic.Add(typeof(AssetBundleCollectorWindow), "355c4ac5cdebddc4c8362bed6f17a79e");
|
||||
|
||||
// 资源包构建
|
||||
_uxmlDic.Add(typeof(AssetBundleBuilderWindow), "28ba29adb4949284e8c48893218b0d9a");
|
||||
|
||||
// 资源包调试
|
||||
_uxmlDic.Add(typeof(AssetBundleDebuggerWindow), "790db12999afd334e8fb6ba70ef0a947");
|
||||
_uxmlDic.Add(typeof(DebuggerAssetListViewer), "31c6096c1cb29b4469096b7b4942a322");
|
||||
_uxmlDic.Add(typeof(DebuggerBundleListViewer), "932a25ffd05c13c47994d66e9d73bc37");
|
||||
|
||||
// 构建报告
|
||||
_uxmlDic.Add(typeof(AssetBundleReporterWindow), "9052b72c383e95043a0c7e7f369b1ad7");
|
||||
_uxmlDic.Add(typeof(ReporterSummaryViewer), "f8929271050855e42a1ccc6b14993a04");
|
||||
_uxmlDic.Add(typeof(ReporterAssetListViewer), "5f81bc15a55ee0a49a266f9d71e2372b");
|
||||
_uxmlDic.Add(typeof(ReporterBundleListViewer), "56d6dbe0d65ce334a8996beb19612989");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载窗口的布局文件
|
||||
/// </summary>
|
||||
public static UnityEngine.UIElements.VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class
|
||||
{
|
||||
var windowType = typeof(TWindow);
|
||||
if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID))
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID);
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
throw new System.Exception($"Invalid YooAsset uxml guid : {uxmlGUID}");
|
||||
var visualTreeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
|
||||
if (visualTreeAsset == null)
|
||||
throw new System.Exception($"Failed to load {windowType}.uxml");
|
||||
return visualTreeAsset;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception($"Invalid YooAsset window type : {windowType}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 加载相关的配置文件
|
||||
/// </summary>
|
||||
public static TSetting LoadSettingData<TSetting>() where TSetting : ScriptableObject
|
||||
{
|
||||
var settingType = typeof(TSetting);
|
||||
var guids = AssetDatabase.FindAssets($"t:{settingType.Name}");
|
||||
if (guids.Length == 0)
|
||||
{
|
||||
Debug.LogWarning($"Create new {settingType.Name}.asset");
|
||||
var setting = ScriptableObject.CreateInstance<TSetting>();
|
||||
string filePath = $"Assets/{settingType.Name}.asset";
|
||||
AssetDatabase.CreateAsset(setting, filePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (guids.Length != 1)
|
||||
{
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
Debug.LogWarning($"Found multiple file : {path}");
|
||||
}
|
||||
throw new System.Exception($"Found multiple {settingType.Name} files !");
|
||||
}
|
||||
|
||||
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
|
||||
return setting;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Editor/EditorHelper.cs.meta
Normal file
11
Assets/YooAsset/Editor/EditorHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2d701e695ac3fe4cbe25d43dde05944
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -462,9 +462,6 @@ namespace YooAsset.Editor
|
||||
#endregion
|
||||
|
||||
#region 路径
|
||||
private static string YooAssetSourcePath;
|
||||
private static string YooAssetSettingPath;
|
||||
|
||||
/// <summary>
|
||||
/// 获取规范的路径
|
||||
/// </summary>
|
||||
@@ -473,83 +470,6 @@ namespace YooAsset.Editor
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源框架源码路径
|
||||
/// </summary>
|
||||
public static string GetYooAssetSourcePath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(YooAssetSourcePath) == false)
|
||||
{
|
||||
if (Directory.Exists(YooAssetSourcePath))
|
||||
return YooAssetSourcePath;
|
||||
}
|
||||
|
||||
// 从Pakcages目录下搜索
|
||||
string packagesPath = "Packages/com.tuyoogame.yooasset/README.md";
|
||||
var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset));
|
||||
if (obj != null)
|
||||
{
|
||||
YooAssetSourcePath = "Packages/com.tuyoogame.yooasset/";
|
||||
return YooAssetSourcePath;
|
||||
}
|
||||
|
||||
// 从Assets目录下搜索
|
||||
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories);
|
||||
if (allDirectorys.Length == 0)
|
||||
{
|
||||
Debug.LogError("Not found YooAsset package !");
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string targetDirectory = string.Empty;
|
||||
foreach (var directory in allDirectorys)
|
||||
{
|
||||
string asmdefFilePath = $"{directory}/Editor/YooAsset.Editor.asmdef";
|
||||
if (File.Exists(asmdefFilePath))
|
||||
{
|
||||
targetDirectory = directory;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(targetDirectory))
|
||||
{
|
||||
Debug.LogError("Should never get here !");
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
YooAssetSourcePath = AbsolutePathToAssetPath(targetDirectory);
|
||||
return YooAssetSourcePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源框架配置路径
|
||||
/// </summary>
|
||||
public static string GetYooAssetSettingPath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(YooAssetSettingPath) == false)
|
||||
{
|
||||
if (Directory.Exists(YooAssetSettingPath))
|
||||
return YooAssetSettingPath;
|
||||
}
|
||||
|
||||
// 从Assets目录下搜索
|
||||
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAssetSetting", SearchOption.AllDirectories);
|
||||
if (allDirectorys.Length == 0)
|
||||
{
|
||||
YooAssetSettingPath = "Assets/YooAssetSetting";
|
||||
return YooAssetSettingPath;
|
||||
}
|
||||
|
||||
string targetDirectory = allDirectorys[0];
|
||||
if (allDirectorys.Length != 1)
|
||||
{
|
||||
Debug.LogError("Found multiple YooAssetSetting folder !");
|
||||
}
|
||||
|
||||
YooAssetSettingPath = AbsolutePathToAssetPath(targetDirectory);
|
||||
return YooAssetSettingPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目工程路径
|
||||
/// </summary>
|
||||
@@ -566,7 +486,7 @@ namespace YooAsset.Editor
|
||||
public static string AbsolutePathToAssetPath(string absolutePath)
|
||||
{
|
||||
string content = GetRegularPath(absolutePath);
|
||||
return Substring(content, "Assets", true);
|
||||
return Substring(content, "Assets/", true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -630,7 +550,6 @@ namespace YooAsset.Editor
|
||||
else
|
||||
return content.Substring(startIndex + key.Length);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -25,22 +25,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
// 加载配置文件
|
||||
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(ShaderVariantCollectorSetting)}.asset";
|
||||
_setting = AssetDatabase.LoadAssetAtPath<ShaderVariantCollectorSetting>(settingFilePath);
|
||||
if (_setting == null)
|
||||
{
|
||||
Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {settingFilePath}");
|
||||
_setting = ScriptableObject.CreateInstance<ShaderVariantCollectorSetting>();
|
||||
EditorTools.CreateFileDirectory(settingFilePath);
|
||||
AssetDatabase.CreateAsset(Setting, settingFilePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Load {nameof(ShaderVariantCollectorSetting)}.asset ok");
|
||||
}
|
||||
_setting = EditorHelper.LoadSettingData<ShaderVariantCollectorSetting>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -11,36 +10,31 @@ namespace YooAsset
|
||||
{
|
||||
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
|
||||
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
|
||||
private static readonly HashSet<AssetOperationHandle> _trackGameObjectHandles = new HashSet<AssetOperationHandle>();
|
||||
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
|
||||
|
||||
/// <summary>
|
||||
/// 在编辑器下模拟运行
|
||||
/// </summary>
|
||||
public static bool SimulationOnEditor { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的最大加载个数
|
||||
/// </summary>
|
||||
public static int AssetLoadingMaxNumber { private set; get; }
|
||||
private static bool _simulationOnEditor;
|
||||
private static int _loadingMaxNumber;
|
||||
|
||||
public static bool AutoReleaseGameObjectHandle { private set; get; }
|
||||
public static IDecryptionServices DecryptionServices { private set; get; }
|
||||
public static IBundleServices BundleServices { private set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源系统
|
||||
/// 初始化
|
||||
/// 注意:在使用AssetSystem之前需要初始化
|
||||
/// </summary>
|
||||
public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, bool autoReleaseGameObjectHandle, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||
{
|
||||
SimulationOnEditor = simulationOnEditor;
|
||||
AssetLoadingMaxNumber = assetLoadingMaxNumber;
|
||||
_simulationOnEditor = simulationOnEditor;
|
||||
_loadingMaxNumber = loadingMaxNumber;
|
||||
AutoReleaseGameObjectHandle = autoReleaseGameObjectHandle;
|
||||
DecryptionServices = decryptionServices;
|
||||
BundleServices = bundleServices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// 更新
|
||||
/// </summary>
|
||||
public static void Update()
|
||||
{
|
||||
@@ -63,7 +57,7 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
if (loadingCount < AssetLoadingMaxNumber)
|
||||
if (loadingCount < _loadingMaxNumber)
|
||||
provider.Update();
|
||||
|
||||
if (provider.IsDone == false)
|
||||
@@ -72,12 +66,30 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public static void DestroyAll()
|
||||
{
|
||||
_loaders.Clear();
|
||||
_providers.Clear();
|
||||
_sceneHandles.Clear();
|
||||
|
||||
DecryptionServices = null;
|
||||
BundleServices = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// </summary>
|
||||
public static void UnloadUnusedAssets()
|
||||
{
|
||||
if (SimulationOnEditor)
|
||||
if (AutoReleaseGameObjectHandle)
|
||||
{
|
||||
CheckAutoReleaseGameObjectHandle();
|
||||
}
|
||||
|
||||
if (_simulationOnEditor)
|
||||
{
|
||||
for (int i = _providers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -128,15 +140,22 @@ namespace YooAsset
|
||||
Resources.UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景
|
||||
/// </summary>
|
||||
public static SceneOperationHandle LoadSceneAsync(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
|
||||
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
return completedProvider.CreateHandle<SceneOperationHandle>();
|
||||
}
|
||||
|
||||
// 注意:场景句柄永远保持唯一
|
||||
if (_sceneHandles.ContainsKey(scenePath))
|
||||
return _sceneHandles[scenePath];
|
||||
string providerGUID = assetInfo.ProviderGUID;
|
||||
if (_sceneHandles.ContainsKey(providerGUID))
|
||||
return _sceneHandles[providerGUID];
|
||||
|
||||
// 如果加载的是主场景,则卸载所有缓存的场景
|
||||
if (sceneMode == LoadSceneMode.Single)
|
||||
@@ -144,68 +163,104 @@ namespace YooAsset
|
||||
UnloadAllScene();
|
||||
}
|
||||
|
||||
ProviderBase provider = TryGetProvider(scenePath);
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (SimulationOnEditor)
|
||||
provider = new DatabaseSceneProvider(scenePath, sceneMode, activateOnLoad, priority);
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
|
||||
else
|
||||
provider = new BundledSceneProvider(scenePath, sceneMode, activateOnLoad, priority);
|
||||
provider = new BundledSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
}
|
||||
|
||||
var handle = provider.CreateHandle() as SceneOperationHandle;
|
||||
_sceneHandles.Add(scenePath, handle);
|
||||
var handle = provider.CreateHandle<SceneOperationHandle>();
|
||||
_sceneHandles.Add(providerGUID, handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源对象
|
||||
/// </summary>
|
||||
public static AssetOperationHandle LoadAssetAsync(string assetPath, System.Type assetType)
|
||||
public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
ProviderBase provider = TryGetProvider(assetPath);
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
return completedProvider.CreateHandle<AssetOperationHandle>();
|
||||
}
|
||||
|
||||
ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (SimulationOnEditor)
|
||||
provider = new DatabaseAssetProvider(assetPath, assetType);
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseAssetProvider(assetInfo);
|
||||
else
|
||||
provider = new BundledAssetProvider(assetPath, assetType);
|
||||
provider = new BundledAssetProvider(assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
}
|
||||
return provider.CreateHandle() as AssetOperationHandle;
|
||||
return provider.CreateHandle<AssetOperationHandle>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载子资源对象
|
||||
/// </summary>
|
||||
public static SubAssetsOperationHandle LoadSubAssetsAsync(string assetPath, System.Type assetType)
|
||||
public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
ProviderBase provider = TryGetProvider(assetPath);
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
|
||||
}
|
||||
|
||||
ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (SimulationOnEditor)
|
||||
provider = new DatabaseSubAssetsProvider(assetPath, assetType);
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSubAssetsProvider(assetInfo);
|
||||
else
|
||||
provider = new BundledSubAssetsProvider(assetPath, assetType);
|
||||
provider = new BundledSubAssetsProvider(assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providers.Add(provider);
|
||||
}
|
||||
return provider.CreateHandle() as SubAssetsOperationHandle;
|
||||
return provider.CreateHandle<SubAssetsOperationHandle>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加自动释放的游戏对象句柄
|
||||
/// </summary>
|
||||
public static void AddAutoReleaseGameObjectHandle(AssetOperationHandle handle)
|
||||
{
|
||||
if (_trackGameObjectHandles.Contains(handle) == false)
|
||||
_trackGameObjectHandles.Add(handle);
|
||||
}
|
||||
private static void CheckAutoReleaseGameObjectHandle()
|
||||
{
|
||||
List<AssetOperationHandle> removeList = new List<AssetOperationHandle>();
|
||||
foreach (var trackHandle in _trackGameObjectHandles)
|
||||
{
|
||||
trackHandle.CheckAutoReleaseHandle();
|
||||
if (trackHandle.IsValidNoWarning == false)
|
||||
removeList.Add(trackHandle);
|
||||
}
|
||||
foreach (var removeHandle in removeList)
|
||||
{
|
||||
_trackGameObjectHandles.Remove(removeHandle);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void UnloadSubScene(ProviderBase provider)
|
||||
{
|
||||
string scenePath = provider.AssetPath;
|
||||
if (_sceneHandles.ContainsKey(scenePath) == false)
|
||||
string providerGUID = provider.MainAssetInfo.ProviderGUID;
|
||||
if (_sceneHandles.ContainsKey(providerGUID) == false)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 释放子场景句柄
|
||||
_sceneHandles[scenePath].ReleaseInternal();
|
||||
_sceneHandles.Remove(scenePath);
|
||||
_sceneHandles[providerGUID].ReleaseInternal();
|
||||
_sceneHandles.Remove(providerGUID);
|
||||
|
||||
// 卸载未被使用的资源(包括场景)
|
||||
AssetSystem.UnloadUnusedAssets();
|
||||
@@ -239,24 +294,19 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(string assetPath)
|
||||
internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
|
||||
{
|
||||
string bundleName = BundleServices.GetBundleName(assetPath);
|
||||
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
|
||||
BundleInfo bundleInfo = BundleServices.GetBundleInfo(assetInfo);
|
||||
return CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
}
|
||||
internal static List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(string assetPath)
|
||||
internal static List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
|
||||
{
|
||||
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>();
|
||||
string[] depends = BundleServices.GetAllDependencies(assetPath);
|
||||
if (depends != null)
|
||||
BundleInfo[] depends = BundleServices.GetAllDependBundleInfos(assetInfo);
|
||||
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>(depends.Length);
|
||||
foreach (var bundleInfo in depends)
|
||||
{
|
||||
foreach (var dependBundleName in depends)
|
||||
{
|
||||
BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName);
|
||||
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(dependBundleInfo);
|
||||
result.Add(dependLoader);
|
||||
}
|
||||
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
result.Add(dependLoader);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -291,7 +341,7 @@ namespace YooAsset
|
||||
for (int i = 0; i < _loaders.Count; i++)
|
||||
{
|
||||
AssetBundleLoaderBase temp = _loaders[i];
|
||||
if (temp.BundleFileInfo.BundleName.Equals(bundleName))
|
||||
if (temp.MainBundleInfo.BundleName.Equals(bundleName))
|
||||
{
|
||||
loader = temp;
|
||||
break;
|
||||
@@ -299,13 +349,13 @@ namespace YooAsset
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
private static ProviderBase TryGetProvider(string assetPath)
|
||||
private static ProviderBase TryGetProvider(string providerGUID)
|
||||
{
|
||||
ProviderBase provider = null;
|
||||
for (int i = 0; i < _providers.Count; i++)
|
||||
{
|
||||
ProviderBase temp = _providers[i];
|
||||
if (temp.AssetPath.Equals(assetPath))
|
||||
if (temp.MainAssetInfo.ProviderGUID.Equals(providerGUID))
|
||||
{
|
||||
provider = temp;
|
||||
break;
|
||||
@@ -314,23 +364,23 @@ namespace YooAsset
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
#region 调试专属方法
|
||||
internal static void GetDebugReport(DebugReport report)
|
||||
internal static DebugReport GetDebugReport()
|
||||
{
|
||||
report.ClearAll();
|
||||
DebugReport report = new DebugReport();
|
||||
report.FrameCount = Time.frameCount;
|
||||
report.BundleCount = _loaders.Count;
|
||||
report.AssetCount = _providers.Count;
|
||||
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
DebugProviderInfo providerInfo = new DebugProviderInfo();
|
||||
providerInfo.AssetPath = provider.AssetPath;
|
||||
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
|
||||
providerInfo.SpawnScene = provider.SpawnScene;
|
||||
providerInfo.SpawnTime = provider.SpawnTime;
|
||||
providerInfo.RefCount = provider.RefCount;
|
||||
providerInfo.Status = provider.Status;
|
||||
providerInfo.BundleInfos.Clear();
|
||||
providerInfo.Status = (int)provider.Status;
|
||||
providerInfo.BundleInfos = new List<DebugBundleInfo>();
|
||||
report.ProviderInfos.Add(providerInfo);
|
||||
|
||||
if (provider is BundledProvider)
|
||||
@@ -342,6 +392,7 @@ namespace YooAsset
|
||||
|
||||
// 重新排序
|
||||
report.ProviderInfos.Sort();
|
||||
return report;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -117,26 +118,72 @@ namespace YooAsset
|
||||
if (Provider.AssetObject == null)
|
||||
return null;
|
||||
|
||||
GameObject result;
|
||||
if (setPositionRotation)
|
||||
{
|
||||
if (parent == null)
|
||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation);
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation);
|
||||
else
|
||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent == null)
|
||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject);
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject);
|
||||
else
|
||||
return UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
|
||||
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
|
||||
}
|
||||
|
||||
if (AssetSystem.AutoReleaseGameObjectHandle)
|
||||
{
|
||||
AddTrackGameObject(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
|
||||
{
|
||||
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
OperationSystem.StartOperaiton(operation);
|
||||
|
||||
if (AssetSystem.AutoReleaseGameObjectHandle)
|
||||
{
|
||||
operation.Completed += InstantiateOperationCompleted;
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
#region 资源对象句柄相关
|
||||
private readonly HashSet<GameObject> _trackGameObjects = new HashSet<GameObject>();
|
||||
private void InstantiateOperationCompleted(AsyncOperationBase obj)
|
||||
{
|
||||
if (obj.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var op = obj as InstantiateOperation;
|
||||
AddTrackGameObject(op.Result);
|
||||
}
|
||||
}
|
||||
private void AddTrackGameObject(GameObject go)
|
||||
{
|
||||
if (go != null)
|
||||
{
|
||||
_trackGameObjects.Add(go);
|
||||
AssetSystem.AddAutoReleaseGameObjectHandle(this);
|
||||
}
|
||||
}
|
||||
internal void CheckAutoReleaseHandle()
|
||||
{
|
||||
if (IsValidNoWarning == false)
|
||||
return;
|
||||
if (_trackGameObjects.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var go in _trackGameObjects)
|
||||
{
|
||||
if (go != null)
|
||||
return;
|
||||
}
|
||||
ReleaseInternal();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,13 @@ namespace YooAsset
|
||||
{
|
||||
public abstract class OperationHandleBase : IEnumerator
|
||||
{
|
||||
private readonly string _cachedAssetPath;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
internal ProviderBase Provider { private set; get; }
|
||||
|
||||
internal OperationHandleBase(ProviderBase provider)
|
||||
{
|
||||
Provider = provider;
|
||||
_cachedAssetPath = provider.AssetPath;
|
||||
_assetInfo = provider.MainAssetInfo;
|
||||
}
|
||||
internal abstract void InvokeCallback();
|
||||
|
||||
@@ -85,14 +85,28 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
if (Provider == null)
|
||||
YooLogger.Warning($"Operation handle is released : {_cachedAssetPath}");
|
||||
YooLogger.Warning($"Operation handle is released : {_assetInfo.AssetPath}");
|
||||
else if (Provider.IsDestroyed)
|
||||
YooLogger.Warning($"Provider is destroyed : {_cachedAssetPath}");
|
||||
YooLogger.Warning($"Provider is destroyed : {_assetInfo.AssetPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 句柄是否有效
|
||||
/// </summary>
|
||||
public bool IsValidNoWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Provider != null && Provider.IsDestroyed == false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放句柄
|
||||
/// </summary>
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace YooAsset
|
||||
{
|
||||
string error = $"{nameof(SceneOperationHandle)} is invalid.";
|
||||
var operation = new UnloadSceneOperation(error);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
OperationSystem.StartOperaiton(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace YooAsset
|
||||
string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !";
|
||||
YooLogger.Error(error);
|
||||
var operation = new UnloadSceneOperation(error);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
OperationSystem.StartOperaiton(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace YooAsset
|
||||
AssetSystem.UnloadSubScene(Provider);
|
||||
{
|
||||
var operation = new UnloadSceneOperation(sceneObject);
|
||||
OperationSystem.ProcessOperaiton(operation);
|
||||
OperationSystem.StartOperaiton(operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class SubAssetsOperationHandle : OperationHandleBase
|
||||
@@ -77,14 +78,35 @@ namespace YooAsset
|
||||
if (IsValid == false)
|
||||
return null;
|
||||
|
||||
foreach (var asset in Provider.AllAssetObjects)
|
||||
foreach (var assetObject in Provider.AllAssetObjects)
|
||||
{
|
||||
if (asset.name == assetName)
|
||||
return asset as TObject;
|
||||
if (assetObject.name == assetName)
|
||||
return assetObject as TObject;
|
||||
}
|
||||
|
||||
YooLogger.Warning($"Not found sub asset object : {assetName}");
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的子资源对象集合
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">子资源对象类型</typeparam>
|
||||
public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object
|
||||
{
|
||||
if (IsValid == false)
|
||||
return null;
|
||||
|
||||
List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);
|
||||
foreach (var assetObject in Provider.AllAssetObjects)
|
||||
{
|
||||
var retObject = assetObject as TObject;
|
||||
if (retObject != null)
|
||||
ret.Add(retObject);
|
||||
else
|
||||
YooLogger.Warning($"The type conversion failed : {assetObject.name}");
|
||||
}
|
||||
return ret.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -39,31 +40,33 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None)
|
||||
if (MainBundleInfo.IsInvalid)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Invalid load mode : {BundleFileInfo.BundleName}";
|
||||
LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
_fileLoadPath = BundleFileInfo.GetCacheLoadPath();
|
||||
_fileLoadPath = MainBundleInfo.GetCacheLoadPath();
|
||||
}
|
||||
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_fileLoadPath = BundleFileInfo.GetStreamingLoadPath();
|
||||
_fileLoadPath = MainBundleInfo.GetStreamingLoadPath();
|
||||
}
|
||||
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_fileLoadPath = BundleFileInfo.GetCacheLoadPath();
|
||||
_fileLoadPath = MainBundleInfo.GetCacheLoadPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString());
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +74,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
_downloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain);
|
||||
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
@@ -109,12 +112,12 @@ namespace YooAsset
|
||||
#endif
|
||||
|
||||
// Load assetBundle file
|
||||
if (BundleFileInfo.IsEncrypted)
|
||||
if (MainBundleInfo.IsEncrypted)
|
||||
{
|
||||
if (AssetSystem.DecryptionServices == null)
|
||||
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {BundleFileInfo.BundleName}");
|
||||
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
|
||||
|
||||
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo);
|
||||
ulong offset = AssetSystem.DecryptionServices.GetFileOffset();
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
|
||||
else
|
||||
@@ -154,8 +157,23 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {BundleFileInfo.BundleName}";
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
string cacheLoadPath = MainBundleInfo.GetCacheLoadPath();
|
||||
if (DownloadSystem.CheckContentIntegrity(EVerifyLevel.High, cacheLoadPath, MainBundleInfo.SizeBytes, MainBundleInfo.CRC) == false)
|
||||
{
|
||||
if (File.Exists(cacheLoadPath))
|
||||
{
|
||||
YooLogger.Error($"Delete the invalid cache file : {cacheLoadPath}");
|
||||
File.Delete(cacheLoadPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,7 +201,7 @@ namespace YooAsset
|
||||
if (_isShowWaitForAsyncError == false)
|
||||
{
|
||||
_isShowWaitForAsyncError = true;
|
||||
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}");
|
||||
YooLogger.Error($"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.BundleName} from remote with sync load method !");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 资源包文件信息
|
||||
/// </summary>
|
||||
public BundleInfo BundleFileInfo { private set; get; }
|
||||
public BundleInfo MainBundleInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
@@ -45,7 +45,7 @@ namespace YooAsset
|
||||
|
||||
public AssetBundleLoaderBase(BundleInfo bundleInfo)
|
||||
{
|
||||
BundleFileInfo = bundleInfo;
|
||||
MainBundleInfo = bundleInfo;
|
||||
RefCount = 0;
|
||||
Status = EStatus.None;
|
||||
}
|
||||
@@ -91,9 +91,9 @@ namespace YooAsset
|
||||
if (forceDestroy == false)
|
||||
{
|
||||
if (RefCount > 0)
|
||||
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}");
|
||||
throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.BundleName}");
|
||||
if (IsDone() == false)
|
||||
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}");
|
||||
throw new Exception($"Bundle file loader is not done : {MainBundleInfo.BundleName}");
|
||||
}
|
||||
|
||||
if (CacheBundle != null)
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
private float _tryTimer = 0;
|
||||
private string _webURL;
|
||||
private bool _isShowWaitForAsyncError = false;
|
||||
private UnityWebRequest _webRequest;
|
||||
|
||||
|
||||
@@ -37,28 +38,30 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None)
|
||||
if (MainBundleInfo.IsInvalid)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Invalid load mode : {BundleFileInfo.BundleName}";
|
||||
LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_webURL = BundleFileInfo.GetStreamingLoadPath();
|
||||
_webURL = MainBundleInfo.GetStreamingLoadPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString());
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 从服务器或缓存中获取AssetBundle文件
|
||||
if (_steps == ESteps.LoadFile)
|
||||
{
|
||||
string hash = StringUtility.RemoveExtension(BundleFileInfo.Hash);
|
||||
string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash);
|
||||
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
|
||||
_webRequest.SendWebRequest();
|
||||
_steps = ESteps.CheckFile;
|
||||
@@ -87,7 +90,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"AssetBundle file is invalid : {BundleFileInfo.BundleName}";
|
||||
LastError = $"AssetBundle file is invalid : {MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
else
|
||||
@@ -116,7 +119,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
throw new System.NotImplementedException($"WebGL platform not support {nameof(WaitForAsyncComplete)}");
|
||||
if (_isShowWaitForAsyncError == false)
|
||||
{
|
||||
_isShowWaitForAsyncError = true;
|
||||
YooLogger.Error($"WebGL platform not support {nameof(WaitForAsyncComplete)} ! Use the async load method instead of the sync load method !");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ namespace YooAsset
|
||||
private readonly List<AssetBundleLoaderBase> _dependBundles;
|
||||
|
||||
|
||||
public DependAssetBundleGroup(string assetPath)
|
||||
public DependAssetBundleGroup(List<AssetBundleLoaderBase> dpendBundles)
|
||||
{
|
||||
_dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath);
|
||||
_dependBundles = dpendBundles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,9 +102,9 @@ namespace YooAsset
|
||||
foreach (var loader in _dependBundles)
|
||||
{
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = loader.BundleFileInfo.BundleName;
|
||||
bundleInfo.BundleName = loader.MainBundleInfo.BundleName;
|
||||
bundleInfo.RefCount = loader.RefCount;
|
||||
bundleInfo.Status = loader.Status;
|
||||
bundleInfo.Status = (int)loader.Status;
|
||||
output.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
if (_handle.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_handle.AssetObject == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public abstract class RawFileOperation : AsyncOperationBase
|
||||
{
|
||||
protected readonly BundleInfo _bundleInfo;
|
||||
internal readonly BundleInfo _bundleInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的拷贝路径
|
||||
@@ -49,6 +49,34 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发生错误的原生文件操作
|
||||
/// </summary>
|
||||
internal sealed class CompletedRawFileOperation : RawFileOperation
|
||||
{
|
||||
private readonly string _error;
|
||||
internal CompletedRawFileOperation(string error, string copyPath) : base(null, copyPath)
|
||||
{
|
||||
_error = error;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _error;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件的缓存路径
|
||||
/// </summary>
|
||||
public override string GetCachePath()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下模拟运行的原生文件操作
|
||||
/// </summary>
|
||||
@@ -175,7 +203,10 @@ namespace YooAsset
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.DownloadFromApk;
|
||||
if (DownloadSystem.ContainsVerifyFile(_bundleInfo.Hash))
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
else
|
||||
_steps = ESteps.DownloadFromApk;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -207,7 +238,17 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||
{
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "File content verify failed !";
|
||||
}
|
||||
}
|
||||
_fileRequester.Dispose();
|
||||
}
|
||||
@@ -314,7 +355,10 @@ namespace YooAsset
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.DownloadFromApk;
|
||||
if (DownloadSystem.ContainsVerifyFile(_bundleInfo.Hash))
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
else
|
||||
_steps = ESteps.DownloadFromApk;
|
||||
}
|
||||
else if (_bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
@@ -377,7 +421,17 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
if (DownloadSystem.CheckContentIntegrity(GetCachePath(), _bundleInfo.SizeBytes, _bundleInfo.CRC))
|
||||
{
|
||||
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
|
||||
_steps = ESteps.CheckAndCopyFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "File content verify failed !";
|
||||
}
|
||||
}
|
||||
_fileRequester.Dispose();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public BundledAssetProvider(string assetPath, System.Type assetType)
|
||||
: base(assetPath, assetType)
|
||||
public BundledAssetProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
@@ -36,19 +35,19 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
DependBundleGroup.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
if (DependBundleGroup.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = DependBundles.GetLastError();
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
@@ -69,17 +68,17 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (AssetType == null)
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName);
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName, AssetType);
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName);
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
|
||||
else
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType);
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
@@ -106,7 +105,10 @@ namespace YooAsset
|
||||
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}";
|
||||
if(MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
|
||||
else
|
||||
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -6,15 +6,17 @@ namespace YooAsset
|
||||
internal abstract class BundledProvider : ProviderBase
|
||||
{
|
||||
protected AssetBundleLoaderBase OwnerBundle { private set; get; }
|
||||
protected DependAssetBundleGroup DependBundles { private set; get; }
|
||||
protected DependAssetBundleGroup DependBundleGroup { private set; get; }
|
||||
|
||||
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType)
|
||||
public BundledProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath);
|
||||
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetInfo);
|
||||
OwnerBundle.Reference();
|
||||
OwnerBundle.AddProvider(this);
|
||||
DependBundles = new DependAssetBundleGroup(assetPath);
|
||||
DependBundles.Reference();
|
||||
|
||||
var dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetInfo);
|
||||
DependBundleGroup = new DependAssetBundleGroup(dependBundles);
|
||||
DependBundleGroup.Reference();
|
||||
}
|
||||
public override void Destroy()
|
||||
{
|
||||
@@ -26,10 +28,10 @@ namespace YooAsset
|
||||
OwnerBundle.Release();
|
||||
OwnerBundle = null;
|
||||
}
|
||||
if (DependBundles != null)
|
||||
if (DependBundleGroup != null)
|
||||
{
|
||||
DependBundles.Release();
|
||||
DependBundles = null;
|
||||
DependBundleGroup.Release();
|
||||
DependBundleGroup = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +41,12 @@ namespace YooAsset
|
||||
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
|
||||
{
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
|
||||
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
|
||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||
bundleInfo.Status = OwnerBundle.Status;
|
||||
bundleInfo.Status = (int)OwnerBundle.Status;
|
||||
output.Add(bundleInfo);
|
||||
|
||||
DependBundles.GetBundleDebugInfos(output);
|
||||
DependBundleGroup.GetBundleDebugInfos(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -22,11 +23,10 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public BundledSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
|
||||
: base(scenePath, null)
|
||||
public BundledSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
_sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
|
||||
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_activateOnLoad = activateOnLoad;
|
||||
_priority = priority;
|
||||
}
|
||||
@@ -43,15 +43,15 @@ namespace YooAsset
|
||||
// 1. 检测资源包
|
||||
if (Status == EStatus.CheckBundle)
|
||||
{
|
||||
if (DependBundles.IsDone() == false)
|
||||
if (DependBundleGroup.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = DependBundles.GetLastError();
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace YooAsset
|
||||
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
|
||||
if(Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"The load scene is invalid : {AssetPath}";
|
||||
LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public BundledSubAssetsProvider(string assetPath, System.Type assetType)
|
||||
: base(assetPath, assetType)
|
||||
public BundledSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
@@ -36,19 +35,19 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
DependBundleGroup.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
if (DependBundleGroup.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
if (DependBundleGroup.IsSucceed() == false)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = DependBundles.GetLastError();
|
||||
LastError = DependBundleGroup.GetLastError();
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
@@ -69,17 +68,17 @@ namespace YooAsset
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (AssetType == null)
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName);
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName, AssetType);
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName);
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath);
|
||||
else
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType);
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
@@ -106,7 +105,10 @@ namespace YooAsset
|
||||
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}";
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
|
||||
else
|
||||
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class CompletedProvider : ProviderBase
|
||||
{
|
||||
public override float Progress
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDone)
|
||||
return 1f;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public CompletedProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = MainAssetInfo.Error;
|
||||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e64fd2ee771f7d498838ebf375a9531
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -17,8 +17,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseAssetProvider(string assetPath, System.Type assetType)
|
||||
: base(assetPath, assetType)
|
||||
public DatabaseAssetProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
@@ -30,11 +29,11 @@ namespace YooAsset
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = $"Not found asset : {AssetPath}";
|
||||
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
return;
|
||||
@@ -50,10 +49,10 @@ namespace YooAsset
|
||||
// 1. 加载资源对象
|
||||
if (Status == EStatus.Loading)
|
||||
{
|
||||
if (AssetType == null)
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(AssetPath);
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType);
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
Status = EStatus.Checking;
|
||||
}
|
||||
|
||||
@@ -63,7 +62,10 @@ namespace YooAsset
|
||||
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"Failed to load asset object : {AssetPath}";
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -19,8 +19,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
|
||||
: base(scenePath, null)
|
||||
public DatabaseSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
_activateOnLoad = activateOnLoad;
|
||||
@@ -42,7 +41,7 @@ namespace YooAsset
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
||||
loadSceneParameters.loadSceneMode = SceneMode;
|
||||
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(AssetPath, loadSceneParameters);
|
||||
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (_asyncOp != null)
|
||||
{
|
||||
_asyncOp.allowSceneActivation = true;
|
||||
@@ -52,7 +51,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = $"Failed to load scene : {AssetPath}";
|
||||
LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
}
|
||||
@@ -70,7 +69,7 @@ namespace YooAsset
|
||||
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"The loaded scene is invalid : {AssetPath}";
|
||||
LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseSubAssetsProvider(string assetPath, System.Type assetType)
|
||||
: base(assetPath, assetType)
|
||||
public DatabaseSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
|
||||
{
|
||||
}
|
||||
public override void Update()
|
||||
@@ -30,11 +29,11 @@ namespace YooAsset
|
||||
if (Status == EStatus.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
Status = EStatus.Fail;
|
||||
LastError = $"Not found asset : {AssetPath}";
|
||||
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
return;
|
||||
@@ -50,17 +49,17 @@ namespace YooAsset
|
||||
// 1. 加载资源对象
|
||||
if (Status == EStatus.Loading)
|
||||
{
|
||||
if (AssetType == null)
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
{
|
||||
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath);
|
||||
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath);
|
||||
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
|
||||
List<UnityEngine.Object> result = new List<Object>(findAssets.Length);
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
if (AssetType.IsAssignableFrom(findAsset.GetType()))
|
||||
if (MainAssetInfo.AssetType.IsAssignableFrom(findAsset.GetType()))
|
||||
result.Add(findAsset);
|
||||
}
|
||||
AllAssetObjects = result.ToArray();
|
||||
@@ -74,7 +73,10 @@ namespace YooAsset
|
||||
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
LastError = $"Failed to load sub assets : {nameof(AssetType)} in {AssetPath}";
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
InvokeCompletion();
|
||||
|
||||
@@ -18,19 +18,9 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象的名称
|
||||
/// </summary>
|
||||
public string AssetName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象的类型
|
||||
/// </summary>
|
||||
public System.Type AssetType { private set; get; }
|
||||
public AssetInfo MainAssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取的资源对象
|
||||
@@ -95,11 +85,9 @@ namespace YooAsset
|
||||
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
|
||||
|
||||
|
||||
public ProviderBase(string assetPath, System.Type assetType)
|
||||
public ProviderBase(AssetInfo assetInfo)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
AssetName = System.IO.Path.GetFileName(assetPath);
|
||||
AssetType = assetType;
|
||||
MainAssetInfo = assetInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -126,25 +114,38 @@ namespace YooAsset
|
||||
return RefCount <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为场景提供者
|
||||
/// </summary>
|
||||
public bool IsSceneProvider()
|
||||
{
|
||||
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建操作句柄
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public OperationHandleBase CreateHandle()
|
||||
public T CreateHandle<T>() where T : OperationHandleBase
|
||||
{
|
||||
// 引用计数增加
|
||||
RefCount++;
|
||||
|
||||
OperationHandleBase handle;
|
||||
if (IsSceneProvider())
|
||||
if (typeof(T) == typeof(AssetOperationHandle))
|
||||
handle = new AssetOperationHandle(this);
|
||||
else if (typeof(T) == typeof(SceneOperationHandle))
|
||||
handle = new SceneOperationHandle(this);
|
||||
else if (IsSubAssetsProvider())
|
||||
else if (typeof(T) == typeof(SubAssetsOperationHandle))
|
||||
handle = new SubAssetsOperationHandle(this);
|
||||
else
|
||||
handle = new AssetOperationHandle(this);
|
||||
throw new System.NotImplementedException();
|
||||
|
||||
_handles.Add(handle);
|
||||
return handle;
|
||||
return handle as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,7 +176,7 @@ namespace YooAsset
|
||||
// 验证结果
|
||||
if (IsDone == false)
|
||||
{
|
||||
YooLogger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}");
|
||||
YooLogger.Warning($"WaitForAsyncComplete failed to loading : {MainAssetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,21 +197,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSceneProvider()
|
||||
{
|
||||
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public bool IsSubAssetsProvider()
|
||||
{
|
||||
if (this is BundledSubAssetsProvider || this is DatabaseSubAssetsProvider)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#region 异步编程相关
|
||||
private TaskCompletionSource<object> _taskCompletionSource;
|
||||
protected void InvokeCompletion()
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
[Serializable]
|
||||
internal class DebugBundleInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName { set; get; }
|
||||
public string BundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
public int RefCount { set; get; }
|
||||
public int RefCount;
|
||||
|
||||
/// <summary>
|
||||
/// 加载状态
|
||||
/// </summary>
|
||||
public AssetBundleLoaderBase.EStatus Status { set; get; }
|
||||
public int Status;
|
||||
}
|
||||
}
|
||||
@@ -4,37 +4,38 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
[Serializable]
|
||||
internal class DebugProviderInfo : IComparer<DebugProviderInfo>, IComparable<DebugProviderInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源对象路径
|
||||
/// </summary>
|
||||
public string AssetPath { set; get; }
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源出生的场景
|
||||
/// </summary>
|
||||
public string SpawnScene { set; get; }
|
||||
public string SpawnScene;
|
||||
|
||||
/// <summary>
|
||||
/// 资源出生的时间
|
||||
/// </summary>
|
||||
public string SpawnTime { set; get; }
|
||||
public string SpawnTime;
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
public int RefCount { set; get; }
|
||||
public int RefCount;
|
||||
|
||||
/// <summary>
|
||||
/// 加载状态
|
||||
/// </summary>
|
||||
public ProviderBase.EStatus Status { set; get; }
|
||||
public int Status;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源包列表
|
||||
/// </summary>
|
||||
public readonly List<DebugBundleInfo> BundleInfos = new List<DebugBundleInfo>();
|
||||
public List<DebugBundleInfo> BundleInfos;
|
||||
|
||||
public int CompareTo(DebugProviderInfo other)
|
||||
{
|
||||
|
||||
@@ -1,21 +1,49 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源系统调试信息
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class DebugReport
|
||||
{
|
||||
public readonly List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
|
||||
public int BundleCount { set; get; }
|
||||
public int AssetCount { set; get; }
|
||||
public List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
ProviderInfos.Clear();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 游戏帧
|
||||
/// </summary>
|
||||
public int FrameCount;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包总数
|
||||
/// </summary>
|
||||
public int BundleCount;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象总数
|
||||
/// </summary>
|
||||
public int AssetCount;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
public static byte[] Serialize(DebugReport debugReport)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonUtility.ToJson(debugReport));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
public static DebugReport Deserialize(byte[] data)
|
||||
{
|
||||
return JsonUtility.FromJson<DebugReport>(Encoding.UTF8.GetString(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs
Normal file
45
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal enum ERemoteCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 采样一次
|
||||
/// </summary>
|
||||
SampleOnce = 0,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class RemoteCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 命令类型
|
||||
/// </summary>
|
||||
public int CommandType;
|
||||
|
||||
/// <summary>
|
||||
/// 命令附加参数
|
||||
/// </summary>
|
||||
public string CommandParam;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
public static byte[] Serialize(RemoteCommand command)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonUtility.ToJson(command));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
public static RemoteCommand Deserialize(byte[] data)
|
||||
{
|
||||
return JsonUtility.FromJson<RemoteCommand>(Encoding.UTF8.GetString(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs.meta
Normal file
11
Assets/YooAsset/Runtime/Debugger/RemoteCommand.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e79402f4d610fb4408aa6f8a94b09cb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerDefine.cs
Normal file
12
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerDefine.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RemoteDebuggerDefine
|
||||
{
|
||||
public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
|
||||
public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fd4f5f47edbfd54ba92427daf9ea3a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerInRuntime.cs
Normal file
53
Assets/YooAsset/Runtime/Debugger/RemoteDebuggerInRuntime.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking.PlayerConnection;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RemoteDebuggerInRuntime : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 编辑器下获取报告的回调
|
||||
/// </summary>
|
||||
public static Action<int, DebugReport> EditorHandleDebugReportCallback;
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器下请求报告数据
|
||||
/// </summary>
|
||||
public static void EditorRequestDebugReport()
|
||||
{
|
||||
if(UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
var report = AssetSystem.GetDebugReport();
|
||||
EditorHandleDebugReportCallback?.Invoke(0, report);
|
||||
}
|
||||
}
|
||||
#else
|
||||
private void OnEnable()
|
||||
{
|
||||
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
|
||||
}
|
||||
private void OnHandleEditorMessage(MessageEventArgs args)
|
||||
{
|
||||
var command = RemoteCommand.Deserialize(args.data);
|
||||
YooLogger.Log($"On handle remote command : {command.CommandType} Param : {command.CommandParam}");
|
||||
if (command.CommandType == (int)ERemoteCommand.SampleOnce)
|
||||
{
|
||||
var debugReport = AssetSystem.GetDebugReport();
|
||||
var data = DebugReport.Serialize(debugReport);
|
||||
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgSendPlayerToEditor, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(command.CommandType.ToString());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91030c545c99c944a846f6a9a2a0756a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,14 +15,17 @@ namespace YooAsset
|
||||
private static readonly Dictionary<string, DownloaderBase> _downloaderDic = new Dictionary<string, DownloaderBase>();
|
||||
private static readonly List<string> _removeList = new List<string>(100);
|
||||
private static readonly Dictionary<string, string> _cachedHashList = new Dictionary<string, string>(1000);
|
||||
private static int _breakpointResumeFileSize;
|
||||
private static int _breakpointResumeFileSize = int.MaxValue;
|
||||
private static EVerifyLevel _verifyLevel = EVerifyLevel.High;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public static void Initialize(int breakpointResumeFileSize)
|
||||
public static void Initialize(int breakpointResumeFileSize, EVerifyLevel verifyLevel)
|
||||
{
|
||||
_breakpointResumeFileSize = breakpointResumeFileSize;
|
||||
_verifyLevel = verifyLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,7 +61,9 @@ namespace YooAsset
|
||||
downloader.Abort();
|
||||
}
|
||||
_downloaderDic.Clear();
|
||||
YooLogger.Log("DownloadSystem destroy all !");
|
||||
_removeList.Clear();
|
||||
_cachedHashList.Clear();
|
||||
_breakpointResumeFileSize = int.MaxValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,29 +148,44 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
// 验证文件完整性
|
||||
public static bool CheckContentIntegrity(BundleInfo bundleInfo)
|
||||
{
|
||||
return CheckContentIntegrity(bundleInfo.GetCacheLoadPath(), bundleInfo.SizeBytes, bundleInfo.CRC);
|
||||
}
|
||||
public static bool CheckContentIntegrity(PatchBundle patchBundle)
|
||||
{
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
return CheckContentIntegrity(filePath, patchBundle.SizeBytes, patchBundle.CRC);
|
||||
}
|
||||
/// <summary>
|
||||
/// 验证文件完整性
|
||||
/// </summary>
|
||||
public static bool CheckContentIntegrity(string filePath, long size, string crc)
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return false;
|
||||
return CheckContentIntegrity(_verifyLevel, filePath, size, crc);
|
||||
}
|
||||
|
||||
// 先验证文件大小
|
||||
long fileSize = FileUtility.GetFileSize(filePath);
|
||||
if (fileSize != size)
|
||||
return false;
|
||||
/// <summary>
|
||||
/// 验证文件完整性
|
||||
/// </summary>
|
||||
public static bool CheckContentIntegrity(EVerifyLevel verifyLevel, string filePath, long size, string crc)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath) == false)
|
||||
return false;
|
||||
|
||||
// 再验证文件CRC
|
||||
string fileCRC = HashUtility.FileCRC32(filePath);
|
||||
return fileCRC == crc;
|
||||
// 先验证文件大小
|
||||
long fileSize = FileUtility.GetFileSize(filePath);
|
||||
if (fileSize != size)
|
||||
return false;
|
||||
|
||||
// 再验证文件CRC
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string fileCRC = HashUtility.FileCRC32(filePath);
|
||||
return fileCRC == crc;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,8 @@ namespace YooAsset
|
||||
if (hasError == false)
|
||||
{
|
||||
// 注意:如果文件验证失败需要删除文件
|
||||
if (DownloadSystem.CheckContentIntegrity(_bundleInfo) == false)
|
||||
|
||||
if (DownloadSystem.CheckContentIntegrity(_bundleInfo.GetCacheLoadPath(), _bundleInfo.SizeBytes, _bundleInfo.CRC) == false)
|
||||
{
|
||||
hasError = true;
|
||||
_lastError = $"Verification failed";
|
||||
|
||||
19
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs
Normal file
19
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载文件校验等级
|
||||
/// </summary>
|
||||
public enum EVerifyLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证文件大小
|
||||
/// </summary>
|
||||
Low,
|
||||
|
||||
/// <summary>
|
||||
/// 验证文件大小和CRC
|
||||
/// </summary>
|
||||
High,
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs.meta
Normal file
11
Assets/YooAsset/Runtime/DownloadSystem/EVerifyLevel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02ad351eb8539da47a0c789e2f8c468f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -45,10 +45,21 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁异步操作系统
|
||||
/// </summary>
|
||||
public static void DestroyAll()
|
||||
{
|
||||
_operations.Clear();
|
||||
_watch = null;
|
||||
_maxTimeSlice = 0;
|
||||
_frameTime = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始处理异步操作类
|
||||
/// </summary>
|
||||
public static void ProcessOperaiton(AsyncOperationBase operationBase)
|
||||
public static void StartOperaiton(AsyncOperationBase operationBase)
|
||||
{
|
||||
_operations.Add(operationBase);
|
||||
operationBase.Start();
|
||||
|
||||
@@ -3,25 +3,92 @@ namespace YooAsset
|
||||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
private readonly PatchAsset _patchAsset;
|
||||
private string _providerGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源提供者唯一标识符
|
||||
/// </summary>
|
||||
internal string ProviderGUID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_providerGUID) == false)
|
||||
return _providerGUID;
|
||||
|
||||
if (AssetType == null)
|
||||
_providerGUID = $"{AssetPath}[null]";
|
||||
else
|
||||
_providerGUID = $"{AssetPath}[{AssetType.Name}]";
|
||||
return _providerGUID;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 身份是否无效
|
||||
/// </summary>
|
||||
internal bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return _patchAsset == null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
internal string Error { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType { private set; get; }
|
||||
|
||||
public AssetInfo(string assetPath, System.Type assetType)
|
||||
|
||||
// 注意:这是一个内部类,严格限制外部创建。
|
||||
private AssetInfo()
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
AssetType = assetType;
|
||||
}
|
||||
public AssetInfo(string assetPath)
|
||||
internal AssetInfo(PatchAsset patchAsset, System.Type assetType)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
if (patchAsset == null)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
_patchAsset = patchAsset;
|
||||
AssetType = assetType;
|
||||
Address = patchAsset.Address;
|
||||
AssetPath = patchAsset.AssetPath;
|
||||
Error = string.Empty;
|
||||
}
|
||||
internal AssetInfo(PatchAsset patchAsset)
|
||||
{
|
||||
if (patchAsset == null)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
_patchAsset = patchAsset;
|
||||
AssetType = null;
|
||||
Address = patchAsset.Address;
|
||||
AssetPath = patchAsset.AssetPath;
|
||||
Error = string.Empty;
|
||||
}
|
||||
internal AssetInfo(string error)
|
||||
{
|
||||
_patchAsset = null;
|
||||
AssetType = null;
|
||||
Address = string.Empty;
|
||||
AssetPath = string.Empty;
|
||||
Error = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class BundleInfo
|
||||
internal class BundleInfo
|
||||
{
|
||||
internal enum ELoadMode
|
||||
public enum ELoadMode
|
||||
{
|
||||
None,
|
||||
LoadFromStreaming,
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly PatchBundle _patchBundle;
|
||||
internal readonly ELoadMode LoadMode;
|
||||
public readonly ELoadMode LoadMode;
|
||||
|
||||
private string _streamingPath;
|
||||
private string _cachePath;
|
||||
@@ -26,17 +26,17 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 远端下载地址
|
||||
/// </summary>
|
||||
internal string RemoteMainURL { private set; get; }
|
||||
public string RemoteMainURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 远端下载备用地址
|
||||
/// </summary>
|
||||
internal string RemoteFallbackURL { private set; get; }
|
||||
public string RemoteFallbackURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器资源路径
|
||||
/// </summary>
|
||||
internal string EditorAssetPath { private set; get; }
|
||||
public string EditorAssetPath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
@@ -108,11 +108,27 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 身份是否无效
|
||||
/// </summary>
|
||||
public bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return _patchBundle == null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
|
||||
|
||||
private BundleInfo()
|
||||
{
|
||||
}
|
||||
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL)
|
||||
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL)
|
||||
{
|
||||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
@@ -120,8 +136,9 @@ namespace YooAsset
|
||||
RemoteMainURL = mainURL;
|
||||
RemoteFallbackURL = fallbackURL;
|
||||
EditorAssetPath = string.Empty;
|
||||
Error = string.Empty;
|
||||
}
|
||||
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath)
|
||||
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath)
|
||||
{
|
||||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
@@ -129,8 +146,9 @@ namespace YooAsset
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
EditorAssetPath = editorAssetPath;
|
||||
Error = string.Empty;
|
||||
}
|
||||
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
|
||||
public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
|
||||
{
|
||||
_patchBundle = patchBundle;
|
||||
LoadMode = loadMode;
|
||||
@@ -138,37 +156,23 @@ namespace YooAsset
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
EditorAssetPath = string.Empty;
|
||||
Error = string.Empty;
|
||||
}
|
||||
internal BundleInfo(string bundleName)
|
||||
public BundleInfo(string error)
|
||||
{
|
||||
_patchBundle = null;
|
||||
LoadMode = ELoadMode.None;
|
||||
BundleName = bundleName;
|
||||
BundleName = string.Empty;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
EditorAssetPath = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源包是否有效
|
||||
/// </summary>
|
||||
public bool IsValid()
|
||||
{
|
||||
return _patchBundle != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件是否在云端
|
||||
/// </summary>
|
||||
public bool InCloud()
|
||||
{
|
||||
return LoadMode == ELoadMode.LoadFromRemote;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取流文件夹的加载路径
|
||||
/// </summary>
|
||||
internal string GetStreamingLoadPath()
|
||||
public string GetStreamingLoadPath()
|
||||
{
|
||||
if (_patchBundle == null)
|
||||
return string.Empty;
|
||||
@@ -181,7 +185,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 获取缓存文件夹的加载路径
|
||||
/// </summary>
|
||||
internal string GetCacheLoadPath()
|
||||
public string GetCacheLoadPath()
|
||||
{
|
||||
if (_patchBundle == null)
|
||||
return string.Empty;
|
||||
@@ -191,7 +195,6 @@ namespace YooAsset
|
||||
return _cachePath;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否为JAR包内文件
|
||||
/// </summary>
|
||||
|
||||
@@ -17,17 +17,19 @@ namespace YooAsset
|
||||
|
||||
public delegate void OnDownloadOver(bool isSucceed);
|
||||
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
|
||||
public delegate void OnDownloadFileFailed(string fileName);
|
||||
|
||||
public delegate void OnDownloadError(string fileName, string error);
|
||||
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
|
||||
|
||||
private readonly int _downloadingMaxNumber;
|
||||
private readonly int _failedTryAgain;
|
||||
private readonly List<BundleInfo> _downloadList;
|
||||
private readonly List<BundleInfo> _loadFailedList = new List<BundleInfo>();
|
||||
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>();
|
||||
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
private readonly List<DownloaderBase> _removeList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
|
||||
|
||||
// 数据相关
|
||||
private ESteps _steps = ESteps.None;
|
||||
private bool _isPause = false;
|
||||
private long _lastDownloadBytes = 0;
|
||||
private int _lastDownloadCount = 0;
|
||||
|
||||
@@ -58,15 +60,20 @@ namespace YooAsset
|
||||
public OnDownloadOver OnDownloadOverCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当下载进度变化
|
||||
/// 当下载进度发生变化
|
||||
/// </summary>
|
||||
public OnDownloadProgress OnDownloadProgressCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当文件下载失败
|
||||
/// 当某个文件下载失败
|
||||
/// </summary>
|
||||
public OnDownloadFileFailed OnDownloadFileFailedCallback { set; get; }
|
||||
public OnDownloadError OnDownloadErrorCallback { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当开始下载某个文件
|
||||
/// </summary>
|
||||
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
|
||||
|
||||
|
||||
internal DownloaderOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||
{
|
||||
@@ -124,7 +131,7 @@ namespace YooAsset
|
||||
if (downloader.HasError())
|
||||
{
|
||||
_removeList.Add(downloader);
|
||||
_loadFailedList.Add(bundleInfo);
|
||||
_failedList.Add(downloader);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -151,27 +158,33 @@ namespace YooAsset
|
||||
|
||||
// 动态创建新的下载器到最大数量限制
|
||||
// 注意:如果期间有下载失败的文件,暂停动态创建下载器
|
||||
if (_downloadList.Count > 0 && _loadFailedList.Count == 0)
|
||||
if (_downloadList.Count > 0 && _failedList.Count == 0)
|
||||
{
|
||||
if (_isPause)
|
||||
return;
|
||||
|
||||
if (_downloaders.Count < _downloadingMaxNumber)
|
||||
{
|
||||
int index = _downloadList.Count - 1;
|
||||
var operation = DownloadSystem.BeginDownload(_downloadList[index], _failedTryAgain);
|
||||
var bundleInfo = _downloadList[index];
|
||||
var operation = DownloadSystem.BeginDownload(bundleInfo, _failedTryAgain);
|
||||
_downloaders.Add(operation);
|
||||
_downloadList.RemoveAt(index);
|
||||
OnStartDownloadFileCallback?.Invoke(bundleInfo.BundleName, bundleInfo.SizeBytes);
|
||||
}
|
||||
}
|
||||
|
||||
// 下载结算
|
||||
if (_downloaders.Count == 0)
|
||||
{
|
||||
if (_loadFailedList.Count > 0)
|
||||
if (_failedList.Count > 0)
|
||||
{
|
||||
string fileName = _loadFailedList[0].BundleName;
|
||||
var failedDownloader = _failedList[0];
|
||||
string fileName = failedDownloader.GetBundleInfo().BundleName;
|
||||
Error = $"Failed to download file : {fileName}";
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
OnDownloadFileFailedCallback?.Invoke(fileName);
|
||||
OnDownloadErrorCallback?.Invoke(fileName, failedDownloader.GetLastError());
|
||||
OnDownloadOverCallback?.Invoke(false);
|
||||
}
|
||||
else
|
||||
@@ -192,9 +205,25 @@ namespace YooAsset
|
||||
{
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
OperationSystem.ProcessOperaiton(this);
|
||||
OperationSystem.StartOperaiton(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暂停下载
|
||||
/// </summary>
|
||||
public void PauseDownload()
|
||||
{
|
||||
_isPause = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复下载
|
||||
/// </summary>
|
||||
public void ResumeDownload()
|
||||
{
|
||||
_isPause = false;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PackageDownloaderOperation : DownloaderOperation
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public abstract class UpdateManifestOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否发现了新的补丁清单
|
||||
/// </summary>
|
||||
public bool FoundNewManifest { protected set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,8 +67,8 @@ namespace YooAsset
|
||||
private readonly int _resourceVersion;
|
||||
private readonly int _timeout;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebDataRequester _downloaderHash;
|
||||
private UnityWebDataRequester _downloaderManifest;
|
||||
private UnityWebDataRequester _downloader1;
|
||||
private UnityWebDataRequester _downloader2;
|
||||
private float _verifyTime;
|
||||
|
||||
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
||||
@@ -87,26 +91,26 @@ namespace YooAsset
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
|
||||
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
||||
_downloaderHash = new UnityWebDataRequester();
|
||||
_downloaderHash.SendRequest(webURL, _timeout);
|
||||
_downloader1 = new UnityWebDataRequester();
|
||||
_downloader1.SendRequest(webURL, _timeout);
|
||||
_steps = ESteps.CheckWebManifestHash;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckWebManifestHash)
|
||||
{
|
||||
if (_downloaderHash.IsDone() == false)
|
||||
if (_downloader1.IsDone() == false)
|
||||
return;
|
||||
|
||||
// Check error
|
||||
if (_downloaderHash.HasError())
|
||||
if (_downloader1.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloaderHash.GetError();
|
||||
Error = _downloader1.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
string webManifestHash = _downloaderHash.GetText();
|
||||
string webManifestHash = _downloader1.GetText();
|
||||
string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
|
||||
|
||||
// 如果补丁清单文件的哈希值相同
|
||||
@@ -114,42 +118,44 @@ namespace YooAsset
|
||||
{
|
||||
YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
|
||||
LoadSandboxPatchManifest(_resourceVersion);
|
||||
FoundNewManifest = false;
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {cachedManifestHash}");
|
||||
FoundNewManifest = true;
|
||||
_steps = ESteps.LoadWebManifest;
|
||||
}
|
||||
}
|
||||
_downloaderHash.Dispose();
|
||||
_downloader1.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadWebManifest)
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
|
||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||
_downloaderManifest = new UnityWebDataRequester();
|
||||
_downloaderManifest.SendRequest(webURL, _timeout);
|
||||
_downloader2 = new UnityWebDataRequester();
|
||||
_downloader2.SendRequest(webURL, _timeout);
|
||||
_steps = ESteps.CheckWebManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckWebManifest)
|
||||
{
|
||||
if (_downloaderManifest.IsDone() == false)
|
||||
if (_downloader2.IsDone() == false)
|
||||
return;
|
||||
|
||||
// Check error
|
||||
if (_downloaderManifest.HasError())
|
||||
if (_downloader2.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloaderManifest.GetError();
|
||||
Error = _downloader2.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 解析补丁清单
|
||||
if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloaderManifest.GetText()))
|
||||
if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
|
||||
{
|
||||
_steps = ESteps.InitVerifyingCache;
|
||||
}
|
||||
@@ -157,10 +163,10 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid";
|
||||
Error = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
|
||||
}
|
||||
}
|
||||
_downloaderManifest.Dispose();
|
||||
_downloader2.Dispose();
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitVerifyingCache)
|
||||
@@ -207,18 +213,19 @@ namespace YooAsset
|
||||
|
||||
YooLogger.Log("Save remote patch manifest file.");
|
||||
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
|
||||
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
|
||||
PatchManifest.Serialize(savePath, remotePatchManifest);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
YooLogger.Warning(e.ToString());
|
||||
YooLogger.Error(e.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载沙盒内的补丁清单
|
||||
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
|
||||
/// </summary>
|
||||
private void LoadSandboxPatchManifest(int updateResourceVersion)
|
||||
{
|
||||
@@ -332,16 +339,8 @@ namespace YooAsset
|
||||
}
|
||||
private void VerifyInThread(object infoObj)
|
||||
{
|
||||
// 验证沙盒内的文件
|
||||
ThreadInfo info = (ThreadInfo)infoObj;
|
||||
try
|
||||
{
|
||||
info.Result = DownloadSystem.CheckContentIntegrity(info.FilePath, info.Bundle.SizeBytes, info.Bundle.CRC);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
info.Result = false;
|
||||
}
|
||||
info.Result = DownloadSystem.CheckContentIntegrity(info.FilePath, info.Bundle.SizeBytes, info.Bundle.CRC);
|
||||
_syncContext.Post(VerifyCallback, info);
|
||||
}
|
||||
private void VerifyCallback(object obj)
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace YooAsset
|
||||
private readonly int _resourceVersion;
|
||||
private readonly int _timeout;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private UnityWebDataRequester _downloaderManifest;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private PatchManifest _remotePatchManifest;
|
||||
|
||||
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
|
||||
@@ -104,28 +104,28 @@ namespace YooAsset
|
||||
{
|
||||
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
|
||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||
_downloaderManifest = new UnityWebDataRequester();
|
||||
_downloaderManifest.SendRequest(webURL, _timeout);
|
||||
_downloader = new UnityWebDataRequester();
|
||||
_downloader.SendRequest(webURL, _timeout);
|
||||
_steps = ESteps.CheckWebManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckWebManifest)
|
||||
{
|
||||
Progress = _downloaderManifest.Progress();
|
||||
if (_downloaderManifest.IsDone() == false)
|
||||
Progress = _downloader.Progress();
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
// Check error
|
||||
if (_downloaderManifest.HasError())
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloaderManifest.GetError();
|
||||
Error = _downloader.GetError();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 解析补丁清单
|
||||
if (ParseRemotePatchManifest(_downloaderManifest.GetText()))
|
||||
if (ParseRemotePatchManifest(_downloader.GetText()))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
@@ -134,10 +134,10 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid";
|
||||
Error = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
|
||||
}
|
||||
}
|
||||
_downloaderManifest.Dispose();
|
||||
_downloader.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ namespace YooAsset
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:下载系统只会验证当前游戏版本的资源文件,对于其它游戏版本的差异文件不会在初始化的时候去做校验。
|
||||
// 注意:通过比对文件大小做实时的文件校验方式!
|
||||
// 注意:通过比对文件大小做快速的文件校验!
|
||||
// 注意:在初始化的时候会去做最终校验!
|
||||
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -15,6 +16,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源的分类标签
|
||||
/// </summary>
|
||||
public string[] AssetTags;
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源包ID
|
||||
/// </summary>
|
||||
@@ -24,5 +30,24 @@ namespace YooAsset
|
||||
/// 依赖的资源包ID列表
|
||||
/// </summary>
|
||||
public int[] DependIDs;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含Tag
|
||||
/// </summary>
|
||||
public bool HasTag(string[] tags)
|
||||
{
|
||||
if (tags == null || tags.Length == 0)
|
||||
return false;
|
||||
if (AssetTags == null || AssetTags.Length == 0)
|
||||
return false;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
if (AssetTags.Contains(tag))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace YooAsset
|
||||
public long SizeBytes;
|
||||
|
||||
/// <summary>
|
||||
/// Tags
|
||||
/// 资源包的分类标签
|
||||
/// </summary>
|
||||
public string[] Tags;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user