Compare commits

...

22 Commits
1.0.8 ... 1.0.9

Author SHA1 Message Date
hevinci
76929cc015 Update CHANGELOG.md 2022-05-14 12:47:16 +08:00
hevinci
cde0f4bcd8 Update package.json 2022-05-14 12:47:12 +08:00
hevinci
8dc0560537 Optimized the loading method of the setting file
优化了配置文件的加载方式和途径。
2022-05-13 23:53:19 +08:00
hevinci
a054740de6 Optimize assetbundle build parameters
优化了资源包的构建参数:始终开启DisableLoadAssetByFileName
2022-05-13 21:58:23 +08:00
hevinci
029b850d6b Update asset system
新增获取所有子资源对象的方法。
2022-05-13 14:57:49 +08:00
hevinci
8260653eae Merge branch 'main' of https://github.com/tuyoogame/YooAsset 2022-05-13 14:29:36 +08:00
hevinci
bd7b9b5c44 Update README.md 2022-05-13 14:29:28 +08:00
hevinci
8f33a391f8 Update document 2022-05-13 14:29:22 +08:00
何冠峰
2f9d3a9f11 Merge pull request #11 from jiangguilong2000/main
feat(AssetSystem): 获取图集下所有的精灵对象集合
2022-05-13 14:23:23 +08:00
Allen Jiang
316294f449 feat(AssetSystem): 获取图集下所有的精灵对象集合 2022-05-13 14:08:36 +08:00
hevinci
09fac3bd64 Add warning when asset path is invalid. 2022-05-12 23:13:21 +08:00
hevinci
2da81212b4 Update document 2022-05-12 12:37:48 +08:00
hevinci
4cad587609 Optimized asset system and patch system framework
优化了资源定位不正确导致的错误报告方式。
YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
YooAssets.GetBundleInfo()已经移除方法。
YooAssets.IsNeedDownloadFromRemote()新增加方法。
2022-05-11 16:48:17 +08:00
hevinci
67eeae31c7 Update patch manifest
更新资源清单:资源对象增加分类标签。
2022-05-11 16:23:31 +08:00
hevinci
ae465a47a9 Simulate build use default build version.
模拟构建模式使用一个默认的资源版本号。
2022-05-11 16:13:51 +08:00
hevinci
23b59f6ad6 Update document 2022-05-09 22:14:49 +08:00
hevinci
09e3483e0a Update README.md 2022-05-09 22:13:20 +08:00
hevinci
b3f4e9ae6e Update document 2022-05-09 22:13:14 +08:00
hevinci
79efe6237d Update asset system 2022-05-09 21:18:15 +08:00
hevinci
bf0f479234 Update download system 2022-05-09 18:44:49 +08:00
hevinci
ece1dab28b Update README.md 2022-05-08 22:21:17 +08:00
hevinci
b913b5c20c Update document 2022-05-08 22:21:13 +08:00
96 changed files with 1480 additions and 963 deletions

View File

@@ -2,6 +2,42 @@
All notable changes to this package will be documented in this file. All notable changes to this package will be documented in this file.
## [1.0.9] - 2022-05-14
### Fixed
- 修复了YooAssets.GetAssetInfos(string Tag)方法返回了无关的资源信息的问题。
### Changed
- 编辑器下的模拟运行模式,不再依赖配置里的构建版本。
- 更新资源清单结构,资源对象类增加分类标签。
- 优化了资源工具相关配置文件的加载方式和途径,这些配置文件可以放置在任何目录下。
- 优化了Location无效后的错误报告方式。
- 优化了资源包的构建参数现在始终开启DisableLoadAssetByFileName帮助减小运行时的内存。
- YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
### Added
- 新增YooAssets.IsNeedDownloadFromRemote()方法。
````c#
public static bool IsNeedDownloadFromRemote(string location);
````
- 新增获取所有子资源对象的方法。
````c#
class SubAssetsOperationHandle
{
public TObject[] GetSubAssetObjects<TObject>();
}
````
### Removed
- YooAssets.GetBundleInfo()方法已经移除。
## [1.0.8] - 2022-05-08 ## [1.0.8] - 2022-05-08
### Fixed ### Fixed

View File

@@ -30,7 +30,7 @@ namespace YooAsset.Editor
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget); PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
if (parameters.BuildMode == EBuildMode.DryRunBuild) if (parameters.BuildMode == EBuildMode.DryRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}"; PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
else if(parameters.BuildMode == EBuildMode.SimulateBuild) else if (parameters.BuildMode == EBuildMode.SimulateBuild)
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}"; PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
} }
@@ -54,9 +54,7 @@ namespace YooAsset.Editor
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it. opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.SimulateBuild) if (Parameters.BuildMode == EBuildMode.SimulateBuild)
{
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
}
if (Parameters.BuildMode == EBuildMode.DryRunBuild) if (Parameters.BuildMode == EBuildMode.DryRunBuild)
{ {
@@ -71,17 +69,13 @@ namespace YooAsset.Editor
if (Parameters.BuildMode == EBuildMode.ForceRebuild) if (Parameters.BuildMode == EBuildMode.ForceRebuild)
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
if (Parameters.AppendHash)
opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name
if (Parameters.DisableWriteTypeTree) if (Parameters.DisableWriteTypeTree)
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree). opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
if (Parameters.IgnoreTypeTreeChanges) if (Parameters.IgnoreTypeTreeChanges)
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check. opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
if (Parameters.DisableLoadAssetByFileName)
{ opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name. opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
}
return opt; return opt;
} }

View File

@@ -24,22 +24,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 _setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleBuilderSetting>();
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleBuilderSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(settingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
}
} }
/// <summary> /// <summary>

View File

@@ -32,21 +32,19 @@ namespace YooAsset.Editor
public void CreateGUI() public void CreateGUI()
{ {
VisualElement root = this.rootVisualElement;
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
try try
{ {
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleBuilderUXML;
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml in settings.");
return;
}
visualAsset.CloneTree(root);
_buildTarget = EditorUserBuildSettings.activeBuildTarget; _buildTarget = EditorUserBuildSettings.activeBuildTarget;
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes(); _encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList(); _encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();

View File

@@ -16,8 +16,7 @@ namespace YooAsset.Editor
buildParameters.OutputRoot = defaultOutputRoot; buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild; buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion; buildParameters.BuildVersion = 999;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();

View File

@@ -10,7 +10,8 @@ namespace YooAsset.Editor
private string _mainBundleName; private string _mainBundleName;
private string _shareBundleName; private string _shareBundleName;
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>(); private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
private bool _isAddAssetTags = false;
/// <summary> /// <summary>
/// 收集器类型 /// 收集器类型
/// </summary> /// </summary>
@@ -37,10 +38,15 @@ namespace YooAsset.Editor
public bool IsShaderAsset { private set; get; } public bool IsShaderAsset { private set; get; }
/// <summary> /// <summary>
/// 资源分类标签列表 /// 资源分类标签
/// </summary> /// </summary>
public readonly List<string> AssetTags = new List<string>(); public readonly List<string> AssetTags = new List<string>();
/// <summary>
/// 资源包的分类标签
/// </summary>
public readonly List<string> BundleTags = new List<string>();
/// <summary> /// <summary>
/// 依赖的所有资源 /// 依赖的所有资源
/// 注意:包括零依赖资源和冗余资源(资源包名无效) /// 注意:包括零依赖资源和冗余资源(资源包名无效)
@@ -89,10 +95,15 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 添加资源分类标签 /// 添加资源分类标签
/// 说明:原始定义的资源分类标签
/// </summary> /// </summary>
public void AddAssetTags(List<string> tags) public void AddAssetTags(List<string> tags)
{ {
if (_isAddAssetTags)
throw new Exception("Should never get here !");
_isAddAssetTags = true;
foreach (var tag in tags) foreach (var tag in tags)
{ {
if (AssetTags.Contains(tag) == false) if (AssetTags.Contains(tag) == false)
@@ -101,6 +112,21 @@ namespace YooAsset.Editor
} }
} }
} }
/// <summary>
/// 添加资源包的分类标签
/// 说明:传染算法统计到的分类标签
/// </summary>
public void AddBundleTags(List<string> tags)
{
foreach (var tag in tags)
{
if (BundleTags.Contains(tag) == false)
{
BundleTags.Add(tag);
}
}
}
/// <summary> /// <summary>
/// 资源包名是否存在 /// 资源包名是否存在

View File

@@ -68,14 +68,14 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源标签列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags() public string[] GetBundleTags()
{ {
List<string> result = new List<string>(BuildinAssets.Count); List<string> result = new List<string>(BuildinAssets.Count);
foreach (var assetInfo in BuildinAssets) foreach (var assetInfo in BuildinAssets)
{ {
foreach (var assetTag in assetInfo.AssetTags) foreach (var assetTag in assetInfo.BundleTags)
{ {
if (result.Contains(assetTag) == false) if (result.Contains(assetTag) == false)
result.Add(assetTag); result.Add(assetTag);

View File

@@ -55,13 +55,13 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取AssetBundle内包含的标记列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags(string bundleName) public string[] GetBundleTags(string bundleName)
{ {
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
{ {
return bundleInfo.GetAssetTags(); return bundleInfo.GetBundleTags();
} }
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}"); throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
} }

View File

@@ -18,7 +18,7 @@ namespace YooAsset.Editor
// 1. 检测配置合法性 // 1. 检测配置合法性
AssetBundleCollectorSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有主动收集的资源 // 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode); List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
// 3. 剔除未被引用的依赖资源 // 3. 剔除未被引用的依赖资源
@@ -36,13 +36,15 @@ namespace YooAsset.Editor
allCollectAssets.Remove(removeValue); allCollectAssets.Remove(removeValue);
} }
// 4. 录入主动收集的资源 // 4. 录入所有收集器收集的资源
foreach (var collectAssetInfo in allCollectAssets) foreach (var collectAssetInfo in allCollectAssets)
{ {
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
{ {
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset); var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo); buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
} }
else else
@@ -58,13 +60,13 @@ namespace YooAsset.Editor
{ {
if (buildAssetDic.ContainsKey(dependAssetPath)) if (buildAssetDic.ContainsKey(dependAssetPath))
{ {
buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags); buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
} }
else else
{ {
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
buildAssetDic.Add(dependAssetPath, buildAssetInfo); buildAssetDic.Add(dependAssetPath, buildAssetInfo);
} }
@@ -92,7 +94,7 @@ namespace YooAsset.Editor
pair.Value.CalculateFullBundleName(); pair.Value.CalculateFullBundleName();
} }
// 8. 移除参与构建的资源 // 8. 移除参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic) foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{ {

View File

@@ -46,12 +46,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool EnableAddressable = false; public bool EnableAddressable = false;
/// <summary>
/// 启用自动分包机制
/// 说明:自动分包机制可以实现资源零冗余
/// </summary>
public bool EnableAutoCollect = true;
/// <summary> /// <summary>
/// 追加文件扩展名 /// 追加文件扩展名
/// </summary> /// </summary>
@@ -68,11 +62,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.Uncompressed; public ECompressOption CompressOption = ECompressOption.Uncompressed;
/// <summary>
/// 文件名附加上哈希值
/// </summary>
public bool AppendHash = false;
/// <summary> /// <summary>
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率) /// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
/// </summary> /// </summary>
@@ -83,11 +72,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool IgnoreTypeTreeChanges = true; public bool IgnoreTypeTreeChanges = true;
/// <summary>
/// 禁用名称查找资源(可以降内存并提高加载效率)
/// </summary>
public bool DisableLoadAssetByFileName = false;
/// <summary> /// <summary>
/// 获取内置标记列表 /// 获取内置标记列表

View File

@@ -22,6 +22,11 @@ namespace YooAsset.Editor
/// 说明Meta文件记录的GUID /// 说明Meta文件记录的GUID
/// </summary> /// </summary>
public string AssetGUID; public string AssetGUID;
/// <summary>
/// 资源的分类标签
/// </summary>
public string[] AssetTags;
/// <summary> /// <summary>
/// 所属资源包名称 /// 所属资源包名称

View File

@@ -48,11 +48,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool EnableAddressable; public bool EnableAddressable;
/// <summary>
/// 启用自动分包机制
/// </summary>
public bool EnableAutoCollect;
/// <summary> /// <summary>
/// 追加文件扩展名 /// 追加文件扩展名
/// </summary> /// </summary>
@@ -75,10 +70,8 @@ namespace YooAsset.Editor
// 构建参数 // 构建参数
public ECompressOption CompressOption; public ECompressOption CompressOption;
public bool AppendHash;
public bool DisableWriteTypeTree; public bool DisableWriteTypeTree;
public bool IgnoreTypeTreeChanges; public bool IgnoreTypeTreeChanges;
public bool DisableLoadAssetByFileName;
// 构建结果 // 构建结果
public int AssetFileTotalCount; public int AssetFileTotalCount;

View File

@@ -70,7 +70,7 @@ namespace YooAsset.Editor
string hash = GetFileHash(filePath, standardBuild); string hash = GetFileHash(filePath, standardBuild);
string crc32 = GetFileCRC(filePath, standardBuild); string crc32 = GetFileCRC(filePath, standardBuild);
long size = GetFileSize(filePath, standardBuild); long size = GetFileSize(filePath, standardBuild);
string[] tags = buildMapContext.GetAssetTags(bundleName); string[] tags = buildMapContext.GetBundleTags(bundleName);
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isBuildin = IsBuildinBundle(tags, buildinTags);
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;
@@ -141,6 +141,7 @@ namespace YooAsset.Editor
else else
patchAsset.Address = string.Empty; patchAsset.Address = string.Empty;
patchAsset.AssetPath = assetInfo.AssetPath; patchAsset.AssetPath = assetInfo.AssetPath;
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest); patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest); patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
result.Add(patchAsset); result.Add(patchAsset);

View File

@@ -41,7 +41,6 @@ namespace YooAsset.Editor
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders; buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
@@ -50,10 +49,8 @@ namespace YooAsset.Editor
// 构建参数 // 构建参数
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
// 构建结果 // 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
@@ -75,6 +72,7 @@ namespace YooAsset.Editor
ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
reportAssetInfo.Address = patchAsset.Address; reportAssetInfo.Address = patchAsset.Address;
reportAssetInfo.AssetPath = patchAsset.AssetPath; reportAssetInfo.AssetPath = patchAsset.AssetPath;
reportAssetInfo.AssetTags = patchAsset.AssetTags;
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath); reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes; reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;

View File

