mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
36 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 |
@@ -2,6 +2,73 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace YooAsset.Editor
|
||||
public EBuildMode BuildMode = EBuildMode.ForceRebuild;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源标签
|
||||
/// 内置资源标签(首包资源标签)
|
||||
/// </summary>
|
||||
public string BuildTags = string.Empty;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleBuilderSetting>();
|
||||
_setting = EditorHelper.LoadSettingData<AssetBundleBuilderSetting>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,7 +25,7 @@ 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;
|
||||
@@ -37,12 +37,10 @@ namespace YooAsset.Editor
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleBuilderUXML;
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
@@ -76,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;
|
||||
});
|
||||
|
||||
// 加密方法
|
||||
@@ -109,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;
|
||||
@@ -141,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);
|
||||
@@ -166,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}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加密类相关
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
private string _mainBundleName;
|
||||
private string _shareBundleName;
|
||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||
private bool _isAddAssetTags = false;
|
||||
|
||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
@@ -68,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;
|
||||
@@ -185,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
||||
public int BuildVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的标记列表
|
||||
/// 内置资源标签集合(首包资源标签)
|
||||
/// 注意:分号为分隔符
|
||||
/// </summary>
|
||||
public string BuildinTags;
|
||||
@@ -51,6 +51,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool AppendFileExtension = false;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源文件到StreamingAssets目录(首包资源文件)
|
||||
/// </summary>
|
||||
public bool CopyBuildinTagFiles = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加密类
|
||||
@@ -74,7 +79,7 @@ namespace YooAsset.Editor
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置标记列表
|
||||
/// 获取内置资源标签列表(首包资源标签)
|
||||
/// </summary>
|
||||
public List<string> GetBuildinTags()
|
||||
{
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool AppendFileExtension;
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝内置资源文件
|
||||
/// </summary>
|
||||
public bool CopyBuildinTagFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集着色器
|
||||
/// </summary>
|
||||
|
||||
@@ -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)
|
||||
@@ -90,7 +88,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private bool IsBuildinBundle(string[] bundleTags, List<string> buildinTags)
|
||||
{
|
||||
// 注意:没有任何标记的Bundle文件默认为内置文件
|
||||
// 注意:没有任何分类标签的Bundle文件默认为内置文件
|
||||
if (bundleTags.Length == 0)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||
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 ?
|
||||
|
||||
@@ -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,7 +129,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
_setting = EditorHelper.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
|
||||
// IPackRule
|
||||
{
|
||||
@@ -182,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>
|
||||
@@ -210,6 +257,23 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 实例类相关
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
{
|
||||
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
|
||||
return instance;
|
||||
|
||||
// 如果不存在创建类的实例
|
||||
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
|
||||
{
|
||||
instance = (IActiveRule)Activator.CreateInstance(type);
|
||||
_cacheActiveRuleInstance.Add(ruleName, instance);
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}");
|
||||
}
|
||||
}
|
||||
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||
{
|
||||
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,33 +33,34 @@ 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;
|
||||
|
||||
_collectorTypeList = new List<string>()
|
||||
{
|
||||
$"{nameof(ECollectorType.MainAssetCollector)}",
|
||||
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
||||
$"{nameof(ECollectorType.DependAssetCollector)}"
|
||||
};
|
||||
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||
|
||||
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 = YooAssetEditorSettingsData.Setting.AssetBundleCollectorUXML;
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 导入导出按钮
|
||||
@@ -71,6 +74,7 @@ namespace YooAsset.Editor
|
||||
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
||||
RefreshWindow();
|
||||
});
|
||||
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
||||
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
||||
@@ -154,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();
|
||||
}
|
||||
@@ -164,6 +187,9 @@ namespace YooAsset.Editor
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
// 注意:清空所有撤销操作
|
||||
Undo.ClearAll();
|
||||
|
||||
if (AssetBundleCollectorSettingData.IsDirty)
|
||||
AssetBundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
@@ -203,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()
|
||||
{
|
||||
@@ -229,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)
|
||||
{
|
||||
@@ -236,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();
|
||||
}
|
||||
@@ -246,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();
|
||||
}
|
||||
@@ -262,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);
|
||||
@@ -510,7 +552,7 @@ namespace YooAsset.Editor
|
||||
|
||||
try
|
||||
{
|
||||
collectAssetInfos = collector.GetAllCollectAssets(group);
|
||||
collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
@@ -550,6 +592,7 @@ namespace YooAsset.Editor
|
||||
if (selectGroup == null)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddCollector");
|
||||
AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
|
||||
FillCollectorViewData();
|
||||
}
|
||||
@@ -560,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e39f1b67d310bb54e8b1220bcf06afc4
|
||||
guid: 2cfd65b3b7663b247b2df16077f4ef17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4eff45040ac501b4fa978c46f72f2e64
|
||||
guid: aed5a1a6733b7d44ca4f6149ed5a2bb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,146 +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 DebuggerAssetListViewer _assetListViewer;
|
||||
private DebuggerBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private readonly DebugReport _debugReport = new DebugReport();
|
||||
private string _searchKeyWord;
|
||||
/// <summary>
|
||||
/// 资源包视图
|
||||
/// </summary>
|
||||
BundleView,
|
||||
}
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
|
||||
|
||||
private Label _playerName;
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private DebuggerAssetListViewer _assetListViewer;
|
||||
private DebuggerBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private DebugReport _debugReport;
|
||||
private string _searchKeyWord;
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
try
|
||||
{
|
||||
VisualElement root = rootVisualElement;
|
||||
VisualElement root = rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleDebuggerUXML;
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
visualAsset.CloneTree(root);
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
// 采样按钮
|
||||
var sampleBtn = root.Q<Button>("SampleButton");
|
||||
sampleBtn.clicked += SampleBtn_onClick;
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 视口模式菜单
|
||||
_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 sampleBtn = root.Q<Button>("SampleButton");
|
||||
sampleBtn.clicked += SampleBtn_onClick;
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
// 用户列表菜单
|
||||
_playerName = root.Q<Label>("PlayerName");
|
||||
_playerName.text = "Editor player";
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new DebuggerAssetListViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
// 视口模式菜单
|
||||
_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();
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new DebuggerBundleListViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.AssetView;
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
_assetListViewer.AttachParent(root);
|
||||
}
|
||||
catch(Exception e)
|
||||
// 加载视图
|
||||
_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());
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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:
|
||||
@@ -24,12 +24,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerAssetListViewerUXML;
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerAssetListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(DebuggerAssetListViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -173,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;
|
||||
|
||||
@@ -24,12 +24,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerBundleListViewerUXML;
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<DebuggerBundleListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(DebuggerBundleListViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -37,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;
|
||||
@@ -149,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;
|
||||
|
||||
@@ -55,12 +55,10 @@ namespace YooAsset.Editor
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleReporterUXML;
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleReporterWindow>();
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 导入按钮
|
||||
|
||||
@@ -38,46 +38,36 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML;
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterAssetListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
|
||||
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>
|
||||
|
||||
@@ -42,56 +42,46 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterBundleListViewerUXML;
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterBundleListViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(ReporterBundleListViewer)}.uxml in settings.");
|
||||
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;
|
||||
|
||||
@@ -37,12 +37,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterSummaryViewerUXML;
|
||||
_visualAsset = EditorHelper.LoadWindowUXML<ReporterSummaryViewer>();
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(ReporterSummaryViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
@@ -70,6 +68,7 @@ namespace YooAsset.Editor
|
||||
|
||||
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
|
||||
_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}"));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
_setting = YooAssetEditorSettingsHelper.LoadSettingData<ShaderVariantCollectorSetting>();
|
||||
_setting = EditorHelper.LoadSettingData<ShaderVariantCollectorSetting>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4eff45040ac501b4fa978c46f72f2e64, type: 3}
|
||||
m_Name: YooAssetEditorSettings
|
||||
m_EditorClassIdentifier:
|
||||
AssetBundleCollectorUXML: {fileID: 9197481963319205126, guid: 355c4ac5cdebddc4c8362bed6f17a79e,
|
||||
type: 3}
|
||||
AssetBundleBuilderUXML: {fileID: 9197481963319205126, guid: 28ba29adb4949284e8c48893218b0d9a,
|
||||
type: 3}
|
||||
AssetBundleDebuggerUXML: {fileID: 9197481963319205126, guid: 790db12999afd334e8fb6ba70ef0a947,
|
||||
type: 3}
|
||||
DebuggerAssetListViewerUXML: {fileID: 9197481963319205126, guid: 31c6096c1cb29b4469096b7b4942a322,
|
||||
type: 3}
|
||||
DebuggerBundleListViewerUXML: {fileID: 9197481963319205126, guid: 932a25ffd05c13c47994d66e9d73bc37,
|
||||
type: 3}
|
||||
AssetBundleReporterUXML: {fileID: 9197481963319205126, guid: 9052b72c383e95043a0c7e7f369b1ad7,
|
||||
type: 3}
|
||||
ReporterSummaryViewerUXML: {fileID: 9197481963319205126, guid: f8929271050855e42a1ccc6b14993a04,
|
||||
type: 3}
|
||||
ReporterAssetListViewerUXML: {fileID: 9197481963319205126, guid: 5f81bc15a55ee0a49a266f9d71e2372b,
|
||||
type: 3}
|
||||
ReporterBundleListViewerUXML: {fileID: 9197481963319205126, guid: 56d6dbe0d65ce334a8996beb19612989,
|
||||
type: 3}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0b43f68477734743a5f2fc507b5bda6
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,25 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class YooAssetEditorSettings : ScriptableObject
|
||||
{
|
||||
// 资源包收集
|
||||
public VisualTreeAsset AssetBundleCollectorUXML;
|
||||
|
||||
// 资源包构建
|
||||
public VisualTreeAsset AssetBundleBuilderUXML;
|
||||
|
||||
// 资源包调试
|
||||
public VisualTreeAsset AssetBundleDebuggerUXML;
|
||||
public VisualTreeAsset DebuggerAssetListViewerUXML;
|
||||
public VisualTreeAsset DebuggerBundleListViewerUXML;
|
||||
|
||||
// 构建报告
|
||||
public VisualTreeAsset AssetBundleReporterUXML;
|
||||
public VisualTreeAsset ReporterSummaryViewerUXML;
|
||||
public VisualTreeAsset ReporterAssetListViewerUXML;
|
||||
public VisualTreeAsset ReporterBundleListViewerUXML;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class YooAssetEditorSettingsData
|
||||
{
|
||||
private static YooAssetEditorSettings _setting = null;
|
||||
public static YooAssetEditorSettings Setting
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_setting == null)
|
||||
LoadEditorSettingData();
|
||||
return _setting;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置文件
|
||||
/// </summary>
|
||||
private static void LoadEditorSettingData()
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"t:{nameof(YooAssetEditorSettings)}", new[] { "Assets", "Packages" });
|
||||
if (guids.Length == 0)
|
||||
throw new System.Exception($"Not found {nameof(YooAssetEditorSettings)} file !");
|
||||
if (guids.Length != 1)
|
||||
throw new System.Exception($"Found multiple {nameof(YooAssetEditorSettings)} files !");
|
||||
|
||||
string settingFilePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
_setting = AssetDatabase.LoadAssetAtPath<YooAssetEditorSettings>(settingFilePath);
|
||||
Debug.Log($"Load {nameof(YooAssetEditorSettings)}.asset ok !");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class YooAssetEditorSettingsHelper
|
||||
{
|
||||
/// <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)
|
||||
throw new System.Exception($"Found multiple {settingType.Name} files !");
|
||||
|
||||
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
|
||||
return setting;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,28 +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);
|
||||
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 loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, bool autoReleaseGameObjectHandle, IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||
{
|
||||
_simulationOnEditor = simulationOnEditor;
|
||||
_loadingMaxNumber = loadingMaxNumber;
|
||||
AutoReleaseGameObjectHandle = autoReleaseGameObjectHandle;
|
||||
DecryptionServices = decryptionServices;
|
||||
BundleServices = bundleServices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// 更新
|
||||
/// </summary>
|
||||
public static void Update()
|
||||
{
|
||||
@@ -63,11 +66,29 @@ 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 (AutoReleaseGameObjectHandle)
|
||||
{
|
||||
CheckAutoReleaseGameObjectHandle();
|
||||
}
|
||||
|
||||
if (_simulationOnEditor)
|
||||
{
|
||||
for (int i = _providers.Count - 1; i >= 0; i--)
|
||||
@@ -208,6 +229,29 @@ namespace YooAsset
|
||||
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 providerGUID = provider.MainAssetInfo.ProviderGUID;
|
||||
@@ -321,9 +365,10 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
@@ -334,8 +379,8 @@ namespace YooAsset
|
||||
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)
|
||||
@@ -347,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.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
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,20 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 句柄是否有效
|
||||
/// </summary>
|
||||
public bool IsValidNoWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Provider != null && Provider.IsDestroyed == false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放句柄
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -39,7 +40,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if(MainBundleInfo.IsInvalid)
|
||||
if (MainBundleInfo.IsInvalid)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
@@ -158,6 +159,21 @@ namespace YooAsset
|
||||
Status = EStatus.Failed;
|
||||
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
|
||||
{
|
||||
@@ -185,7 +201,7 @@ namespace YooAsset
|
||||
if (_isShowWaitForAsyncError == false)
|
||||
{
|
||||
_isShowWaitForAsyncError = true;
|
||||
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {MainBundleInfo.BundleName} States : {Status}");
|
||||
YooLogger.Error($"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.BundleName} from remote with sync load method !");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -118,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 !");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace YooAsset
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
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;
|
||||
|
||||
@@ -203,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
|
||||
{
|
||||
@@ -235,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();
|
||||
}
|
||||
@@ -342,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)
|
||||
{
|
||||
@@ -405,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();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
|
||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||
bundleInfo.Status = OwnerBundle.Status;
|
||||
bundleInfo.Status = (int)OwnerBundle.Status;
|
||||
output.Add(bundleInfo);
|
||||
|
||||
DependBundleGroup.GetBundleDebugInfos(output);
|
||||
|
||||
@@ -59,19 +59,6 @@ namespace YooAsset
|
||||
// 2. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
if (AssetObject != null)
|
||||
{
|
||||
if (UnityEditor.AssetDatabase.IsMainAsset(AssetObject) == false)
|
||||
{
|
||||
AssetObject = null;
|
||||
Status = EStatus.Fail;
|
||||
LastError = $"The loaded asset object is not main asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
|
||||
if (Status == EStatus.Fail)
|
||||
{
|
||||
|
||||
@@ -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:
|
||||
@@ -16,13 +16,16 @@ namespace YooAsset
|
||||
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 = 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,17 +148,18 @@ 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)
|
||||
{
|
||||
return CheckContentIntegrity(_verifyLevel, filePath, size, crc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证文件完整性
|
||||
/// </summary>
|
||||
public static bool CheckContentIntegrity(EVerifyLevel verifyLevel, string filePath, long size, string crc)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -166,10 +172,17 @@ namespace YooAsset
|
||||
return false;
|
||||
|
||||
// 再验证文件CRC
|
||||
string fileCRC = HashUtility.FileCRC32(filePath);
|
||||
return fileCRC == crc;
|
||||
if (verifyLevel == EVerifyLevel.High)
|
||||
{
|
||||
string fileCRC = HashUtility.FileCRC32(filePath);
|
||||
return fileCRC == crc;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(Exception)
|
||||
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,6 +45,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁异步操作系统
|
||||
/// </summary>
|
||||
public static void DestroyAll()
|
||||
{
|
||||
_operations.Clear();
|
||||
_watch = null;
|
||||
_maxTimeSlice = 0;
|
||||
_frameTime = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始处理异步操作类
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class AssetInfo
|
||||
@@ -41,11 +40,16 @@ namespace YooAsset
|
||||
/// </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>
|
||||
@@ -63,6 +67,7 @@ namespace YooAsset
|
||||
|
||||
_patchAsset = patchAsset;
|
||||
AssetType = assetType;
|
||||
Address = patchAsset.Address;
|
||||
AssetPath = patchAsset.AssetPath;
|
||||
Error = string.Empty;
|
||||
}
|
||||
@@ -73,6 +78,7 @@ namespace YooAsset
|
||||
|
||||
_patchAsset = patchAsset;
|
||||
AssetType = null;
|
||||
Address = patchAsset.Address;
|
||||
AssetPath = patchAsset.AssetPath;
|
||||
Error = string.Empty;
|
||||
}
|
||||
@@ -80,6 +86,7 @@ namespace YooAsset
|
||||
{
|
||||
_patchAsset = null;
|
||||
AssetType = null;
|
||||
Address = string.Empty;
|
||||
AssetPath = string.Empty;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -195,6 +208,22 @@ namespace YooAsset
|
||||
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>
|
||||
@@ -114,11 +118,13 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
||||
public int ResourceVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的标记列表
|
||||
/// 内置资源的标签列表(首包资源)
|
||||
/// </summary>
|
||||
public string BuildinTags;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace YooAsset
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
DownloadSystem.DestroyAll();
|
||||
YooAssets.InternalDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool LocationToLower = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自动释放游戏对象所属资源句柄
|
||||
/// 说明:通过资源句柄实例化的游戏对象在销毁之后,会自动释放所属资源句柄。
|
||||
/// </summary>
|
||||
public bool AutoReleaseGameObjectHandle = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位服务接口
|
||||
/// </summary>
|
||||
@@ -104,6 +110,11 @@ namespace YooAsset
|
||||
/// 启用断点续传功能的文件大小
|
||||
/// </summary>
|
||||
public int BreakpointResumeFileSize = int.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件校验等级
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel = EVerifyLevel.High;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +129,14 @@ namespace YooAsset
|
||||
private static HostPlayModeImpl _hostPlayModeImpl;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经初始化
|
||||
/// </summary>
|
||||
public static bool IsInitialized
|
||||
{
|
||||
get { return _isInitialize; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
@@ -143,6 +162,10 @@ namespace YooAsset
|
||||
UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]");
|
||||
driverGo.AddComponent<YooAssetDriver>();
|
||||
UnityEngine.Object.DontDestroyOnLoad(driverGo);
|
||||
|
||||
#if DEBUG
|
||||
driverGo.AddComponent<RemoteDebuggerInRuntime>();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,7 +204,7 @@ namespace YooAsset
|
||||
throw new Exception($"{EPlayMode.HostPlayMode} not supports WebGL platform !");
|
||||
#else
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize);
|
||||
DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize, hostPlayModeParameters.VerifyLevel);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -191,7 +214,7 @@ namespace YooAsset
|
||||
{
|
||||
_editorSimulateModeImpl = new EditorSimulateModeImpl();
|
||||
_bundleServices = _editorSimulateModeImpl;
|
||||
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.AutoReleaseGameObjectHandle, parameters.DecryptionServices, _bundleServices);
|
||||
var editorSimulateModeParameters = parameters as EditorSimulateModeParameters;
|
||||
initializeOperation = _editorSimulateModeImpl.InitializeAsync(
|
||||
editorSimulateModeParameters.LocationToLower,
|
||||
@@ -201,14 +224,14 @@ namespace YooAsset
|
||||
{
|
||||
_offlinePlayModeImpl = new OfflinePlayModeImpl();
|
||||
_bundleServices = _offlinePlayModeImpl;
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.AutoReleaseGameObjectHandle, parameters.DecryptionServices, _bundleServices);
|
||||
initializeOperation = _offlinePlayModeImpl.InitializeAsync(parameters.LocationToLower);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
_hostPlayModeImpl = new HostPlayModeImpl();
|
||||
_bundleServices = _hostPlayModeImpl;
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
|
||||
AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.AutoReleaseGameObjectHandle, parameters.DecryptionServices, _bundleServices);
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = _hostPlayModeImpl.InitializeAsync(
|
||||
hostPlayModeParameters.LocationToLower,
|
||||
@@ -409,6 +432,17 @@ namespace YooAsset
|
||||
DebugCheckInitialize();
|
||||
return _bundleServices.GetAssetInfos(tags);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源路径
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
/// <returns>如果location地址无效,则返回空字符串</returns>
|
||||
public static string GetAssetPath(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _locationServices.ConvertLocationToAssetPath(location);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 场景加载
|
||||
@@ -519,7 +553,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : class
|
||||
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||
@@ -554,7 +588,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public static AssetOperationHandle LoadAssetAsync<TObject>(string location)
|
||||
public static AssetOperationHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||
@@ -599,7 +633,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location)
|
||||
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||
@@ -634,7 +668,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源类型</typeparam>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location)
|
||||
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
|
||||
@@ -922,29 +956,30 @@ namespace YooAsset
|
||||
#endregion
|
||||
|
||||
#region 内部方法
|
||||
internal static void InternalDestroy()
|
||||
{
|
||||
_isInitialize = false;
|
||||
_initializeError = string.Empty;
|
||||
_initializeStatus = EOperationStatus.None;
|
||||
|
||||
_bundleServices = null;
|
||||
_locationServices = null;
|
||||
_editorSimulateModeImpl = null;
|
||||
_offlinePlayModeImpl = null;
|
||||
_hostPlayModeImpl = null;
|
||||
|
||||
OperationSystem.DestroyAll();
|
||||
DownloadSystem.DestroyAll();
|
||||
AssetSystem.DestroyAll();
|
||||
YooLogger.Log("YooAssets destroy all !");
|
||||
}
|
||||
internal static void InternalUpdate()
|
||||
{
|
||||
// 更新异步操作系统
|
||||
OperationSystem.Update();
|
||||
|
||||
// 更新下载管理系统
|
||||
DownloadSystem.Update();
|
||||
|
||||
// 更新资源系统
|
||||
AssetSystem.Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试信息
|
||||
/// </summary>
|
||||
internal static void GetDebugReport(DebugReport report)
|
||||
{
|
||||
if (report == null)
|
||||
YooLogger.Error($"{nameof(DebugReport)} is null");
|
||||
|
||||
AssetSystem.GetDebugReport(report);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址转换为资源完整路径
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.0.9",
|
||||
"version": "1.1.0",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system",
|
||||
"author": {
|
||||
|
||||
@@ -175,6 +175,9 @@ private object LoadFunc(string name, string extension, System.Type type, out Des
|
||||
return handle.AssetObject;
|
||||
}
|
||||
|
||||
// 执行FairyGUI的添加包函数
|
||||
UIPackage.AddPackage(name, LoadFunc);
|
||||
|
||||
// 释放资源句柄列表
|
||||
private void ReleaseHandles()
|
||||
{
|
||||
|
||||
@@ -9,3 +9,4 @@
|
||||
- Wales-丁 (709501148)
|
||||
- L (401419353)
|
||||
- 秀 (1025466218)
|
||||
- martin (643087149)
|
||||
|
||||
Reference in New Issue
Block a user