@@ -105,22 +105,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 _setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleCollectorSetting>();
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleCollectorSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleCollectorSetting>(settingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(AssetBundleCollectorSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleCollectorSetting>();
EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(AssetBundleCollectorSetting)}.asset ok");
}
// IPackRule // IPackRule
{ {

View File

@@ -37,8 +37,6 @@ namespace YooAsset.Editor
Undo.undoRedoPerformed -= RefreshWindow; Undo.undoRedoPerformed -= RefreshWindow;
Undo.undoRedoPerformed += RefreshWindow; Undo.undoRedoPerformed += RefreshWindow;
VisualElement root = this.rootVisualElement;
_collectorTypeList = new List<string>() _collectorTypeList = new List<string>()
{ {
$"{nameof(ECollectorType.MainAssetCollector)}", $"{nameof(ECollectorType.MainAssetCollector)}",
@@ -49,19 +47,19 @@ namespace YooAsset.Editor
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames(); _packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames(); _filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleCollector/{nameof(AssetBundleCollectorWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
try try
{ {
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleCollectorUXML;
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml in settings.");
return;
}
visualAsset.CloneTree(root);
// 导入导出按钮 // 导入导出按钮
var exportBtn = root.Q<Button>("ExportButton"); var exportBtn = root.Q<Button>("ExportButton");
exportBtn.clicked += ExportBtn_clicked; exportBtn.clicked += ExportBtn_clicked;

View File

@@ -1,4 +1,5 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
@@ -37,8 +38,8 @@ namespace YooAsset.Editor
} }
private ToolbarMenu _viewModeMenu; private ToolbarMenu _viewModeMenu;
private AssetListDebuggerViewer _assetListViewer; private DebuggerAssetListViewer _assetListViewer;
private BundleListDebuggerViewer _bundleListViewer; private DebuggerBundleListViewer _bundleListViewer;
private EViewMode _viewMode; private EViewMode _viewMode;
private readonly DebugReport _debugReport = new DebugReport(); private readonly DebugReport _debugReport = new DebugReport();
@@ -47,45 +48,50 @@ namespace YooAsset.Editor
public void CreateGUI() public void CreateGUI()
{ {
VisualElement root = rootVisualElement; try
{
VisualElement root = rootVisualElement;
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleDebuggerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml"; if (visualAsset == null)
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); {
if (visualAsset == null) Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml in settings.");
{ return;
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml : {uxml}"); }
return; visualAsset.CloneTree(root);
// 采样按钮
var sampleBtn = root.Q<Button>("SampleButton");
sampleBtn.clicked += SampleBtn_onClick;
// 视口模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_assetListViewer = new DebuggerAssetListViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new DebuggerBundleListViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.AssetView;
_viewModeMenu.text = EViewMode.AssetView.ToString();
_assetListViewer.AttachParent(root);
}
catch(Exception e)
{
Debug.LogError(e.ToString());
} }
visualAsset.CloneTree(root);
// 采样按钮
var sampleBtn = root.Q<Button>("SampleButton");
sampleBtn.clicked += SampleBtn_onClick;
// 视口模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_assetListViewer = new AssetListDebuggerViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new BundleListDebuggerViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.AssetView;
_viewModeMenu.text = EViewMode.AssetView.ToString();
_assetListViewer.AttachParent(root);
} }
private void SampleBtn_onClick() private void SampleBtn_onClick()
{ {

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class AssetListDebuggerViewer internal class DebuggerAssetListViewer
{ {
private VisualTreeAsset _visualAsset; private VisualTreeAsset _visualAsset;
private TemplateContainer _root; private TemplateContainer _root;
@@ -23,13 +23,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = YooAssetEditorSettingsData.Setting.DebuggerAssetListViewerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(DebuggerAssetListViewer)}.uxml in settings.");
return; return;
} }
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class BundleListDebuggerViewer internal class DebuggerBundleListViewer
{ {
private VisualTreeAsset _visualAsset; private VisualTreeAsset _visualAsset;
private TemplateContainer _root; private TemplateContainer _root;
@@ -24,12 +24,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = YooAssetEditorSettingsData.Setting.DebuggerBundleListViewerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(DebuggerBundleListViewer)}.uxml in settings.");
return; return;
} }
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();

View File

@@ -1,4 +1,5 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEditor.UIElements; using UnityEditor.UIElements;
@@ -37,9 +38,9 @@ namespace YooAsset.Editor
} }
private ToolbarMenu _viewModeMenu; private ToolbarMenu _viewModeMenu;
private SummaryReporterViewer _summaryViewer; private ReporterSummaryViewer _summaryViewer;
private AssetListReporterViewer _assetListViewer; private ReporterAssetListViewer _assetListViewer;
private BundleListReporterViewer _bundleListViewer; private ReporterBundleListViewer _bundleListViewer;
private EViewMode _viewMode; private EViewMode _viewMode;
private BuildReport _buildReport; private BuildReport _buildReport;
@@ -49,49 +50,54 @@ namespace YooAsset.Editor
public void CreateGUI() public void CreateGUI()
{ {
VisualElement root = this.rootVisualElement; try
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}"); VisualElement root = this.rootVisualElement;
return;
// 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleReporterUXML;
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml in settings.");
return;
}
visualAsset.CloneTree(root);
// 导入按钮
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
// 视图模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_summaryViewer = new ReporterSummaryViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new ReporterAssetListViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new ReporterBundleListViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
}
catch (Exception e)
{
Debug.LogError(e.ToString());
} }
visualAsset.CloneTree(root);
// 导入按钮
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
// 视图模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_summaryViewer = new SummaryReporterViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new AssetListReporterViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new BundleListReporterViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
} }
public void OnDestroy() public void OnDestroy()
{ {

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class AssetListReporterViewer internal class ReporterAssetListViewer
{ {
private enum ESortMode private enum ESortMode
{ {
@@ -38,12 +38,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
return; return;
} }

View File

@@ -10,7 +10,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class BundleListReporterViewer internal class ReporterBundleListViewer
{ {
private enum ESortMode private enum ESortMode
{ {
@@ -42,12 +42,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = YooAssetEditorSettingsData.Setting.ReporterBundleListViewerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(ReporterBundleListViewer)}.uxml in settings.");
return; return;
} }

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class SummaryReporterViewer internal class ReporterSummaryViewer
{ {
private class ItemWrapper private class ItemWrapper
{ {
@@ -37,12 +37,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = YooAssetEditorSettingsData.Setting.ReporterSummaryViewerUXML;
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(SummaryReporterViewer)}.uxml : {uxml}"); Debug.LogError($"Not found {nameof(ReporterSummaryViewer)}.uxml in settings.");
return; return;
} }
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
@@ -71,7 +69,6 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}")); _items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}")); _items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("启用自动分包机制", $"{buildReport.Summary.EnableAutoCollect}"));
_items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}")); _items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}"));
_items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}")); _items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}"));
_items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}")); _items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}"));
@@ -80,10 +77,8 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper(string.Empty, string.Empty)); _items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("构建参数", string.Empty)); _items.Add(new ItemWrapper("构建参数", string.Empty));
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}")); _items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
_items.Add(new ItemWrapper("AppendHash", $"{buildReport.Summary.AppendHash}"));
_items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}")); _items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}"));
_items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}")); _items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}"));
_items.Add(new ItemWrapper("DisableLoadAssetByFileName", $"{buildReport.Summary.DisableLoadAssetByFileName}"));
_items.Add(new ItemWrapper(string.Empty, string.Empty)); _items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("构建结果", string.Empty)); _items.Add(new ItemWrapper("构建结果", string.Empty));

View File

@@ -1,6 +1,7 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
#if UNITY_2019 #if UNITY_2019
public static partial class UnityEngine_UIElements_ListView_Extension public static partial class UnityEngine_UIElements_ListView_Extension
{ {
@@ -20,4 +21,5 @@ namespace YooAsset.Editor
} }
} }
#endif #endif
} }

View File

@@ -462,9 +462,6 @@ namespace YooAsset.Editor
#endregion #endregion
#region #region
private static string YooAssetSourcePath;
private static string YooAssetSettingPath;
/// <summary> /// <summary>
/// 获取规范的路径 /// 获取规范的路径
/// </summary> /// </summary>
@@ -473,83 +470,6 @@ namespace YooAsset.Editor
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式 return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
} }
/// <summary>
/// 获取资源框架源码路径
/// </summary>
public static string GetYooAssetSourcePath()
{
if (string.IsNullOrEmpty(YooAssetSourcePath) == false)
{
if (Directory.Exists(YooAssetSourcePath))
return YooAssetSourcePath;
}
// 从Pakcages目录下搜索
string packagesPath = "Packages/com.tuyoogame.yooasset/README.md";
var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset));
if (obj != null)
{
YooAssetSourcePath = "Packages/com.tuyoogame.yooasset/";
return YooAssetSourcePath;
}
// 从Assets目录下搜索
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories);
if (allDirectorys.Length == 0)
{
Debug.LogError("Not found YooAsset package !");
return string.Empty;
}
string targetDirectory = string.Empty;
foreach (var directory in allDirectorys)
{
string asmdefFilePath = $"{directory}/Editor/YooAsset.Editor.asmdef";
if (File.Exists(asmdefFilePath))
{
targetDirectory = directory;
break;
}
}
if (string.IsNullOrEmpty(targetDirectory))
{
Debug.LogError("Should never get here !");
return string.Empty;
}
YooAssetSourcePath = AbsolutePathToAssetPath(targetDirectory);
return YooAssetSourcePath;
}
/// <summary>
/// 获取资源框架配置路径
/// </summary>
public static string GetYooAssetSettingPath()
{
if (string.IsNullOrEmpty(YooAssetSettingPath) == false)
{
if (Directory.Exists(YooAssetSettingPath))
return YooAssetSettingPath;
}
// 从Assets目录下搜索
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAssetSetting", SearchOption.AllDirectories);
if (allDirectorys.Length == 0)
{
YooAssetSettingPath = "Assets/YooAssetSetting";
return YooAssetSettingPath;
}
string targetDirectory = allDirectorys[0];
if (allDirectorys.Length != 1)
{
Debug.LogError("Found multiple YooAssetSetting folder !");
}
YooAssetSettingPath = AbsolutePathToAssetPath(targetDirectory);
return YooAssetSettingPath;
}
/// <summary> /// <summary>
/// 获取项目工程路径 /// 获取项目工程路径
/// </summary> /// </summary>
@@ -566,7 +486,7 @@ namespace YooAsset.Editor
public static string AbsolutePathToAssetPath(string absolutePath) public static string AbsolutePathToAssetPath(string absolutePath)
{ {
string content = GetRegularPath(absolutePath); string content = GetRegularPath(absolutePath);
return Substring(content, "Assets", true); return Substring(content, "Assets/", true);
} }
/// <summary> /// <summary>
@@ -630,7 +550,6 @@ namespace YooAsset.Editor
else else
return content.Substring(startIndex + key.Length); return content.Substring(startIndex + key.Length);
} }
#endregion #endregion
} }
} }

View File

@@ -25,22 +25,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 _setting = YooAssetEditorSettingsHelper.LoadSettingData<ShaderVariantCollectorSetting>();
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(ShaderVariantCollectorSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<ShaderVariantCollectorSetting>(settingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<ShaderVariantCollectorSetting>();
EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(ShaderVariantCollectorSetting)}.asset ok");
}
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,32 @@
%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}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b0b43f68477734743a5f2fc507b5bda6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4eff45040ac501b4fa978c46f72f2e64
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
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 !");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e39f1b67d310bb54e8b1220bcf06afc4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
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;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2d701e695ac3fe4cbe25d43dde05944
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@@ -12,16 +11,8 @@ namespace YooAsset
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000); private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000); private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100); private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private static bool _simulationOnEditor;
/// <summary> private static int _loadingMaxNumber;
/// 在编辑器下模拟运行
/// </summary>
public static bool SimulationOnEditor { private set; get; }
/// <summary>
/// 运行时的最大加载个数
/// </summary>
public static int AssetLoadingMaxNumber { private set; get; }
public static IDecryptionServices DecryptionServices { private set; get; } public static IDecryptionServices DecryptionServices { private set; get; }
public static IBundleServices BundleServices { private set; get; } public static IBundleServices BundleServices { private set; get; }
@@ -31,10 +22,10 @@ namespace YooAsset
/// 初始化资源系统 /// 初始化资源系统
/// 注意在使用AssetSystem之前需要初始化 /// 注意在使用AssetSystem之前需要初始化
/// </summary> /// </summary>
public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices) public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
{ {
SimulationOnEditor = simulationOnEditor; _simulationOnEditor = simulationOnEditor;
AssetLoadingMaxNumber = assetLoadingMaxNumber; _loadingMaxNumber = loadingMaxNumber;
DecryptionServices = decryptionServices; DecryptionServices = decryptionServices;
BundleServices = bundleServices; BundleServices = bundleServices;
} }
@@ -63,7 +54,7 @@ namespace YooAsset
} }
else else
{ {
if (loadingCount < AssetLoadingMaxNumber) if (loadingCount < _loadingMaxNumber)
provider.Update(); provider.Update();
if (provider.IsDone == false) if (provider.IsDone == false)
@@ -77,7 +68,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void UnloadUnusedAssets() public static void UnloadUnusedAssets()
{ {
if (SimulationOnEditor) if (_simulationOnEditor)
{ {
for (int i = _providers.Count - 1; i >= 0; i--) for (int i = _providers.Count - 1; i >= 0; i--)
{ {
@@ -128,15 +119,22 @@ namespace YooAsset
Resources.UnloadUnusedAssets(); Resources.UnloadUnusedAssets();
} }
/// <summary> /// <summary>
/// 加载场景 /// 加载场景
/// </summary> /// </summary>
public static SceneOperationHandle LoadSceneAsync(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
{ {
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SceneOperationHandle>();
}
// 注意:场景句柄永远保持唯一 // 注意:场景句柄永远保持唯一
if (_sceneHandles.ContainsKey(scenePath)) string providerGUID = assetInfo.ProviderGUID;
return _sceneHandles[scenePath]; if (_sceneHandles.ContainsKey(providerGUID))
return _sceneHandles[providerGUID];
// 如果加载的是主场景,则卸载所有缓存的场景 // 如果加载的是主场景,则卸载所有缓存的场景
if (sceneMode == LoadSceneMode.Single) if (sceneMode == LoadSceneMode.Single)
@@ -144,68 +142,81 @@ namespace YooAsset
UnloadAllScene(); UnloadAllScene();
} }
ProviderBase provider = TryGetProvider(scenePath); ProviderBase provider = TryGetProvider(providerGUID);
if (provider == null) if (provider == null)
{ {
if (SimulationOnEditor) if (_simulationOnEditor)
provider = new DatabaseSceneProvider(scenePath, sceneMode, activateOnLoad, priority); provider = new DatabaseSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
else else
provider = new BundledSceneProvider(scenePath, sceneMode, activateOnLoad, priority); provider = new BundledSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
provider.InitSpawnDebugInfo(); provider.InitSpawnDebugInfo();
_providers.Add(provider); _providers.Add(provider);
} }
var handle = provider.CreateHandle() as SceneOperationHandle; var handle = provider.CreateHandle<SceneOperationHandle>();
_sceneHandles.Add(scenePath, handle); _sceneHandles.Add(providerGUID, handle);
return handle; return handle;
} }
/// <summary> /// <summary>
/// 加载资源对象 /// 加载资源对象
/// </summary> /// </summary>
public static AssetOperationHandle LoadAssetAsync(string assetPath, System.Type assetType) public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
{ {
ProviderBase provider = TryGetProvider(assetPath); if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<AssetOperationHandle>();
}
ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID);
if (provider == null) if (provider == null)
{ {
if (SimulationOnEditor) if (_simulationOnEditor)
provider = new DatabaseAssetProvider(assetPath, assetType); provider = new DatabaseAssetProvider(assetInfo);
else else
provider = new BundledAssetProvider(assetPath, assetType); provider = new BundledAssetProvider(assetInfo);
provider.InitSpawnDebugInfo(); provider.InitSpawnDebugInfo();
_providers.Add(provider); _providers.Add(provider);
} }
return provider.CreateHandle() as AssetOperationHandle; return provider.CreateHandle<AssetOperationHandle>();
} }
/// <summary> /// <summary>
/// 加载子资源对象 /// 加载子资源对象
/// </summary> /// </summary>
public static SubAssetsOperationHandle LoadSubAssetsAsync(string assetPath, System.Type assetType) public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
{ {
ProviderBase provider = TryGetProvider(assetPath); if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
}
ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID);
if (provider == null) if (provider == null)
{ {
if (SimulationOnEditor) if (_simulationOnEditor)
provider = new DatabaseSubAssetsProvider(assetPath, assetType); provider = new DatabaseSubAssetsProvider(assetInfo);
else else
provider = new BundledSubAssetsProvider(assetPath, assetType); provider = new BundledSubAssetsProvider(assetInfo);
provider.InitSpawnDebugInfo(); provider.InitSpawnDebugInfo();
_providers.Add(provider); _providers.Add(provider);
} }
return provider.CreateHandle() as SubAssetsOperationHandle; return provider.CreateHandle<SubAssetsOperationHandle>();
} }
internal static void UnloadSubScene(ProviderBase provider) internal static void UnloadSubScene(ProviderBase provider)
{ {
string scenePath = provider.AssetPath; string providerGUID = provider.MainAssetInfo.ProviderGUID;
if (_sceneHandles.ContainsKey(scenePath) == false) if (_sceneHandles.ContainsKey(providerGUID) == false)
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
// 释放子场景句柄 // 释放子场景句柄
_sceneHandles[scenePath].ReleaseInternal(); _sceneHandles[providerGUID].ReleaseInternal();
_sceneHandles.Remove(scenePath); _sceneHandles.Remove(providerGUID);
// 卸载未被使用的资源(包括场景) // 卸载未被使用的资源(包括场景)
AssetSystem.UnloadUnusedAssets(); AssetSystem.UnloadUnusedAssets();
@@ -239,24 +250,19 @@ namespace YooAsset
} }
} }
internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(string assetPath) internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
{ {
string bundleName = BundleServices.GetBundleName(assetPath); BundleInfo bundleInfo = BundleServices.GetBundleInfo(assetInfo);
BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName);
return CreateAssetBundleLoaderInternal(bundleInfo); return CreateAssetBundleLoaderInternal(bundleInfo);
} }
internal static List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(string assetPath) internal static List<AssetBundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
{ {
List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>(); BundleInfo[] depends = BundleServices.GetAllDependBundleInfos(assetInfo);
string[] depends = BundleServices.GetAllDependencies(assetPath); List<AssetBundleLoaderBase> result = new List<AssetBundleLoaderBase>(depends.Length);
if (depends != null) foreach (var bundleInfo in depends)
{ {
foreach (var dependBundleName in depends) AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
{ result.Add(dependLoader);
BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName);
AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(dependBundleInfo);
result.Add(dependLoader);
}
} }
return result; return result;
} }
@@ -291,7 +297,7 @@ namespace YooAsset
for (int i = 0; i < _loaders.Count; i++) for (int i = 0; i < _loaders.Count; i++)
{ {
AssetBundleLoaderBase temp = _loaders[i]; AssetBundleLoaderBase temp = _loaders[i];
if (temp.BundleFileInfo.BundleName.Equals(bundleName)) if (temp.MainBundleInfo.BundleName.Equals(bundleName))
{ {
loader = temp; loader = temp;
break; break;
@@ -299,13 +305,13 @@ namespace YooAsset
} }
return loader; return loader;
} }
private static ProviderBase TryGetProvider(string assetPath) private static ProviderBase TryGetProvider(string providerGUID)
{ {
ProviderBase provider = null; ProviderBase provider = null;
for (int i = 0; i < _providers.Count; i++) for (int i = 0; i < _providers.Count; i++)
{ {
ProviderBase temp = _providers[i]; ProviderBase temp = _providers[i];
if (temp.AssetPath.Equals(assetPath)) if (temp.MainAssetInfo.ProviderGUID.Equals(providerGUID))
{ {
provider = temp; provider = temp;
break; break;
@@ -314,7 +320,6 @@ namespace YooAsset
return provider; return provider;
} }
#region #region
internal static void GetDebugReport(DebugReport report) internal static void GetDebugReport(DebugReport report)
{ {
@@ -325,7 +330,7 @@ namespace YooAsset
foreach (var provider in _providers) foreach (var provider in _providers)
{ {
DebugProviderInfo providerInfo = new DebugProviderInfo(); DebugProviderInfo providerInfo = new DebugProviderInfo();
providerInfo.AssetPath = provider.AssetPath; providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
providerInfo.SpawnScene = provider.SpawnScene; providerInfo.SpawnScene = provider.SpawnScene;
providerInfo.SpawnTime = provider.SpawnTime; providerInfo.SpawnTime = provider.SpawnTime;
providerInfo.RefCount = provider.RefCount; providerInfo.RefCount = provider.RefCount;

View File

@@ -135,7 +135,7 @@ namespace YooAsset
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
{ {
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation); InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
} }

View File

@@ -4,13 +4,13 @@ namespace YooAsset
{ {
public abstract class OperationHandleBase : IEnumerator public abstract class OperationHandleBase : IEnumerator
{ {
private readonly string _cachedAssetPath; private readonly AssetInfo _assetInfo;
internal ProviderBase Provider { private set; get; } internal ProviderBase Provider { private set; get; }
internal OperationHandleBase(ProviderBase provider) internal OperationHandleBase(ProviderBase provider)
{ {
Provider = provider; Provider = provider;
_cachedAssetPath = provider.AssetPath; _assetInfo = provider.MainAssetInfo;
} }
internal abstract void InvokeCallback(); internal abstract void InvokeCallback();
@@ -85,9 +85,9 @@ namespace YooAsset
else else
{ {
if (Provider == null) if (Provider == null)
YooLogger.Warning($"Operation handle is released : {_cachedAssetPath}"); YooLogger.Warning($"Operation handle is released : {_assetInfo.AssetPath}");
else if (Provider.IsDestroyed) else if (Provider.IsDestroyed)
YooLogger.Warning($"Provider is destroyed : {_cachedAssetPath}"); YooLogger.Warning($"Provider is destroyed : {_assetInfo.AssetPath}");
return false; return false;
} }
} }

View File

@@ -102,7 +102,7 @@ namespace YooAsset
{ {
string error = $"{nameof(SceneOperationHandle)} is invalid."; string error = $"{nameof(SceneOperationHandle)} is invalid.";
var operation = new UnloadSceneOperation(error); var operation = new UnloadSceneOperation(error);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -112,7 +112,7 @@ namespace YooAsset
string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !"; string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !";
YooLogger.Error(error); YooLogger.Error(error);
var operation = new UnloadSceneOperation(error); var operation = new UnloadSceneOperation(error);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -121,7 +121,7 @@ namespace YooAsset
AssetSystem.UnloadSubScene(Provider); AssetSystem.UnloadSubScene(Provider);
{ {
var operation = new UnloadSceneOperation(sceneObject); var operation = new UnloadSceneOperation(sceneObject);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
} }

View File

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
public sealed class SubAssetsOperationHandle : OperationHandleBase public sealed class SubAssetsOperationHandle : OperationHandleBase
@@ -77,14 +78,35 @@ namespace YooAsset
if (IsValid == false) if (IsValid == false)
return null; return null;
foreach (var asset in Provider.AllAssetObjects) foreach (var assetObject in Provider.AllAssetObjects)
{ {
if (asset.name == assetName) if (assetObject.name == assetName)
return asset as TObject; return assetObject as TObject;
} }
YooLogger.Warning($"Not found sub asset object : {assetName}"); YooLogger.Warning($"Not found sub asset object : {assetName}");
return null; return null;
} }
/// <summary>
/// 获取所有的子资源对象集合
/// </summary>
/// <typeparam name="TObject">子资源对象类型</typeparam>
public TObject[] GetSubAssetObjects<TObject>() where TObject : UnityEngine.Object
{
if (IsValid == false)
return null;
List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);
foreach (var assetObject in Provider.AllAssetObjects)
{
var retObject = assetObject as TObject;
if (retObject != null)
ret.Add(retObject);
else
YooLogger.Warning($"The type conversion failed : {assetObject.name}");
}
return ret.ToArray();
}
} }
} }

View File

@@ -39,31 +39,33 @@ namespace YooAsset
if (_steps == ESteps.None) if (_steps == ESteps.None)
{ {
if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None) if(MainBundleInfo.IsInvalid)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = $"Invalid load mode : {BundleFileInfo.BundleName}"; LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
return;
} }
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{ {
_steps = ESteps.Download; _steps = ESteps.Download;
_fileLoadPath = BundleFileInfo.GetCacheLoadPath(); _fileLoadPath = MainBundleInfo.GetCacheLoadPath();
} }
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming) else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadFile;
_fileLoadPath = BundleFileInfo.GetStreamingLoadPath(); _fileLoadPath = MainBundleInfo.GetStreamingLoadPath();
} }
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache) else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadFile;
_fileLoadPath = BundleFileInfo.GetCacheLoadPath(); _fileLoadPath = MainBundleInfo.GetCacheLoadPath();
} }
else else
{ {
throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString()); throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
} }
} }
@@ -71,7 +73,7 @@ namespace YooAsset
if (_steps == ESteps.Download) if (_steps == ESteps.Download)
{ {
int failedTryAgain = int.MaxValue; int failedTryAgain = int.MaxValue;
_downloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain); _downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload; _steps = ESteps.CheckDownload;
} }
@@ -109,12 +111,12 @@ namespace YooAsset
#endif #endif
// Load assetBundle file // Load assetBundle file
if (BundleFileInfo.IsEncrypted) if (MainBundleInfo.IsEncrypted)
{ {
if (AssetSystem.DecryptionServices == null) if (AssetSystem.DecryptionServices == null)
throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {BundleFileInfo.BundleName}"); throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}");
ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo); ulong offset = AssetSystem.DecryptionServices.GetFileOffset();
if (_isWaitForAsyncComplete) if (_isWaitForAsyncComplete)
CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset); CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset);
else else
@@ -154,7 +156,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = $"Failed to load assetBundle : {BundleFileInfo.BundleName}"; LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
else else
@@ -183,7 +185,7 @@ namespace YooAsset
if (_isShowWaitForAsyncError == false) if (_isShowWaitForAsyncError == false)
{ {
_isShowWaitForAsyncError = true; _isShowWaitForAsyncError = true;
YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}"); YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {MainBundleInfo.BundleName} States : {Status}");
} }
break; break;
} }

View File

@@ -17,7 +17,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 资源包文件信息 /// 资源包文件信息
/// </summary> /// </summary>
public BundleInfo BundleFileInfo { private set; get; } public BundleInfo MainBundleInfo { private set; get; }
/// <summary> /// <summary>
/// 引用计数 /// 引用计数
@@ -45,7 +45,7 @@ namespace YooAsset
public AssetBundleLoaderBase(BundleInfo bundleInfo) public AssetBundleLoaderBase(BundleInfo bundleInfo)
{ {
BundleFileInfo = bundleInfo; MainBundleInfo = bundleInfo;
RefCount = 0; RefCount = 0;
Status = EStatus.None; Status = EStatus.None;
} }
@@ -91,9 +91,9 @@ namespace YooAsset
if (forceDestroy == false) if (forceDestroy == false)
{ {
if (RefCount > 0) if (RefCount > 0)
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}"); throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.BundleName}");
if (IsDone() == false) if (IsDone() == false)
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}"); throw new Exception($"Bundle file loader is not done : {MainBundleInfo.BundleName}");
} }
if (CacheBundle != null) if (CacheBundle != null)

View File

@@ -37,28 +37,30 @@ namespace YooAsset
if (_steps == ESteps.None) if (_steps == ESteps.None)
{ {
if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None) if (MainBundleInfo.IsInvalid)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = $"Invalid load mode : {BundleFileInfo.BundleName}"; LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
return;
} }
else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{ {
_steps = ESteps.LoadFile; _steps = ESteps.LoadFile;
_webURL = BundleFileInfo.GetStreamingLoadPath(); _webURL = MainBundleInfo.GetStreamingLoadPath();
} }
else else
{ {
throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString()); throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
} }
} }
// 1. 从服务器或缓存中获取AssetBundle文件 // 1. 从服务器或缓存中获取AssetBundle文件
if (_steps == ESteps.LoadFile) if (_steps == ESteps.LoadFile)
{ {
string hash = StringUtility.RemoveExtension(BundleFileInfo.Hash); string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash);
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash)); _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash));
_webRequest.SendWebRequest(); _webRequest.SendWebRequest();
_steps = ESteps.CheckFile; _steps = ESteps.CheckFile;
@@ -87,7 +89,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EStatus.Failed; Status = EStatus.Failed;
LastError = $"AssetBundle file is invalid : {BundleFileInfo.BundleName}"; LastError = $"AssetBundle file is invalid : {MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
else else

View File

@@ -12,9 +12,9 @@ namespace YooAsset
private readonly List<AssetBundleLoaderBase> _dependBundles; private readonly List<AssetBundleLoaderBase> _dependBundles;
public DependAssetBundleGroup(string assetPath) public DependAssetBundleGroup(List<AssetBundleLoaderBase> dpendBundles)
{ {
_dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath); _dependBundles = dpendBundles;
} }
/// <summary> /// <summary>
@@ -102,7 +102,7 @@ namespace YooAsset
foreach (var loader in _dependBundles) foreach (var loader in _dependBundles)
{ {
var bundleInfo = new DebugBundleInfo(); var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = loader.BundleFileInfo.BundleName; bundleInfo.BundleName = loader.MainBundleInfo.BundleName;
bundleInfo.RefCount = loader.RefCount; bundleInfo.RefCount = loader.RefCount;
bundleInfo.Status = loader.Status; bundleInfo.Status = loader.Status;
output.Add(bundleInfo); output.Add(bundleInfo);

View File

@@ -7,7 +7,7 @@ namespace YooAsset
/// </summary> /// </summary>
public abstract class RawFileOperation : AsyncOperationBase public abstract class RawFileOperation : AsyncOperationBase
{ {
protected readonly BundleInfo _bundleInfo; internal readonly BundleInfo _bundleInfo;
/// <summary> /// <summary>
/// 原生文件的拷贝路径 /// 原生文件的拷贝路径
@@ -49,6 +49,34 @@ namespace YooAsset
} }
} }
/// <summary>
/// 发生错误的原生文件操作
/// </summary>
internal sealed class CompletedRawFileOperation : RawFileOperation
{
private readonly string _error;
internal CompletedRawFileOperation(string error, string copyPath) : base(null, copyPath)
{
_error = error;
}
internal override void Start()
{
Status = EOperationStatus.Failed;
Error = _error;
}
internal override void Update()
{
}
/// <summary>
/// 原生文件的缓存路径
/// </summary>
public override string GetCachePath()
{
return string.Empty;
}
}
/// <summary> /// <summary>
/// 编辑器下模拟运行的原生文件操作 /// 编辑器下模拟运行的原生文件操作
/// </summary> /// </summary>

View File

@@ -17,8 +17,7 @@ namespace YooAsset
} }
} }
public BundledAssetProvider(string assetPath, System.Type assetType) public BundledAssetProvider(AssetInfo assetInfo) : base(assetInfo)
: base(assetPath, assetType)
{ {
} }
public override void Update() public override void Update()
@@ -36,19 +35,19 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
DependBundles.WaitForAsyncComplete(); DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete();
} }
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }
@@ -69,17 +68,17 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName); AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath);
else else
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName, AssetType); AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
} }
else else
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName); _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
else else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType); _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
} }
Status = EStatus.Checking; Status = EStatus.Checking;
} }
@@ -106,7 +105,10 @@ namespace YooAsset
Status = AssetObject == null ? EStatus.Fail : EStatus.Success; Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail) if (Status == EStatus.Fail)
{ {
LastError = $"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"; if(MainAssetInfo.AssetType == null)
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
else
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -6,15 +6,17 @@ namespace YooAsset
internal abstract class BundledProvider : ProviderBase internal abstract class BundledProvider : ProviderBase
{ {
protected AssetBundleLoaderBase OwnerBundle { private set; get; } protected AssetBundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundleGroup DependBundles { private set; get; } protected DependAssetBundleGroup DependBundleGroup { private set; get; }
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType) public BundledProvider(AssetInfo assetInfo) : base(assetInfo)
{ {
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath); OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetInfo);
OwnerBundle.Reference(); OwnerBundle.Reference();
OwnerBundle.AddProvider(this); OwnerBundle.AddProvider(this);
DependBundles = new DependAssetBundleGroup(assetPath);
DependBundles.Reference(); var dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetInfo);
DependBundleGroup = new DependAssetBundleGroup(dependBundles);
DependBundleGroup.Reference();
} }
public override void Destroy() public override void Destroy()
{ {
@@ -26,10 +28,10 @@ namespace YooAsset
OwnerBundle.Release(); OwnerBundle.Release();
OwnerBundle = null; OwnerBundle = null;
} }
if (DependBundles != null) if (DependBundleGroup != null)
{ {
DependBundles.Release(); DependBundleGroup.Release();
DependBundles = null; DependBundleGroup = null;
} }
} }
@@ -39,12 +41,12 @@ namespace YooAsset
internal void GetBundleDebugInfos(List<DebugBundleInfo> output) internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{ {
var bundleInfo = new DebugBundleInfo(); var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName; bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
bundleInfo.RefCount = OwnerBundle.RefCount; bundleInfo.RefCount = OwnerBundle.RefCount;
bundleInfo.Status = OwnerBundle.Status; bundleInfo.Status = OwnerBundle.Status;
output.Add(bundleInfo); output.Add(bundleInfo);
DependBundles.GetBundleDebugInfos(output); DependBundleGroup.GetBundleDebugInfos(output);
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@@ -22,11 +23,10 @@ namespace YooAsset
} }
} }
public BundledSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) public BundledSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
: base(scenePath, null)
{ {
SceneMode = sceneMode; SceneMode = sceneMode;
_sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath); _sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_activateOnLoad = activateOnLoad; _activateOnLoad = activateOnLoad;
_priority = priority; _priority = priority;
} }
@@ -43,15 +43,15 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (Status == EStatus.CheckBundle) if (Status == EStatus.CheckBundle)
{ {
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }
@@ -98,7 +98,7 @@ namespace YooAsset
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
if(Status == EStatus.Fail) if(Status == EStatus.Fail)
{ {
LastError = $"The load scene is invalid : {AssetPath}"; LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -17,8 +17,7 @@ namespace YooAsset
} }
} }
public BundledSubAssetsProvider(string assetPath, System.Type assetType) public BundledSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
: base(assetPath, assetType)
{ {
} }
public override void Update() public override void Update()
@@ -36,19 +35,19 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
DependBundles.WaitForAsyncComplete(); DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete();
} }
if (DependBundles.IsDone() == false) if (DependBundleGroup.IsDone() == false)
return; return;
if (OwnerBundle.IsDone() == false) if (OwnerBundle.IsDone() == false)
return; return;
if (DependBundles.IsSucceed() == false) if (DependBundleGroup.IsSucceed() == false)
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = DependBundles.GetLastError(); LastError = DependBundleGroup.GetLastError();
InvokeCompletion(); InvokeCompletion();
return; return;
} }
@@ -69,17 +68,17 @@ namespace YooAsset
{ {
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName); AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath);
else else
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName, AssetType); AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
} }
else else
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName); _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath);
else else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType); _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
} }
Status = EStatus.Checking; Status = EStatus.Checking;
} }
@@ -106,7 +105,10 @@ namespace YooAsset
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail) if (Status == EStatus.Fail)
{ {
LastError = $"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"; if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
else
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -0,0 +1,33 @@

namespace YooAsset
{
internal sealed class CompletedProvider : ProviderBase
{
public override float Progress
{
get
{
if (IsDone)
return 1f;
else
return 0;
}
}
public CompletedProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
{
if (IsDone)
return;
if (Status == EStatus.None)
{
Status = EStatus.Fail;
LastError = MainAssetInfo.Error;
InvokeCompletion();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e64fd2ee771f7d498838ebf375a9531
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -17,8 +17,7 @@ namespace YooAsset
} }
} }
public DatabaseAssetProvider(string assetPath, System.Type assetType) public DatabaseAssetProvider(AssetInfo assetInfo) : base(assetInfo)
: base(assetPath, assetType)
{ {
} }
public override void Update() public override void Update()
@@ -30,11 +29,11 @@ namespace YooAsset
if (Status == EStatus.None) if (Status == EStatus.None)
{ {
// 检测资源文件是否存在 // 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid)) if (string.IsNullOrEmpty(guid))
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = $"Not found asset : {AssetPath}"; LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
InvokeCompletion(); InvokeCompletion();
return; return;
@@ -50,20 +49,36 @@ namespace YooAsset
// 1. 加载资源对象 // 1. 加载资源对象
if (Status == EStatus.Loading) if (Status == EStatus.Loading)
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(AssetPath); AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
else else
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType); AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
Status = EStatus.Checking; Status = EStatus.Checking;
} }
// 2. 检测加载结果 // 2. 检测加载结果
if (Status == EStatus.Checking) 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; Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail) if (Status == EStatus.Fail)
{ {
LastError = $"Failed to load asset object : {AssetPath}"; if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
else
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -19,8 +19,7 @@ namespace YooAsset
} }
} }
public DatabaseSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) public DatabaseSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
: base(scenePath, null)
{ {
SceneMode = sceneMode; SceneMode = sceneMode;
_activateOnLoad = activateOnLoad; _activateOnLoad = activateOnLoad;
@@ -42,7 +41,7 @@ namespace YooAsset
{ {
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
loadSceneParameters.loadSceneMode = SceneMode; loadSceneParameters.loadSceneMode = SceneMode;
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(AssetPath, loadSceneParameters); _asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
if (_asyncOp != null) if (_asyncOp != null)
{ {
_asyncOp.allowSceneActivation = true; _asyncOp.allowSceneActivation = true;
@@ -52,7 +51,7 @@ namespace YooAsset
else else
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = $"Failed to load scene : {AssetPath}"; LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
InvokeCompletion(); InvokeCompletion();
} }
@@ -70,7 +69,7 @@ namespace YooAsset
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
if (Status == EStatus.Fail) if (Status == EStatus.Fail)
{ {
LastError = $"The loaded scene is invalid : {AssetPath}"; LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -17,8 +17,7 @@ namespace YooAsset
} }
} }
public DatabaseSubAssetsProvider(string assetPath, System.Type assetType) public DatabaseSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
: base(assetPath, assetType)
{ {
} }
public override void Update() public override void Update()
@@ -30,11 +29,11 @@ namespace YooAsset
if (Status == EStatus.None) if (Status == EStatus.None)
{ {
// 检测资源文件是否存在 // 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid)) if (string.IsNullOrEmpty(guid))
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = $"Not found asset : {AssetPath}"; LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
InvokeCompletion(); InvokeCompletion();
return; return;
@@ -50,17 +49,17 @@ namespace YooAsset
// 1. 加载资源对象 // 1. 加载资源对象
if (Status == EStatus.Loading) if (Status == EStatus.Loading)
{ {
if (AssetType == null) if (MainAssetInfo.AssetType == null)
{ {
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath); AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
} }
else else
{ {
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath); UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
List<UnityEngine.Object> result = new List<Object>(findAssets.Length); List<UnityEngine.Object> result = new List<Object>(findAssets.Length);
foreach (var findAsset in findAssets) foreach (var findAsset in findAssets)
{ {
if (AssetType.IsAssignableFrom(findAsset.GetType())) if (MainAssetInfo.AssetType.IsAssignableFrom(findAsset.GetType()))
result.Add(findAsset); result.Add(findAsset);
} }
AllAssetObjects = result.ToArray(); AllAssetObjects = result.ToArray();
@@ -74,7 +73,10 @@ namespace YooAsset
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail) if (Status == EStatus.Fail)
{ {
LastError = $"Failed to load sub assets : {nameof(AssetType)} in {AssetPath}"; if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
else
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError); YooLogger.Error(LastError);
} }
InvokeCompletion(); InvokeCompletion();

View File

@@ -18,19 +18,9 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 资源路径 /// 资源信息
/// </summary> /// </summary>
public string AssetPath { private set; get; } public AssetInfo MainAssetInfo { private set; get; }
/// <summary>
/// 资源对象的名称
/// </summary>
public string AssetName { private set; get; }
/// <summary>
/// 资源对象的类型
/// </summary>
public System.Type AssetType { private set; get; }
/// <summary> /// <summary>
/// 获取的资源对象 /// 获取的资源对象
@@ -95,11 +85,9 @@ namespace YooAsset
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>(); private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
public ProviderBase(string assetPath, System.Type assetType) public ProviderBase(AssetInfo assetInfo)
{ {
AssetPath = assetPath; MainAssetInfo = assetInfo;
AssetName = System.IO.Path.GetFileName(assetPath);
AssetType = assetType;
} }
/// <summary> /// <summary>
@@ -126,25 +114,38 @@ namespace YooAsset
return RefCount <= 0; return RefCount <= 0;
} }
/// <summary>
/// 是否为场景提供者
/// </summary>
public bool IsSceneProvider()
{
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
return true;
else
return false;
}
/// <summary> /// <summary>
/// 创建操作句柄 /// 创建操作句柄
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public OperationHandleBase CreateHandle() public T CreateHandle<T>() where T : OperationHandleBase
{ {
// 引用计数增加 // 引用计数增加
RefCount++; RefCount++;
OperationHandleBase handle; OperationHandleBase handle;
if (IsSceneProvider()) if (typeof(T) == typeof(AssetOperationHandle))
handle = new AssetOperationHandle(this);
else if (typeof(T) == typeof(SceneOperationHandle))
handle = new SceneOperationHandle(this); handle = new SceneOperationHandle(this);
else if (IsSubAssetsProvider()) else if (typeof(T) == typeof(SubAssetsOperationHandle))
handle = new SubAssetsOperationHandle(this); handle = new SubAssetsOperationHandle(this);
else else
handle = new AssetOperationHandle(this); throw new System.NotImplementedException();
_handles.Add(handle); _handles.Add(handle);
return handle; return handle as T;
} }
/// <summary> /// <summary>
@@ -175,7 +176,7 @@ namespace YooAsset
// 验证结果 // 验证结果
if (IsDone == false) if (IsDone == false)
{ {
YooLogger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}"); YooLogger.Warning($"WaitForAsyncComplete failed to loading : {MainAssetInfo.AssetPath}");
} }
} }
@@ -196,21 +197,6 @@ namespace YooAsset
} }
} }
public bool IsSceneProvider()
{
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
return true;
else
return false;
}
public bool IsSubAssetsProvider()
{
if (this is BundledSubAssetsProvider || this is DatabaseSubAssetsProvider)
return true;
else
return false;
}
#region #region
private TaskCompletionSource<object> _taskCompletionSource; private TaskCompletionSource<object> _taskCompletionSource;
protected void InvokeCompletion() protected void InvokeCompletion()

View File

@@ -15,7 +15,7 @@ namespace YooAsset
private static readonly Dictionary<string, DownloaderBase> _downloaderDic = new Dictionary<string, DownloaderBase>(); private static readonly Dictionary<string, DownloaderBase> _downloaderDic = new Dictionary<string, DownloaderBase>();
private static readonly List<string> _removeList = new List<string>(100); private static readonly List<string> _removeList = new List<string>(100);
private static readonly Dictionary<string, string> _cachedHashList = new Dictionary<string, string>(1000); private static readonly Dictionary<string, string> _cachedHashList = new Dictionary<string, string>(1000);
private static int _breakpointResumeFileSize; private static int _breakpointResumeFileSize = int.MaxValue;
/// <summary> /// <summary>
/// 初始化 /// 初始化
@@ -155,17 +155,24 @@ namespace YooAsset
} }
public static bool CheckContentIntegrity(string filePath, long size, string crc) public static bool CheckContentIntegrity(string filePath, long size, string crc)
{ {
if (File.Exists(filePath) == false) try
return false; {
if (File.Exists(filePath) == false)
return false;
// 先验证文件大小 // 先验证文件大小
long fileSize = FileUtility.GetFileSize(filePath); long fileSize = FileUtility.GetFileSize(filePath);
if (fileSize != size) if (fileSize != size)
return false; return false;
// 再验证文件CRC // 再验证文件CRC
string fileCRC = HashUtility.FileCRC32(filePath); string fileCRC = HashUtility.FileCRC32(filePath);
return fileCRC == crc; return fileCRC == crc;
}
catch(Exception)
{
return false;
}
} }
} }
} }

View File

@@ -48,7 +48,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 开始处理异步操作类 /// 开始处理异步操作类
/// </summary> /// </summary>
public static void ProcessOperaiton(AsyncOperationBase operationBase) public static void StartOperaiton(AsyncOperationBase operationBase)
{ {
_operations.Add(operationBase); _operations.Add(operationBase);
operationBase.Start(); operationBase.Start();

View File

@@ -1,8 +1,46 @@
 using System.IO;
namespace YooAsset namespace YooAsset
{ {
public class AssetInfo public class AssetInfo
{ {
private readonly PatchAsset _patchAsset;
private string _providerGUID;
/// <summary>
/// 资源提供者唯一标识符
/// </summary>
internal string ProviderGUID
{
get
{
if (string.IsNullOrEmpty(_providerGUID) == false)
return _providerGUID;
if (AssetType == null)
_providerGUID = $"{AssetPath}[null]";
else
_providerGUID = $"{AssetPath}[{AssetType.Name}]";
return _providerGUID;
}
}
/// <summary>
/// 身份是否无效
/// </summary>
internal bool IsInvalid
{
get
{
return _patchAsset == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
internal string Error { private set; get; }
/// <summary> /// <summary>
/// 资源路径 /// 资源路径
/// </summary> /// </summary>
@@ -13,15 +51,37 @@ namespace YooAsset
/// </summary> /// </summary>
public System.Type AssetType { private set; get; } public System.Type AssetType { private set; get; }
public AssetInfo(string assetPath, System.Type assetType)
// 注意:这是一个内部类,严格限制外部创建。
private AssetInfo()
{ {
AssetPath = assetPath;
AssetType = assetType;
} }
public AssetInfo(string assetPath) internal AssetInfo(PatchAsset patchAsset, System.Type assetType)
{ {
AssetPath = assetPath; if (patchAsset == null)
throw new System.Exception("Should never get here !");
_patchAsset = patchAsset;
AssetType = assetType;
AssetPath = patchAsset.AssetPath;
Error = string.Empty;
}
internal AssetInfo(PatchAsset patchAsset)
{
if (patchAsset == null)
throw new System.Exception("Should never get here !");
_patchAsset = patchAsset;
AssetType = null; AssetType = null;
AssetPath = patchAsset.AssetPath;
Error = string.Empty;
}
internal AssetInfo(string error)
{
_patchAsset = null;
AssetType = null;
AssetPath = string.Empty;
Error = error;
} }
} }
} }

View File

@@ -1,9 +1,9 @@
 
namespace YooAsset namespace YooAsset
{ {
public class BundleInfo internal class BundleInfo
{ {
internal enum ELoadMode public enum ELoadMode
{ {
None, None,
LoadFromStreaming, LoadFromStreaming,
@@ -13,7 +13,7 @@ namespace YooAsset
} }
private readonly PatchBundle _patchBundle; private readonly PatchBundle _patchBundle;
internal readonly ELoadMode LoadMode; public readonly ELoadMode LoadMode;
private string _streamingPath; private string _streamingPath;
private string _cachePath; private string _cachePath;
@@ -26,17 +26,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 远端下载地址 /// 远端下载地址
/// </summary> /// </summary>
internal string RemoteMainURL { private set; get; } public string RemoteMainURL { private set; get; }
/// <summary> /// <summary>
/// 远端下载备用地址 /// 远端下载备用地址
/// </summary> /// </summary>
internal string RemoteFallbackURL { private set; get; } public string RemoteFallbackURL { private set; get; }
/// <summary> /// <summary>
/// 编辑器资源路径 /// 编辑器资源路径
/// </summary> /// </summary>
internal string EditorAssetPath { private set; get; } public string EditorAssetPath { private set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
@@ -108,11 +108,27 @@ namespace YooAsset
} }
} }
/// <summary>
/// 身份是否无效
/// </summary>
public bool IsInvalid
{
get
{
return _patchBundle == null;
}
}
/// <summary>
/// 错误信息
/// </summary>
public string Error { private set; get; }
private BundleInfo() private BundleInfo()
{ {
} }
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL) public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL)
{ {
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
@@ -120,8 +136,9 @@ namespace YooAsset
RemoteMainURL = mainURL; RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL; RemoteFallbackURL = fallbackURL;
EditorAssetPath = string.Empty; EditorAssetPath = string.Empty;
Error = string.Empty;
} }
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath) public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath)
{ {
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
@@ -129,8 +146,9 @@ namespace YooAsset
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
EditorAssetPath = editorAssetPath; EditorAssetPath = editorAssetPath;
Error = string.Empty;
} }
internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode) public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode)
{ {
_patchBundle = patchBundle; _patchBundle = patchBundle;
LoadMode = loadMode; LoadMode = loadMode;
@@ -138,37 +156,23 @@ namespace YooAsset
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
EditorAssetPath = string.Empty; EditorAssetPath = string.Empty;
Error = string.Empty;
} }
internal BundleInfo(string bundleName) public BundleInfo(string error)
{ {
_patchBundle = null; _patchBundle = null;
LoadMode = ELoadMode.None; LoadMode = ELoadMode.None;
BundleName = bundleName; BundleName = string.Empty;
RemoteMainURL = string.Empty; RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty; RemoteFallbackURL = string.Empty;
EditorAssetPath = string.Empty; EditorAssetPath = string.Empty;
} Error = error;
/// <summary>
/// 资源包是否有效
/// </summary>
public bool IsValid()
{
return _patchBundle != null;
}
/// <summary>
/// 资源包文件是否在云端
/// </summary>
public bool InCloud()
{
return LoadMode == ELoadMode.LoadFromRemote;
} }
/// <summary> /// <summary>
/// 获取流文件夹的加载路径 /// 获取流文件夹的加载路径
/// </summary> /// </summary>
internal string GetStreamingLoadPath() public string GetStreamingLoadPath()
{ {
if (_patchBundle == null) if (_patchBundle == null)
return string.Empty; return string.Empty;
@@ -181,7 +185,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 获取缓存文件夹的加载路径 /// 获取缓存文件夹的加载路径
/// </summary> /// </summary>
internal string GetCacheLoadPath() public string GetCacheLoadPath()
{ {
if (_patchBundle == null) if (_patchBundle == null)
return string.Empty; return string.Empty;
@@ -191,7 +195,6 @@ namespace YooAsset
return _cachePath; return _cachePath;
} }
/// <summary> /// <summary>
/// 是否为JAR包内文件 /// 是否为JAR包内文件
/// </summary> /// </summary>

View File

@@ -192,7 +192,7 @@ namespace YooAsset
{ {
if (_steps == ESteps.None) if (_steps == ESteps.None)
{ {
OperationSystem.ProcessOperaiton(this); OperationSystem.StartOperaiton(this);
} }
} }
} }

View File

@@ -63,8 +63,8 @@ namespace YooAsset
private readonly int _resourceVersion; private readonly int _resourceVersion;
private readonly int _timeout; private readonly int _timeout;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloaderHash; private UnityWebDataRequester _downloader1;
private UnityWebDataRequester _downloaderManifest; private UnityWebDataRequester _downloader2;
private float _verifyTime; private float _verifyTime;
internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) internal HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@@ -87,26 +87,26 @@ namespace YooAsset
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestHashFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}"); YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
_downloaderHash = new UnityWebDataRequester(); _downloader1 = new UnityWebDataRequester();
_downloaderHash.SendRequest(webURL, _timeout); _downloader1.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifestHash; _steps = ESteps.CheckWebManifestHash;
} }
if (_steps == ESteps.CheckWebManifestHash) if (_steps == ESteps.CheckWebManifestHash)
{ {
if (_downloaderHash.IsDone() == false) if (_downloader1.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderHash.HasError()) if (_downloader1.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderHash.GetError(); Error = _downloader1.GetError();
} }
else else
{ {
string webManifestHash = _downloaderHash.GetText(); string webManifestHash = _downloader1.GetText();
string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion); string cachedManifestHash = GetSandboxPatchManifestFileHash(_resourceVersion);
// 如果补丁清单文件的哈希值相同 // 如果补丁清单文件的哈希值相同
@@ -122,34 +122,34 @@ namespace YooAsset
_steps = ESteps.LoadWebManifest; _steps = ESteps.LoadWebManifest;
} }
} }
_downloaderHash.Dispose(); _downloader1.Dispose();
} }
if (_steps == ESteps.LoadWebManifest) if (_steps == ESteps.LoadWebManifest)
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}"); YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloaderManifest = new UnityWebDataRequester(); _downloader2 = new UnityWebDataRequester();
_downloaderManifest.SendRequest(webURL, _timeout); _downloader2.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest; _steps = ESteps.CheckWebManifest;
} }
if (_steps == ESteps.CheckWebManifest) if (_steps == ESteps.CheckWebManifest)
{ {
if (_downloaderManifest.IsDone() == false) if (_downloader2.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderManifest.HasError()) if (_downloader2.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderManifest.GetError(); Error = _downloader2.GetError();
} }
else else
{ {
// 解析补丁清单 // 解析补丁清单
if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloaderManifest.GetText())) if (ParseAndSaveRemotePatchManifest(_resourceVersion, _downloader2.GetText()))
{ {
_steps = ESteps.InitVerifyingCache; _steps = ESteps.InitVerifyingCache;
} }
@@ -157,10 +157,10 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid"; Error = $"URL : {_downloader2.URL} Error : remote patch manifest content is invalid";
} }
} }
_downloaderManifest.Dispose(); _downloader2.Dispose();
} }
if (_steps == ESteps.InitVerifyingCache) if (_steps == ESteps.InitVerifyingCache)
@@ -207,18 +207,19 @@ namespace YooAsset
YooLogger.Log("Save remote patch manifest file."); YooLogger.Log("Save remote patch manifest file.");
string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion)); string savePath = PathHelper.MakePersistentLoadPath(YooAssetSettingsData.GetPatchManifestFileName(updateResourceVersion));
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest); PatchManifest.Serialize(savePath, remotePatchManifest);
return true; return true;
} }
catch (Exception e) catch (Exception e)
{ {
YooLogger.Warning(e.ToString()); YooLogger.Error(e.ToString());
return false; return false;
} }
} }
/// <summary> /// <summary>
/// 加载沙盒内的补丁清单 /// 加载沙盒内的补丁清单
/// 注意:在加载本地补丁清单之前,已经验证过文件的哈希值
/// </summary> /// </summary>
private void LoadSandboxPatchManifest(int updateResourceVersion) private void LoadSandboxPatchManifest(int updateResourceVersion)
{ {
@@ -332,16 +333,8 @@ namespace YooAsset
} }
private void VerifyInThread(object infoObj) private void VerifyInThread(object infoObj)
{ {
// 验证沙盒内的文件
ThreadInfo info = (ThreadInfo)infoObj; ThreadInfo info = (ThreadInfo)infoObj;
try info.Result = DownloadSystem.CheckContentIntegrity(info.FilePath, info.Bundle.SizeBytes, info.Bundle.CRC);
{
info.Result = DownloadSystem.CheckContentIntegrity(info.FilePath, info.Bundle.SizeBytes, info.Bundle.CRC);
}
catch (Exception)
{
info.Result = false;
}
_syncContext.Post(VerifyCallback, info); _syncContext.Post(VerifyCallback, info);
} }
private void VerifyCallback(object obj) private void VerifyCallback(object obj)

View File

@@ -81,7 +81,7 @@ namespace YooAsset
private readonly int _resourceVersion; private readonly int _resourceVersion;
private readonly int _timeout; private readonly int _timeout;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloaderManifest; private UnityWebDataRequester _downloader;
private PatchManifest _remotePatchManifest; private PatchManifest _remotePatchManifest;
internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout) internal HostPlayModeUpdatePackageOperation(HostPlayModeImpl impl, int resourceVersion, int timeout)
@@ -104,28 +104,28 @@ namespace YooAsset
{ {
string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion)); string webURL = GetPatchManifestRequestURL(YooAssetSettingsData.GetPatchManifestFileName(_resourceVersion));
YooLogger.Log($"Beginning to request patch manifest : {webURL}"); YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloaderManifest = new UnityWebDataRequester(); _downloader = new UnityWebDataRequester();
_downloaderManifest.SendRequest(webURL, _timeout); _downloader.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest; _steps = ESteps.CheckWebManifest;
} }
if (_steps == ESteps.CheckWebManifest) if (_steps == ESteps.CheckWebManifest)
{ {
Progress = _downloaderManifest.Progress(); Progress = _downloader.Progress();
if (_downloaderManifest.IsDone() == false) if (_downloader.IsDone() == false)
return; return;
// Check error // Check error
if (_downloaderManifest.HasError()) if (_downloader.HasError())
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloaderManifest.GetError(); Error = _downloader.GetError();
} }
else else
{ {
// 解析补丁清单 // 解析补丁清单
if (ParseRemotePatchManifest(_downloaderManifest.GetText())) if (ParseRemotePatchManifest(_downloader.GetText()))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -134,10 +134,10 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"URL : {_downloaderManifest.URL} Error : remote patch manifest content is invalid"; Error = $"URL : {_downloader.URL} Error : remote patch manifest content is invalid";
} }
} }
_downloaderManifest.Dispose(); _downloader.Dispose();
} }
} }
@@ -209,8 +209,8 @@ namespace YooAsset
continue; continue;
} }
// 注意:下载系统只会验证当前游戏版本的资源文件,对于其它游戏版本的差异文件不会在初始化的时候去做校验 // 注意:通过比对文件大小做快速的文件校验
// 注意:通过比对文件大小做实时的文件校验方式 // 注意:在初始化的时候会去做最终校验
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
namespace YooAsset namespace YooAsset
{ {
@@ -15,6 +16,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string AssetPath; public string AssetPath;
/// <summary>
/// 资源的分类标签
/// </summary>
public string[] AssetTags;
/// <summary> /// <summary>
/// 所属资源包ID /// 所属资源包ID
/// </summary> /// </summary>
@@ -24,5 +30,24 @@ namespace YooAsset
/// 依赖的资源包ID列表 /// 依赖的资源包ID列表
/// </summary> /// </summary>
public int[] DependIDs; public int[] DependIDs;
/// <summary>
/// 是否包含Tag
/// </summary>
public bool HasTag(string[] tags)
{
if (tags == null || tags.Length == 0)
return false;
if (AssetTags == null || AssetTags.Length == 0)
return false;
foreach (var tag in tags)
{
if (AssetTags.Contains(tag))
return true;
}
return false;
}
} }
} }

View File

@@ -27,7 +27,7 @@ namespace YooAsset
public long SizeBytes; public long SizeBytes;
/// <summary> /// <summary>
/// Tags /// 资源包的分类标签
/// </summary> /// </summary>
public string[] Tags; public string[] Tags;

View File

@@ -61,90 +61,6 @@ namespace YooAsset
private bool _locationToLower = false; private bool _locationToLower = false;
/// <summary>
/// 获取内置资源标签列表
/// </summary>
public string[] GetBuildinTags()
{
return StringUtility.StringToStringList(BuildinTags, ';').ToArray();
}
/// <summary>
/// 获取资源依赖列表
/// </summary>
public string[] GetAllDependencies(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
{
List<string> result = new List<string>(patchAsset.DependIDs.Length);
foreach (var dependID in patchAsset.DependIDs)
{
if (dependID >= 0 && dependID < BundleList.Count)
{
var dependPatchBundle = BundleList[dependID];
result.Add(dependPatchBundle.BundleName);
}
else
{
throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}");
}
}
return result.ToArray();
}
else
{
YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}");
return new string[] { };
}
}
/// <summary>
/// 获取资源包名称
/// </summary>
public string GetBundleName(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
{
int bundleID = patchAsset.BundleID;
if (bundleID >= 0 && bundleID < BundleList.Count)
{
var patchBundle = BundleList[bundleID];
return patchBundle.BundleName;
}
else
{
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}");
}
}
else
{
YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}");
return string.Empty;
}
}
/// <summary>
/// 尝试获取资源包的主资源路径
/// </summary>
public string TryGetBundleMainAssetPath(string bundleName)
{
foreach (var patchAsset in AssetList)
{
int bundleID = patchAsset.BundleID;
if (bundleID >= 0 && bundleID < BundleList.Count)
{
var patchBundle = BundleList[bundleID];
if (patchBundle.BundleName == bundleName)
return patchAsset.AssetPath;
}
else
{
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {patchAsset.AssetPath}");
}
}
return string.Empty;
}
/// <summary> /// <summary>
/// 初始化资源路径映射 /// 初始化资源路径映射
/// </summary> /// </summary>
@@ -157,7 +73,7 @@ namespace YooAsset
if (EnableAddressable) if (EnableAddressable)
{ {
if (locationToLower) if (locationToLower)
YooLogger.Warning("Addressable not support location to lower !"); YooLogger.Error("Addressable not support location to lower !");
foreach (var patchAsset in AssetList) foreach (var patchAsset in AssetList)
{ {
@@ -201,6 +117,12 @@ namespace YooAsset
/// </summary> /// </summary>
public string MappingToAssetPath(string location) public string MappingToAssetPath(string location)
{ {
if(string.IsNullOrEmpty(location))
{
YooLogger.Error("Failed to mapping location to asset path, The location is null or empty.");
return string.Empty;
}
if (_locationToLower) if (_locationToLower)
location = location.ToLower(); location = location.ToLower();
@@ -210,11 +132,65 @@ namespace YooAsset
} }
else else
{ {
YooLogger.Error($"Failed to mapping location to asset path : {location}"); YooLogger.Warning($"Failed to mapping location to asset path : {location}");
return string.Empty; return string.Empty;
} }
} }
/// <summary>
/// 获取资源包名称
/// 注意:传入的资源路径一定合法有效!
/// </summary>
public string GetBundleName(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
{
int bundleID = patchAsset.BundleID;
if (bundleID >= 0 && bundleID < BundleList.Count)
{
var patchBundle = BundleList[bundleID];
return patchBundle.BundleName;
}
else
{
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}");
}
}
else
{
throw new Exception("Should never get here !");
}
}
/// <summary>
/// 获取资源依赖列表
/// 注意:传入的资源路径一定合法有效!
/// </summary>
public string[] GetAllDependencies(string assetPath)
{
if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
{
List<string> result = new List<string>(patchAsset.DependIDs.Length);
foreach (var dependID in patchAsset.DependIDs)
{
if (dependID >= 0 && dependID < BundleList.Count)
{
var dependPatchBundle = BundleList[dependID];
result.Add(dependPatchBundle.BundleName);
}
else
{
throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}");
}
}
return result.ToArray();
}
else
{
throw new Exception("Should never get here !");
}
}
/// <summary> /// <summary>
/// 序列化 /// 序列化

View File

@@ -16,7 +16,7 @@ namespace YooAsset
{ {
_locationToLower = locationToLower; _locationToLower = locationToLower;
var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath); var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -38,44 +38,41 @@ namespace YooAsset
} }
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{ {
if (string.IsNullOrEmpty(bundleName)) if(assetInfo.IsInvalid)
return new BundleInfo(string.Empty); throw new Exception("Should never get here !");
string bundleName = _simulatePatchManifest.GetBundleName(assetInfo.AssetPath);
if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{ {
string mainAssetPath = _simulatePatchManifest.TryGetBundleMainAssetPath(bundleName); BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, mainAssetPath);
return bundleInfo; return bundleInfo;
} }
else else
{ {
YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); throw new Exception("Should never get here !");
BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
} }
} }
AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{ {
return PatchHelper.GetAssetsInfoByBundleName(_simulatePatchManifest, bundleName); throw new NotImplementedException();
} }
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
{ {
return PatchHelper.GetAssetsInfoByTags(_simulatePatchManifest, tags); return PatchHelper.GetAssetsInfoByTags(_simulatePatchManifest, tags);
} }
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (_simulatePatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;
}
string IBundleServices.MappingToAssetPath(string location) string IBundleServices.MappingToAssetPath(string location)
{ {
return _simulatePatchManifest.MappingToAssetPath(location); return _simulatePatchManifest.MappingToAssetPath(location);
} }
string IBundleServices.GetBundleName(string assetPath)
{
return _simulatePatchManifest.GetBundleName(assetPath);
}
string[] IBundleServices.GetAllDependencies(string assetPath)
{
return _simulatePatchManifest.GetAllDependencies(assetPath);
}
#endregion #endregion
} }
} }

View File

@@ -12,23 +12,28 @@ namespace YooAsset
internal PatchManifest LocalPatchManifest { private set; get; } internal PatchManifest LocalPatchManifest { private set; get; }
// 参数相关 // 参数相关
internal bool LocationToLower { private set; get; } private bool _locationToLower;
internal bool ClearCacheWhenDirty { private set; get; } private bool _clearCacheWhenDirty;
private string _defaultHostServer; private string _defaultHostServer;
private string _fallbackHostServer; private string _fallbackHostServer;
public bool ClearCacheWhenDirty
{
get { return _clearCacheWhenDirty; }
}
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer) public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
{ {
LocationToLower = locationToLower; _locationToLower = locationToLower;
ClearCacheWhenDirty = clearCacheWhenDirty; _clearCacheWhenDirty = clearCacheWhenDirty;
_defaultHostServer = defaultHostServer; _defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer; _fallbackHostServer = fallbackHostServer;
var operation = new HostPlayModeInitializationOperation(this); var operation = new HostPlayModeInitializationOperation(this);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -38,7 +43,7 @@ namespace YooAsset
public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout) public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout)
{ {
var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout); var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -48,7 +53,7 @@ namespace YooAsset
public UpdateManifestOperation UpdatePatchManifestAsync(int resourceVersion, int timeout) public UpdateManifestOperation UpdatePatchManifestAsync(int resourceVersion, int timeout)
{ {
var operation = new HostPlayModeUpdateManifestOperation(this, resourceVersion, timeout); var operation = new HostPlayModeUpdateManifestOperation(this, resourceVersion, timeout);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -58,7 +63,7 @@ namespace YooAsset
public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout) public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout)
{ {
var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout); var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -182,29 +187,32 @@ namespace YooAsset
/// <summary> /// <summary>
/// 创建下载器 /// 创建下载器
/// </summary> /// </summary>
public PatchDownloaderOperation CreatePatchDownloaderByPaths(List<string> assetPaths, int fileLoadingMaxNumber, int failedTryAgain) public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain)
{ {
List<BundleInfo> downloadList = GetDownloadListByPaths(assetPaths); List<BundleInfo> downloadList = GetDownloadListByPaths(assetInfos);
var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
private List<BundleInfo> GetDownloadListByPaths(List<string> assetPaths) private List<BundleInfo> GetDownloadListByPaths(AssetInfo[] assetInfos)
{ {
// 获取资源对象的资源包和所有依赖资源包 // 获取资源对象的资源包和所有依赖资源包
List<PatchBundle> checkList = new List<PatchBundle>(); List<PatchBundle> checkList = new List<PatchBundle>();
foreach (var assetPath in assetPaths) foreach (var assetInfo in assetInfos)
{ {
string mainBundleName = LocalPatchManifest.GetBundleName(assetPath); if (assetInfo.IsInvalid)
if (string.IsNullOrEmpty(mainBundleName) == false)
{ {
if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle)) YooLogger.Warning(assetInfo.Error);
{ continue;
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
}
} }
string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetPath); string mainBundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle))
{
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
}
string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundleName in dependBundleNames) foreach (var dependBundleName in dependBundleNames)
{ {
if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle)) if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle))
@@ -245,6 +253,12 @@ namespace YooAsset
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation; return operation;
} }
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByAll(AppPatchManifest);
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation;
}
// WEB相关 // WEB相关
public string GetPatchDownloadMainURL(string fileName) public string GetPatchDownloadMainURL(string fileName)
@@ -284,15 +298,12 @@ namespace YooAsset
internal void SetLocalPatchManifest(PatchManifest patchManifest) internal void SetLocalPatchManifest(PatchManifest patchManifest)
{ {
LocalPatchManifest = patchManifest; LocalPatchManifest = patchManifest;
LocalPatchManifest.InitAssetPathMapping(LocationToLower); LocalPatchManifest.InitAssetPathMapping(_locationToLower);
} }
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) private BundleInfo CreateBundleInfo(string bundleName)
{ {
if (string.IsNullOrEmpty(bundleName))
return new BundleInfo(string.Empty);
if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{ {
// 查询沙盒资源 // 查询沙盒资源
@@ -317,31 +328,46 @@ namespace YooAsset
} }
else else
{ {
YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); throw new Exception("Should never get here !");
BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
} }
} }
AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{ {
return PatchHelper.GetAssetsInfoByBundleName(LocalPatchManifest, bundleName); if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
string bundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath);
return CreateBundleInfo(bundleName);
}
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var bundleName in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
result.Add(bundleInfo);
}
return result.ToArray();
} }
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
{ {
return PatchHelper.GetAssetsInfoByTags(LocalPatchManifest, tags); return PatchHelper.GetAssetsInfoByTags(LocalPatchManifest, tags);
} }
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (LocalPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;
}
string IBundleServices.MappingToAssetPath(string location) string IBundleServices.MappingToAssetPath(string location)
{ {
return LocalPatchManifest.MappingToAssetPath(location); return LocalPatchManifest.MappingToAssetPath(location);
} }
string IBundleServices.GetBundleName(string assetPath)
{
return LocalPatchManifest.GetBundleName(assetPath);
}
string[] IBundleServices.GetAllDependencies(string assetPath)
{
return LocalPatchManifest.GetAllDependencies(assetPath);
}
#endregion #endregion
} }
} }

View File

@@ -16,7 +16,7 @@ namespace YooAsset
{ {
_locationToLower = locationToLower; _locationToLower = locationToLower;
var operation = new OfflinePlayModeInitializationOperation(this); var operation = new OfflinePlayModeInitializationOperation(this);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
@@ -39,6 +39,12 @@ namespace YooAsset
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation; return operation;
} }
public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = PatchHelper.GetUnpackListByAll(_appPatchManifest);
var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation;
}
// 设置资源清单 // 设置资源清单
internal void SetAppPatchManifest(PatchManifest patchManifest) internal void SetAppPatchManifest(PatchManifest patchManifest)
@@ -48,11 +54,8 @@ namespace YooAsset
} }
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) private BundleInfo CreateBundleInfo(string bundleName)
{ {
if (string.IsNullOrEmpty(bundleName))
return new BundleInfo(string.Empty);
if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
{ {
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming); BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming);
@@ -60,31 +63,46 @@ namespace YooAsset
} }
else else
{ {
YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); throw new Exception("Should never get here !");
BundleInfo bundleInfo = new BundleInfo(bundleName);
return bundleInfo;
} }
} }
AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
{ {
return PatchHelper.GetAssetsInfoByBundleName(_appPatchManifest, bundleName); if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath);
return CreateBundleInfo(bundleName);
}
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
throw new Exception("Should never get here !");
var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var bundleName in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(bundleName);
result.Add(bundleInfo);
}
return result.ToArray();
} }
AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) AssetInfo[] IBundleServices.GetAssetInfos(string[] tags)
{ {
return PatchHelper.GetAssetsInfoByTags(_appPatchManifest, tags); return PatchHelper.GetAssetsInfoByTags(_appPatchManifest, tags);
} }
PatchAsset IBundleServices.TryGetPatchAsset(string assetPath)
{
if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset))
return patchAsset;
else
return null;
}
string IBundleServices.MappingToAssetPath(string location) string IBundleServices.MappingToAssetPath(string location)
{ {
return _appPatchManifest.MappingToAssetPath(location); return _appPatchManifest.MappingToAssetPath(location);
} }
string IBundleServices.GetBundleName(string assetPath)
{
return _appPatchManifest.GetBundleName(assetPath);
}
string[] IBundleServices.GetAllDependencies(string assetPath)
{
return _appPatchManifest.GetAllDependencies(assetPath);
}
#endregion #endregion
} }
} }

View File

@@ -6,31 +6,26 @@ namespace YooAsset
/// <summary> /// <summary>
/// 获取资源包信息 /// 获取资源包信息
/// </summary> /// </summary>
BundleInfo GetBundleInfo(string bundleName); BundleInfo GetBundleInfo(AssetInfo assetInfo);
/// <summary> /// <summary>
/// 获取资源信息列表 /// 获取依赖的资源信息集合
/// </summary> /// </summary>
AssetInfo[] GetAssetInfos(string bundleName); BundleInfo[] GetAllDependBundleInfos(AssetInfo assetPath);
/// <summary> /// <summary>
/// 获取资源信息列表 /// 获取资源信息列表
/// </summary> /// </summary>
AssetInfo[] GetAssetInfos(string[] tags); AssetInfo[] GetAssetInfos(string[] tags);
/// <summary>
/// 尝试获取补丁资源
/// </summary>
PatchAsset TryGetPatchAsset(string assetPath);
/// <summary> /// <summary>
/// 映射为资源路径 /// 映射为资源路径
/// </summary> /// </summary>
string MappingToAssetPath(string location); string MappingToAssetPath(string location);
/// <summary>
/// 获取资源所属的资源包名称
/// </summary>
string GetBundleName(string assetPath);
/// <summary>
/// 获取资源依赖的所有AssetBundle列表
/// </summary>
string[] GetAllDependencies(string assetPath);
} }
} }

View File

@@ -6,6 +6,6 @@ namespace YooAsset
/// <summary> /// <summary>
/// 获取加密文件的数据偏移量 /// 获取加密文件的数据偏移量
/// </summary> /// </summary>
ulong GetFileOffset(BundleInfo bundleInfo); ulong GetFileOffset();
} }
} }

View File

@@ -3,7 +3,7 @@ namespace YooAsset
{ {
public class AddressLocationServices : ILocationServices public class AddressLocationServices : ILocationServices
{ {
public string ConvertLocationToAssetPath(string location) string ILocationServices.ConvertLocationToAssetPath(string location)
{ {
return YooAssets.MappingToAssetPath(location); return YooAssets.MappingToAssetPath(location);
} }

View File

@@ -11,7 +11,7 @@ namespace YooAsset
_resourceRoot = PathHelper.GetRegularPath(resourceRoot); _resourceRoot = PathHelper.GetRegularPath(resourceRoot);
} }
public string ConvertLocationToAssetPath(string location) string ILocationServices.ConvertLocationToAssetPath(string location)
{ {
if (string.IsNullOrEmpty(_resourceRoot)) if (string.IsNullOrEmpty(_resourceRoot))
{ {

View File

@@ -28,7 +28,7 @@ namespace YooAsset
} }
else else
{ {
YooLogger.Log("YooAsset use custom settings."); YooLogger.Log("YooAsset use user settings.");
} }
} }

View File

@@ -151,6 +151,26 @@ namespace YooAsset
return ConvertToUnpackList(downloadList); return ConvertToUnpackList(downloadList);
} }
public static List<BundleInfo> GetUnpackListByAll(PatchManifest appPatchManifest)
{
// 注意:离线运行模式也依赖下面逻辑,所以判断沙盒内文件是否存在不能通过缓存系统去验证。
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
foreach (var patchBundle in appPatchManifest.BundleList)
{
// 如果已经在沙盒内
string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash);
if (System.IO.File.Exists(filePath))
continue;
// 如果不是内置资源
if (patchBundle.IsBuildin == false)
continue;
downloadList.Add(patchBundle);
}
return ConvertToUnpackList(downloadList);
}
private static List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList) private static List<BundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
{ {
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count); List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
@@ -178,31 +198,13 @@ namespace YooAsset
List<AssetInfo> result = new List<AssetInfo>(100); List<AssetInfo> result = new List<AssetInfo>(100);
foreach (var patchAsset in patchManifest.AssetList) foreach (var patchAsset in patchManifest.AssetList)
{ {
string bundleName = patchManifest.GetBundleName(patchAsset.AssetPath); if(patchAsset.HasTag(tags))
if(patchManifest.Bundles.TryGetValue(bundleName, out PatchBundle bundle))
{ {
if(bundle.HasTag(tags)) AssetInfo assetInfo = new AssetInfo(patchAsset);
{ result.Add(assetInfo);
result.Add(new AssetInfo(patchAsset.AssetPath));
}
} }
} }
return result.ToArray(); return result.ToArray();
} }
/// <summary>
/// 获取资源信息列表
/// </summary>
public static AssetInfo[] GetAssetsInfoByBundleName(PatchManifest patchManifest, string bundleName)
{
List<AssetInfo> result = new List<AssetInfo>(100);
foreach (var patchAsset in patchManifest.AssetList)
{
string tempName = patchManifest.GetBundleName(patchAsset.AssetPath);
if (tempName == bundleName)
result.Add(new AssetInfo(patchAsset.AssetPath));
}
return result.ToArray();
}
} }
} }

View File

@@ -33,7 +33,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 初始化参数 /// 初始化参数
/// </summary> /// </summary>
public abstract class CreateParameters public abstract class InitializeParameters
{ {
/// <summary> /// <summary>
/// 资源定位地址大小写不敏感 /// 资源定位地址大小写不敏感
@@ -64,7 +64,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 编辑器下模拟运行模式的初始化参数 /// 编辑器下模拟运行模式的初始化参数
/// </summary> /// </summary>
public class EditorSimulateModeParameters : CreateParameters public class EditorSimulateModeParameters : InitializeParameters
{ {
/// <summary> /// <summary>
/// 用于模拟运行的资源清单路径 /// 用于模拟运行的资源清单路径
@@ -76,14 +76,14 @@ namespace YooAsset
/// <summary> /// <summary>
/// 离线运行模式的初始化参数 /// 离线运行模式的初始化参数
/// </summary> /// </summary>
public class OfflinePlayModeParameters : CreateParameters public class OfflinePlayModeParameters : InitializeParameters
{ {
} }
/// <summary> /// <summary>
/// 网络运行模式的初始化参数 /// 网络运行模式的初始化参数
/// </summary> /// </summary>
public class HostPlayModeParameters : CreateParameters public class HostPlayModeParameters : InitializeParameters
{ {
/// <summary> /// <summary>
/// 当缓存池被污染的时候清理缓存池 /// 当缓存池被污染的时候清理缓存池
@@ -121,7 +121,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public static InitializationOperation InitializeAsync(CreateParameters parameters) public static InitializationOperation InitializeAsync(InitializeParameters parameters)
{ {
if (parameters == null) if (parameters == null)
throw new Exception($"YooAsset create parameters is null."); throw new Exception($"YooAsset create parameters is null.");
@@ -149,19 +149,19 @@ namespace YooAsset
throw new Exception("YooAsset is initialized yet."); throw new Exception("YooAsset is initialized yet.");
} }
// 检测参数范围
if (parameters.AssetLoadingMaxNumber < 1) if (parameters.AssetLoadingMaxNumber < 1)
{ {
parameters.AssetLoadingMaxNumber = 1; parameters.AssetLoadingMaxNumber = 1;
YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1"); YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1");
} }
if (parameters.OperationSystemMaxTimeSlice < 30) if (parameters.OperationSystemMaxTimeSlice < 30)
{ {
parameters.OperationSystemMaxTimeSlice = 30; parameters.OperationSystemMaxTimeSlice = 30;
YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 33 milliseconds"); YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 30 milliseconds");
} }
// 运行模式 // 鉴定运行模式
if (parameters is EditorSimulateModeParameters) if (parameters is EditorSimulateModeParameters)
_playMode = EPlayMode.EditorSimulateMode; _playMode = EPlayMode.EditorSimulateMode;
else if (parameters is OfflinePlayModeParameters) else if (parameters is OfflinePlayModeParameters)
@@ -241,19 +241,17 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
var operation = new EditorPlayModeUpdateStaticVersionOperation(); var operation = new EditorPlayModeUpdateStaticVersionOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
var operation = new OfflinePlayModeUpdateStaticVersionOperation(); var operation = new OfflinePlayModeUpdateStaticVersionOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.UpdateStaticVersionAsync(timeout); return _hostPlayModeImpl.UpdateStaticVersionAsync(timeout);
} }
else else
@@ -273,19 +271,17 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
var operation = new EditorPlayModeUpdateManifestOperation(); var operation = new EditorPlayModeUpdateManifestOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
var operation = new OfflinePlayModeUpdateManifestOperation(); var operation = new OfflinePlayModeUpdateManifestOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.UpdatePatchManifestAsync(resourceVersion, timeout); return _hostPlayModeImpl.UpdatePatchManifestAsync(resourceVersion, timeout);
} }
else else
@@ -298,9 +294,9 @@ namespace YooAsset
/// 开启一个异步操作 /// 开启一个异步操作
/// </summary> /// </summary>
/// <param name="operation">异步操作对象</param> /// <param name="operation">异步操作对象</param>
public static void ProcessOperaiton(GameAsyncOperation operation) public static void StartOperaiton(GameAsyncOperation operation)
{ {
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
} }
/// <summary> /// <summary>
@@ -311,20 +307,14 @@ namespace YooAsset
DebugCheckInitialize(); DebugCheckInitialize();
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
if (_editorSimulateModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _editorSimulateModeImpl.GetResourceVersion(); return _editorSimulateModeImpl.GetResourceVersion();
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
if (_offlinePlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _offlinePlayModeImpl.GetResourceVersion(); return _offlinePlayModeImpl.GetResourceVersion();
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.GetResourceVersion(); return _hostPlayModeImpl.GetResourceVersion();
} }
else else
@@ -338,8 +328,11 @@ namespace YooAsset
/// </summary> /// </summary>
public static void UnloadUnusedAssets() public static void UnloadUnusedAssets()
{ {
AssetSystem.Update(); if (_isInitialize)
AssetSystem.UnloadUnusedAssets(); {
AssetSystem.Update();
AssetSystem.UnloadUnusedAssets();
}
} }
/// <summary> /// <summary>
@@ -347,52 +340,53 @@ namespace YooAsset
/// </summary> /// </summary>
public static void ForceUnloadAllAssets() public static void ForceUnloadAllAssets()
{ {
AssetSystem.ForceUnloadAllAssets(); if (_isInitialize)
{
AssetSystem.ForceUnloadAllAssets();
}
} }
/// <summary>
/// 获取调试信息
/// </summary>
internal static void GetDebugReport(DebugReport report)
{
if (report == null)
YooLogger.Error($"{nameof(DebugReport)} is null");
AssetSystem.GetDebugReport(report);
}
#region #region
/// <summary> /// <summary>
/// 获取资源包信息 /// 是否需要从远端更新下载
/// </summary> /// </summary>
/// <param name="location">资源的定位地址</param> /// <param name="location">资源的定位地址</param>
public static BundleInfo GetBundleInfo(string location) public static bool IsNeedDownloadFromRemote(string location)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
string bundleName = _bundleServices.GetBundleName(assetPath); if (assetInfo.IsInvalid)
return _bundleServices.GetBundleInfo(bundleName); {
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
else
return false;
} }
/// <summary> /// <summary>
/// 获取资源包信息 /// 是否需要从远端更新下载
/// </summary> /// </summary>
/// <param name="assetInfo">资源信息</param> /// <param name="location">资源的定位地址</param>
public static BundleInfo GetBundleInfo(AssetInfo assetInfo) public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string bundleName = _bundleServices.GetBundleName(assetInfo.AssetPath); if (assetInfo.IsInvalid)
return _bundleServices.GetBundleInfo(bundleName); {
} YooLogger.Warning(assetInfo.Error);
return false;
}
/// <summary> BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
/// 获取资源信息列表 if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
/// </summary> return true;
/// <param name="bundleInfo">资源包信息</param> else
public static AssetInfo[] GetAssetInfos(BundleInfo bundleInfo) return false;
{
DebugCheckInitialize();
return _bundleServices.GetAssetInfos(bundleInfo.BundleName);
} }
/// <summary> /// <summary>
@@ -428,8 +422,8 @@ namespace YooAsset
public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string scenePath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority); var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
return handle; return handle;
} }
@@ -443,8 +437,7 @@ namespace YooAsset
public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string scenePath = assetInfo.AssetPath; var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority);
var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority);
return handle; return handle;
} }
#endregion #endregion
@@ -458,8 +451,8 @@ namespace YooAsset
public static RawFileOperation GetRawFileAsync(string location, string copyPath = null) public static RawFileOperation GetRawFileAsync(string location, string copyPath = null)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return GetRawFileInternal(assetPath, copyPath); return GetRawFileInternal(assetInfo, copyPath);
} }
/// <summary> /// <summary>
@@ -470,31 +463,37 @@ namespace YooAsset
public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null) public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return GetRawFileInternal(assetInfo.AssetPath, copyPath); return GetRawFileInternal(assetInfo, copyPath);
} }
private static RawFileOperation GetRawFileInternal(string assetPath, string copyPath) private static RawFileOperation GetRawFileInternal(AssetInfo assetInfo, string copyPath)
{ {
string bundleName = _bundleServices.GetBundleName(assetPath); if (assetInfo.IsInvalid)
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName); {
YooLogger.Warning(assetInfo.Error);
RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
OperationSystem.StartOperaiton(operation);
return operation;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath); RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath); RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath); RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else else
@@ -512,7 +511,7 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo) public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, true); return LoadAssetInternal(assetInfo, true);
} }
/// <summary> /// <summary>
@@ -523,8 +522,8 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : class public static AssetOperationHandle LoadAssetSync<TObject>(string location) where TObject : class
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetPath, typeof(TObject), true); return LoadAssetInternal(assetInfo, true);
} }
/// <summary> /// <summary>
@@ -535,8 +534,8 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetSync(string location, System.Type type) public static AssetOperationHandle LoadAssetSync(string location, System.Type type)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetPath, type, true); return LoadAssetInternal(assetInfo, true);
} }
@@ -547,7 +546,7 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, false); return LoadAssetInternal(assetInfo, false);
} }
/// <summary> /// <summary>
@@ -558,8 +557,8 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetAsync<TObject>(string location) public static AssetOperationHandle LoadAssetAsync<TObject>(string location)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetPath, typeof(TObject), false); return LoadAssetInternal(assetInfo, false);
} }
/// <summary> /// <summary>
@@ -570,14 +569,14 @@ namespace YooAsset
public static AssetOperationHandle LoadAssetAsync(string location, System.Type type) public static AssetOperationHandle LoadAssetAsync(string location, System.Type type)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetPath, type, false); return LoadAssetInternal(assetInfo, false);
} }
private static AssetOperationHandle LoadAssetInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete) private static AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
var handle = AssetSystem.LoadAssetAsync(assetPath, assetType); var handle = AssetSystem.LoadAssetAsync(assetInfo);
if (waitForAsyncComplete) if (waitForAsyncComplete)
handle.WaitForAsyncComplete(); handle.WaitForAsyncComplete();
return handle; return handle;
@@ -592,7 +591,7 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo) public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, true); return LoadSubAssetsInternal(assetInfo, true);
} }
/// <summary> /// <summary>
@@ -603,8 +602,8 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location) public static SubAssetsOperationHandle LoadSubAssetsSync<TObject>(string location)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetPath, typeof(TObject), true); return LoadSubAssetsInternal(assetInfo, true);
} }
/// <summary> /// <summary>
@@ -615,8 +614,8 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type) public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetPath, type, true); return LoadSubAssetsInternal(assetInfo, true);
} }
@@ -627,7 +626,7 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, false); return LoadSubAssetsInternal(assetInfo, false);
} }
/// <summary> /// <summary>
@@ -638,8 +637,8 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location) public static SubAssetsOperationHandle LoadSubAssetsAsync<TObject>(string location)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetPath, typeof(TObject), false); return LoadSubAssetsInternal(assetInfo, false);
} }
/// <summary> /// <summary>
@@ -650,14 +649,14 @@ namespace YooAsset
public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type) public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetPath, type, false); return LoadSubAssetsInternal(assetInfo, false);
} }
private static SubAssetsOperationHandle LoadSubAssetsInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete) private static SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
var handle = AssetSystem.LoadSubAssetsAsync(assetPath, assetType); var handle = AssetSystem.LoadSubAssetsAsync(assetInfo);
if (waitForAsyncComplete) if (waitForAsyncComplete)
handle.WaitForAsyncComplete(); handle.WaitForAsyncComplete();
return handle; return handle;
@@ -694,8 +693,6 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain);
} }
else else
@@ -720,8 +717,6 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain); return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain);
} }
else else
@@ -748,16 +743,13 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null) List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
throw new Exception("YooAsset is not initialized.");
List<string> assetPaths = new List<string>(locations.Length);
foreach (var location in locations) foreach (var location in locations)
{ {
string assetPath = _locationServices.ConvertLocationToAssetPath(location); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
assetPaths.Add(assetPath); assetInfos.Add(assetInfo);
} }
return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain);
} }
else else
{ {
@@ -782,15 +774,7 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null) return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain);
throw new Exception("YooAsset is not initialized.");
List<string> assetPaths = new List<string>(assetInfos.Length);
foreach (var assetInfo in assetInfos)
{
assetPaths.Add(assetInfo.AssetPath);
}
return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain);
} }
else else
{ {
@@ -829,14 +813,10 @@ namespace YooAsset
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
if (_offlinePlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _offlinePlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); return _offlinePlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
} }
else else
@@ -844,6 +824,34 @@ namespace YooAsset
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
/// <summary>
/// 创建补丁解压器
/// </summary>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorSimulateMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
return _offlinePlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain);
}
else if (_playMode == EPlayMode.HostPlayMode)
{
return _hostPlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain);
}
else
{
throw new NotImplementedException();
}
}
#endregion #endregion
#region #region
@@ -858,19 +866,17 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
var operation = new EditorPlayModeUpdatePackageOperation(); var operation = new EditorPlayModeUpdatePackageOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
var operation = new OfflinePlayModeUpdatePackageOperation(); var operation = new OfflinePlayModeUpdatePackageOperation();
OperationSystem.ProcessOperaiton(operation); OperationSystem.StartOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout); return _hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout);
} }
else else
@@ -918,22 +924,32 @@ namespace YooAsset
#region #region
internal static void InternalUpdate() internal static void InternalUpdate()
{ {
// 更新异步请求操作 // 更新异步操作系统
OperationSystem.Update(); OperationSystem.Update();
// 更新下载管理系统 // 更新下载管理系统
DownloadSystem.Update(); DownloadSystem.Update();
// 轮询更新资源系统 // 更新资源系统
AssetSystem.Update(); AssetSystem.Update();
} }
/// <summary>
/// 获取调试信息
/// </summary>
internal static void GetDebugReport(DebugReport report)
{
if (report == null)
YooLogger.Error($"{nameof(DebugReport)} is null");
AssetSystem.GetDebugReport(report);
}
/// <summary> /// <summary>
/// 资源定位地址转换为资源完整路径 /// 资源定位地址转换为资源完整路径
/// </summary> /// </summary>
internal static string MappingToAssetPath(string location) internal static string MappingToAssetPath(string location)
{ {
DebugCheckLocation(location);
return _bundleServices.MappingToAssetPath(location); return _bundleServices.MappingToAssetPath(location);
} }
#endregion #endregion
@@ -951,11 +967,7 @@ namespace YooAsset
[Conditional("DEBUG")] [Conditional("DEBUG")]
private static void DebugCheckLocation(string location) private static void DebugCheckLocation(string location)
{ {
if (string.IsNullOrEmpty(location)) if (string.IsNullOrEmpty(location) == false)
{
YooLogger.Error("location param is null or empty!");
}
else
{ {
// 检查路径末尾是否有空格 // 检查路径末尾是否有空格
int index = location.LastIndexOf(" "); int index = location.LastIndexOf(" ");
@@ -970,5 +982,30 @@ namespace YooAsset
} }
} }
#endregion #endregion
#region
private static AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
DebugCheckLocation(location);
string assetPath = _locationServices.ConvertLocationToAssetPath(location);
PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath);
if (patchAsset != null)
{
AssetInfo assetInfo = new AssetInfo(patchAsset, assetType);
return assetInfo;
}
else
{
string error;
if (string.IsNullOrEmpty(location))
error = $"The location is null or empty !";
else
error = $"The location is invalid : {location}";
YooLogger.Error(error);
AssetInfo assetInfo = new AssetInfo(error);
return assetInfo;
}
}
#endregion
} }
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "com.tuyoogame.yooasset", "name": "com.tuyoogame.yooasset",
"displayName": "YooAsset", "displayName": "YooAsset",
"version": "1.0.8", "version": "1.0.9",
"unity": "2019.4", "unity": "2019.4",
"description": "unity3d resources management system", "description": "unity3d resources management system",
"author": { "author": {

View File

@@ -14,7 +14,15 @@
- **Build Mode** - **Build Mode**
构建模式:强制构建模式,增量构建模式,演练构建模式,模拟构建模式。 构建模式
(1) 强制构建模式:会删除指定构建平台下的所有构建记录,重新构建所有资源包。
(2) 增量构建模式:以上一次构建结果为基础,对于发生变化的资源进行增量构建。
(3) 演练构建模式在不生成AssetBundle文件的前提下进行演练构建并快速生成构建报告和补丁清单。
(4) 模拟构建模式在编辑器下配合EditorSimulateMode运行模式来模拟真实运行的环境。
- **Encryption** - **Encryption**

147
Docs/CodeStyle.md Normal file
View File

@@ -0,0 +1,147 @@
# 代码贡献
代码贡献请遵循下面的规范。
### 提交规范
每个PR只针对一项内容的改进或修复请勿合并提交。
PR标题尽量选择英文备注内容可选中文。
### 对齐规范
Tab键对齐可以在VS里设置
### 命名规范
[规则1-1] 英文单词命名。禁止使用拼音或无意义的字母命名。
[规则1-2] 直观易懂。使用能够描述其功能或有意义的英文单词或词组。
[规则1-3] 不要采用下划线命名法。
```C#
int car_type //错误:下划线命名。
```
[规则1-4] 常量、静态字段、类、结构体、非私有字段、方法等名称采用**大驼峰式命名法**
```C#
public const float MaxSpeed = 100f; //常量
public static float MaxSpeed = 100f; //静态字段
public class GameClass; //类
public struct GameStruct; //结构体
public string FirstName; //public字段
protected string FirstName; //protected字段
public void SendMessage(string message) {} //方法
```
[规则1-5] 私有字段、方法形参、局部变量采用 **小驼峰式命名法**
注意:私有字段以下划线开头
```C#
private string _firstName; //私有字段
public void FindByFirstName(string firstName) {} //方法参数
string firstName; //局部变量
```
[规则1-6] 接口命名
注意接口以大写字母I开头
```C#
public interface IState; //接口
```
[规则1-7] 枚举命名
注意枚举以大写字母E开头
```C#
public enum EGameType {Simple, Hard}//枚举及枚举值
```
### 编码规范
[规则2-1] 声明变量时,一行只声明一个变量。
```C#
private string _firstName;
private string _lastName;
```
[规则2-2] 类的字段声明统一放置于类的最前端。
```C#
public class Student
{
private string _firstName;
private string _lastName;
public string GetFirstName()
{
return _firstFiled;
}
}
```
[规则2-3] 一行代码长度不要超过屏幕宽度。如果超过了,将超过部分换行。
### 注释规范
[规则3-1] 公共方法注释,采用 /// 形式自动产生XML标签格式的注释。包括方法介绍参数含义返回内容。
注意:私有方法可以不用注释。
```C#
/// <summary>
/// 设置场景名称
/// </summary>
/// <param name="sceneName">场景名</param>
/// <returns>如果设置成功返回True</returns>
public bool SetSceneName(string sceneName)
{
}
```
[规则3-2] 公共字段注释,采用 /// 形式自动产生XML标签格式的注释。
注意:私有字段可以不用注释。
```C#
public class SceneManager
{
/// <summary>
/// 场景的名字
/// </summary>
public string SceneName;
}
```
[规则3-3] 私有字段注释注释位于代码后面中间Space键隔开。
```C#
public class Student
{
private string _firstName; //姓氏
private string _lastName; //姓名
}
```
[规则3-4] 方法内的代码块注释。
```C#
public void UpdateHost
{
// 和服务器通信
...
// 检测通信结果
...
// 分析数据
...
}
```

View File

@@ -77,7 +77,7 @@ private IEnumerator InitializeYooAsset()
````c# ````c#
public class BundleDecryption : IDecryptionServices public class BundleDecryption : IDecryptionServices
{ {
public ulong GetFileOffset(BundleInfo bundleInfo) public ulong GetFileOffset()
{ {
return 32; return 32;
} }

View File

@@ -1,13 +1,13 @@
# 资源加载 # 资源加载
加载接口 加载方法
- YooAssets.LoadAssetSync() 同步加载资源对象接口 - YooAssets.LoadAssetSync() 同步加载资源对象
- YooAssets.LoadSubAssetsSync() 同步加载子资源对象接口 - YooAssets.LoadSubAssetsSync() 同步加载子资源对象
- YooAssets.LoadAssetAsync() 异步加载资源对象接口 - YooAssets.LoadAssetAsync() 异步加载资源对象
- YooAssets.LoadSubAssetsAsync() 异步加载子资源对象接口 - YooAssets.LoadSubAssetsAsync() 异步加载子资源对象
- YooAssets.LoadSceneAsync() 异步加载场景接口 - YooAssets.LoadSceneAsync() 异步加载场景
- YooAssets.LoadRawFileAsync() 异步取原生文件接口 - YooAssets.GetRawFileAsync() 异步取原生文件
统一约定location为资源的定位地址也是加载资源对象的唯一标识符。 统一约定location为资源的定位地址也是加载资源对象的唯一标识符。
@@ -135,14 +135,29 @@ IEnumerator Start()
{ {
string location = "wwise/init.bnk"; string location = "wwise/init.bnk";
string copyPath = $"{Application.persistentDataPath}/Audio/init.bnk"; string copyPath = $"{Application.persistentDataPath}/Audio/init.bnk";
RawFileOperation operation = YooAssets.LoadRawFileAsync(location, copyPath); RawFileOperation operation = YooAssets.GetRawFileAsync(location, copyPath);
yield return operation; yield return operation;
byte[] fileData = operation.GetFileData(); byte[] fileData = operation.GetFileData();
string fileText = operation.GetFileText(); string fileText = operation.GetFileText();
} }
```` ````
**FairyGUI加载方案** **获取资源信息列表**
通过资源标签来获取资源信息列表。
````c#
private GetAssetInfosByTag(string tag)
{
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(tag);
foreach (var assetInfo in assetInfos)
{
Debug.Log(assetInfo.AssetPath);
}
}
````
**FairyGUI支持解决方案**
注意在FairyGUI的面板销毁的时候将资源句柄列表释放否则会造成资源泄漏。 注意在FairyGUI的面板销毁的时候将资源句柄列表释放否则会造成资源泄漏。
@@ -153,7 +168,7 @@ private List<AssetOperationHandle> _handles = new List<AssetOperationHandle>(100
// 加载方法 // 加载方法
private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method) private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method)
{ {
method = DestroyMethod.None; method = DestroyMethod.None; //注意这里一定要设置为None
string location = $"FairyRes/{name}{extension}"; string location = $"FairyRes/{name}{extension}";
var handle = YooAssets.LoadAssetSync(location , type); var handle = YooAssets.LoadAssetSync(location , type);
_handles.Add(handle); _handles.Add(handle);
@@ -171,3 +186,6 @@ private void ReleaseHandles()
} }
```` ````
**UniTask支持解决方案**
[解决方案](https://github.com/tuyoogame/YooAsset/blob/master/Assets/UniTask.YooAsset~/README.md)

13
Docs/FAQ.md Normal file
View File

@@ -0,0 +1,13 @@
# 常见问题解答
### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
如果在打AssetBundle的时候选定的构建目标是安卓。那么在windows操作系统下编辑器的默认渲染模式为DX11我们需要修改编辑器的渲染模式可以通过UnityHub来修改启动项目的编辑器渲染模式[参考官方文档](https://docs.unity3d.com/cn/2019.4/Manual/CommandLineArguments.html)。
### 问题YooAsset的DLL引用丢失导致编译报错了
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
2. 关闭游戏工程后删除Assets同级目录下所有的csproj文件和sln文件。
3. 删除Library/ScriptAssemblies文件夹。
4. 重新打开游戏工程,然后点击某个脚本重新编译。

View File

@@ -11,7 +11,7 @@
## 系统特点 ## 系统特点
- **安全高效的分包方案** - **安全高效的分包方案**
基于资源对象的标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。 基于资源标签分包方案,自动对依赖资源包进行分类,避免人工维护成本。可以非常方便的实现零资源安装包,或者全量资源安装包。
- **强大灵活的打包系统** - **强大灵活的打包系统**
@@ -19,11 +19,11 @@
- **基于引用计数方案** - **基于引用计数方案**
基于引用计数的资源管理方案,可以帮助我们实现安全的资源卸载策略,更好的对内存管理,避免资源对象冗余。还有强大的分析器可帮助发现潜在的资源泄漏问题。 基于引用计数的管理方案,可以帮助我们实现安全的资源卸载策略,更好的对内存管理,避免资源对象冗余。还有强大的分析器可帮助发现潜在的资源泄漏问题。
- **多种模式自由切换** - **多种模式自由切换**
编辑器模拟模式,单机运行模式,联机运行模式。在编辑器模拟模式下,可以不构建资源包来模拟线上环境,在不修改任何代码的情况下,可以自由切换到其它模式。 编辑器模拟模式,单机运行模式,联机运行模式。在编辑器模拟模式下,可以不构建资源包来模拟真实环境,在不修改任何代码的情况下,可以自由切换到其它模式。
- **强大安全的加载系统** - **强大安全的加载系统**
@@ -53,6 +53,7 @@
5. [资源部署](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDeploy.md) 5. [资源部署](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDeploy.md)
5. [构建报告](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetReporter.md) 5. [构建报告](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetReporter.md)
5. [调试器](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDebugger.md) 5. [调试器](https://github.com/tuyoogame/YooAsset/blob/master/Docs/AssetDebugger.md)
5. [常见问题](https://github.com/tuyoogame/YooAsset/blob/master/Docs/FAQ.md)
## 代码教程 ## 代码教程
1. [初始化](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial1.md) 1. [初始化](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeTutorial1.md)
@@ -61,17 +62,19 @@
## 视频教程 ## 视频教程
[B站](https://space.bilibili.com/328590743/channel/seriesdetail?sid=2207858) [B站视频教程](https://space.bilibili.com/328590743/channel/seriesdetail?sid=2207858)
## 社区 ## 社区
QQ群963240451 QQ群**963240451**
[致谢名单](https://github.com/tuyoogame/YooAsset/blob/master/Docs/Contributor.md)👯 [致谢名单](https://github.com/tuyoogame/YooAsset/blob/master/Docs/Contributor.md)👯
[代码贡献](https://github.com/tuyoogame/YooAsset/blob/master/Docs/CodeStyle.md)
## 友情链接 ## 友情链接
[huatuo](https://github.com/focus-creative-games/huatuo):华佗是一个**特性完整、零成本、高性能、低内存**的近乎完美的c#热更新方案 [huatuo](https://github.com/focus-creative-games/huatuo)华佗是一个特性完整、零成本、高性能、低内存的近乎完美的c#热更新方案
[YooAssetEx](https://gitee.com/liu_zhongxiu/yoo-asset-ex/tree/master) YooAsset Odin扩展工具用于支持Unity2017和Unity2018版本。 [YooAssetEx](https://gitee.com/liu_zhongxiu/yoo-asset-ex/tree/master) YooAsset Odin扩展工具用于支持Unity2017和Unity2018版本。