Compare commits

...

44 Commits

Author SHA1 Message Date
hevinci
ca89113c67 Update CHANGELOG.md 2023-09-26 18:54:25 +08:00
hevinci
29d840b168 Update package.json 2023-09-26 18:54:19 +08:00
hevinci
41d1586109 fix #96 2023-09-26 18:51:00 +08:00
hevinci
8d6a1d0066 Update CHANGELOG.md 2023-09-25 19:09:20 +08:00
hevinci
bdfaaa0973 Update package.json 2023-09-25 19:09:11 +08:00
hevinci
30854e4b93 update asset settings
可以自定义设置参数DefaultYooFolderName
2023-09-25 18:25:34 +08:00
hevinci
54d89d957a update package system 2023-09-25 18:19:58 +08:00
hevinci
ade97605f9 update asset bundle collector
增加了AddressDisable规则
2023-09-25 18:19:48 +08:00
hevinci
bcb6443300 update asset bundle builder 2023-09-25 17:59:31 +08:00
hevinci
11386a7ec2 fix #161 2023-09-25 16:57:35 +08:00
hevinci
6fc45a758c fix #171 2023-09-25 16:21:02 +08:00
hevinci
dcdf41b7c2 fix #96 2023-09-25 15:38:49 +08:00
hevinci
1aaf569396 fix #167 2023-09-25 15:08:43 +08:00
hevinci
101960f6d8 fix #163 2023-09-25 12:18:55 +08:00
hevinci
49b188964c fix #169 2023-09-25 11:38:01 +08:00
何冠峰
5539d81c93 Merge pull request #153 from michael811125/main
判断分组不激活时,则不进行 CheckConfigError 的检测
2023-09-01 14:07:11 +08:00
MichaelO
ac3154e2ae 判断分组不激活时,则不进行 CheckConfigError 的检测 2023-09-01 13:43:03 +08:00
何冠峰
880b6d429d Merge pull request #151 from michael811125/main
加入 ExtdBuildTasks 进行 SBP 扩展,修复 Sprite 打包冗馀问题 (猫佬方案) + typo error
2023-08-28 10:30:58 +08:00
MichaelO
070db961fc corrected typo error 2023-08-26 15:03:12 +08:00
MichaelO
96ef379668 Merge branch 'tuyoogame:main' into main 2023-08-25 20:48:08 +08:00
hevinci
697a87721f Update CHANGELOG.md 2023-08-25 20:39:53 +08:00
hevinci
09cf93d852 Update package.json 2023-08-25 20:39:46 +08:00
hevinci
8725821a27 update download system 2023-08-25 20:15:58 +08:00
MichaelO
7ad8651ca0 加入 ExtdBuildTasks 进行 SBP 扩展,修复 Sprite 打包冗馀问题 2023-08-25 19:48:02 +08:00
hevinci
a2e57c6e90 update operation system 2023-08-25 17:37:49 +08:00
hevinci
6d37bca2a9 update asset bundle builder 2023-08-25 17:37:34 +08:00
hevinci
8471bb0f9a update asset bundle builder
暂时移除xxHash
2023-08-25 17:19:57 +08:00
何冠峰
05cb57db09 Merge pull request #150 from yingnierxiao/main
优化打包速度,提示编辑器启动速度,md5替换xxhash,速度提升一倍以上
2023-08-25 15:17:49 +08:00
yingnierxiao
064e9a1aa3 优化打包速度,提示编辑器启动速度,md5替换xxhash,速度提升一倍以上 2023-08-25 14:53:59 +08:00
hevinci
a618b6cf9e update asset bundle reporter 2023-08-18 18:31:15 +08:00
何冠峰
e3e810e702 Merge pull request #134 from gepengmiss/main
bundle viewer 功能扩展
2023-08-18 17:58:43 +08:00
hevinci
b4f0d6bab8 fix #138 2023-08-18 17:40:55 +08:00
hevinci
44cb4168cf update asset bundle collector 2023-08-17 22:13:31 +08:00
hevinci
559ed95999 update asset bundle collector
增加在配置错误的时候警示提示。
2023-08-17 21:53:51 +08:00
hevinci
b766df1d31 update shader variant collector 2023-08-17 21:18:21 +08:00
hevinci
057ff6b22b fix #130 2023-08-17 21:05:21 +08:00
hevinci
995b0c8050 update space shooter 2023-08-15 18:19:07 +08:00
hevinci
a2d4691f04 update package system
IQueryServices接口变更为IBuildinQueryServices
2023-08-14 12:27:43 +08:00
hevinci
ab2d7d4724 update operation system
Operation状态增加Processing处理中状态
2023-08-11 16:20:38 +08:00
hevinci
9b4abf86b6 update runtime code
可寻址模式默认支持通过资源路径加载。
2023-08-09 20:15:55 +08:00
hevinci
0331b7b6e3 update editor code 2023-08-09 20:15:33 +08:00
YGP
bd080eb19b modify bundleViewer func 2023-07-27 16:12:21 +08:00
YGP
ef231e213e modify bundleViewer func 2023-07-27 16:06:09 +08:00
YGP
a5900b5f99 ignore 2023-07-27 16:04:59 +08:00
56 changed files with 627 additions and 261 deletions

17
.gitignore vendored
View File

@@ -10,8 +10,23 @@
/[Ll]ogs/ /[Ll]ogs/
/[Mm]emoryCaptures/ /[Mm]emoryCaptures/
/Bundles/
/ProjectSettings/
/App/
/yoo/
/Assets/StreamingAssets
/Assets/StreamingAssets.meta
/Assets/Samples
/Assets/Samples.meta
/Packages
/UserSettings
# Asset meta data should only be ignored when the corresponding asset is also ignored # Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta
# Uncomment this line if you wish to ignore the asset store tools plugin # Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools* # /[Aa]ssets/AssetStoreTools*

View File

@@ -2,6 +2,91 @@
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.5.6-preview] - 2023-09-26
### Fixed
- (#172) 修复包裹初始化后package的状态不正确的问题。
## [1.5.5-preview] - 2023-09-25
### Fixed
- (#96) 修复了异步操作任务的完成回调在业务层触发异常时无法正常完成的问题。
- (#156) 修复了多个Package存在时服务器请求地址请求顺序不对的问题。
- (#163) 修复了Unity2019版本编译报错的问题。
- (#167) 修复了初始化时每次都会提示文件验证失败日志。
- (#171) 修复了IsNeedDownloadFromRemote里缺少判断依赖的资源是否下载 。
### Added
- 资源收集器里增加了AddressDisable规则。
- 资源收集器里FilterRuleData结构体增加了多个备选字段。
```c#
public struct FilterRuleData
{
public string AssetPath;
public string CollectPath;
public string GroupName;
public string UserData;
}
```
### Changed
- 可以设置自定义参数DefaultYooFolderName。
- 资源配置界面的分组不激活时,不再进行配置检测。
- SBP构建管线增加新构建参数用于修复图集资源冗余问题。
```c#
public class SBPBuildParameters
{
/// <summary>
/// 修复图集资源冗余问题
/// </summary>
public bool FixSpriteAtlasRedundancy = false;
}
```
## [1.5.4-preview] - 2023-08-25
优化了资源清单文件构建速度极大提升构建体验感谢yingnierxiao同学
### Fixed
- (#130) 修复了打包路径无效问题bug
- (#138) 修复了Unity不支持的格式的原生文件会报warning
### Added
- 新增了IBuildinQueryServices 接口。
### Changed
- 在开启可寻址模式下,默认支持通过资源路径加载资源对象。
- 优化了资源收集界面,增加了配置相关的警示提示。
- 优化了资源报告界面增加了BundleView界面里的builtin资源的列表显示。
- IQueryServices接口变更为IBuildinQueryServices接口
- EOperationStatus增加了正在处理的状态。
```c#
public enum EOperationStatus
{
None,
Processing,
Succeed,
Failed
}
```
## [1.5.3-preview] - 2023-07-28 ## [1.5.3-preview] - 2023-07-28
### Fixed ### Fixed

View File

@@ -22,7 +22,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public static string GetDefaultStreamingAssetsRoot() public static string GetDefaultStreamingAssetsRoot()
{ {
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.DefaultYooFolderName}/"; return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/";
} }
} }
} }

View File

@@ -28,6 +28,11 @@ namespace YooAsset.Editor
/// 缓存服务器端口 /// 缓存服务器端口
/// </summary> /// </summary>
public int CacheServerPort; public int CacheServerPort;
/// <summary>
/// 修复图集资源冗余问题
/// </summary>
public bool FixSpriteAtlasRedundancy = false;
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,68 @@
using System.Collections.Generic;
using UnityEditor.Build.Content;
using UnityEngine.U2D;
using UnityEditor.Build.Pipeline.Injector;
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEngine;
using System.Linq;
namespace UnityEditor.Build.Pipeline.Tasks
{
/// <summary>
/// Ref https://zhuanlan.zhihu.com/p/586918159
/// </summary>
public class RemoveSpriteAtlasRedundancy : IBuildTask
{
public int Version => 1;
[InjectContext]
IBundleWriteData writeDataParam;
public ReturnCode Run()
{
#if UNITY_2020_3_OR_NEWER
BundleWriteData writeData = (BundleWriteData)writeDataParam;
// 图集引用的精灵图片集合
HashSet<GUID> spriteGuids = new HashSet<GUID>();
foreach (var pair in writeData.FileToObjects)
{
foreach (ObjectIdentifier objectIdentifier in pair.Value)
{
var assetPath = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(SpriteAtlas))
{
var spritePaths = AssetDatabase.GetDependencies(assetPath, false);
foreach (string spritePath in spritePaths)
{
GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
spriteGuids.Add(spriteGuild);
}
}
}
}
// 移除图集引用的精力图片对象
foreach (var pair in writeData.FileToObjects)
{
List<ObjectIdentifier> objectIdentifiers = pair.Value;
for (int i = objectIdentifiers.Count - 1; i >= 0; i--)
{
ObjectIdentifier objectIdentifier = objectIdentifiers[i];
if (spriteGuids.Contains(objectIdentifier.guid))
{
if (objectIdentifier.localIdentifierInFile == 2800000)
{
// 删除图集散图的冗余纹理
objectIdentifiers.RemoveAt(i);
}
}
}
}
#endif
return ReturnCode.Success;
}
}
}

View File

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

View File

@@ -9,7 +9,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
{ {
public static class SBPBuildTasks public static class SBPBuildTasks
{ {
public static IList<IBuildTask> Create(string builtInShaderBundleName) public static IList<IBuildTask> Create(bool fixSpriteAtlasRedundancy, string builtInShaderBundleName)
{ {
var buildTasks = new List<IBuildTask>(); var buildTasks = new List<IBuildTask>();
@@ -33,6 +33,8 @@ namespace UnityEditor.Build.Pipeline.Tasks
// Packing // Packing
buildTasks.Add(new GenerateBundlePacking()); buildTasks.Add(new GenerateBundlePacking());
if (fixSpriteAtlasRedundancy)
buildTasks.Add(new RemoveSpriteAtlasRedundancy());
buildTasks.Add(new UpdateBundleObjectLayout()); buildTasks.Add(new UpdateBundleObjectLayout());
buildTasks.Add(new GenerateBundleCommands()); buildTasks.Add(new GenerateBundleCommands());
buildTasks.Add(new GenerateSubAssetPathMaps()); buildTasks.Add(new GenerateSubAssetPathMaps());

View File

@@ -33,7 +33,7 @@ namespace YooAsset.Editor
// 开始构建 // 开始构建
IBundleBuildResults buildResults; IBundleBuildResults buildResults;
var buildParameters = buildParametersContext.GetSBPBuildParameters(); var buildParameters = buildParametersContext.GetSBPBuildParameters();
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName); var taskList = SBPBuildTasks.Create(buildParametersContext.Parameters.SBPParameters.FixSpriteAtlasRedundancy, buildMapContext.Command.ShadersBundleName);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0) if (exitCode < 0)
{ {

View File

@@ -40,7 +40,12 @@ namespace YooAsset.Editor
manifest.OutputNameStyle = (int)buildParameters.OutputNameStyle; manifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
manifest.PackageName = buildParameters.PackageName; manifest.PackageName = buildParameters.PackageName;
manifest.PackageVersion = buildParameters.PackageVersion; manifest.PackageVersion = buildParameters.PackageVersion;
// 填充资源包集合
manifest.BundleList = GetAllPackageBundle(context); manifest.BundleList = GetAllPackageBundle(context);
CacheBundleIDs(manifest);
// 填充主资源集合
manifest.AssetList = GetAllPackageAsset(context, manifest); manifest.AssetList = GetAllPackageAsset(context, manifest);
// 更新Unity内置资源包的引用关系 // 更新Unity内置资源包的引用关系
@@ -147,7 +152,7 @@ namespace YooAsset.Editor
packageAsset.AssetPath = assetInfo.AssetPath; packageAsset.AssetPath = assetInfo.AssetPath;
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty; packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty;
packageAsset.AssetTags = assetInfo.AssetTags.ToArray(); packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
packageAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, manifest); packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
packageAsset.DependIDs = GetAssetBundleDependIDs(packageAsset.BundleID, assetInfo, manifest); packageAsset.DependIDs = GetAssetBundleDependIDs(packageAsset.BundleID, assetInfo, manifest);
result.Add(packageAsset); result.Add(packageAsset);
} }
@@ -156,12 +161,12 @@ namespace YooAsset.Editor
} }
private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PackageManifest manifest) private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PackageManifest manifest)
{ {
List<int> result = new List<int>(); HashSet<int> result = new HashSet<int>();
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos) foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{ {
if (dependAssetInfo.HasBundleName()) if (dependAssetInfo.HasBundleName())
{ {
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, manifest); int bundleID = GetCachedBundleID(dependAssetInfo.BundleName);
if (mainBundleID != bundleID) if (mainBundleID != bundleID)
{ {
if (result.Contains(bundleID) == false) if (result.Contains(bundleID) == false)
@@ -171,15 +176,6 @@ namespace YooAsset.Editor
} }
return result.ToArray(); return result.ToArray();
} }
private int GetAssetBundleID(string bundleName, PackageManifest manifest)
{
for (int index = 0; index < manifest.BundleList.Count; index++)
{
if (manifest.BundleList[index].BundleName == bundleName)
return index;
}
throw new Exception($"Not found bundle name : {bundleName}");
}
/// <summary> /// <summary>
/// 更新Unity内置资源包的引用关系 /// 更新Unity内置资源包的引用关系
@@ -212,7 +208,7 @@ namespace YooAsset.Editor
List<string> conflictAssetPathList = dependBundles.Intersect(shaderBundleReferenceList).ToList(); List<string> conflictAssetPathList = dependBundles.Intersect(shaderBundleReferenceList).ToList();
if (conflictAssetPathList.Count > 0) if (conflictAssetPathList.Count > 0)
{ {
List<int> newDependIDs = new List<int>(packageAsset.DependIDs); HashSet<int> newDependIDs = new HashSet<int>(packageAsset.DependIDs);
if (newDependIDs.Contains(shaderBundleId) == false) if (newDependIDs.Contains(shaderBundleId) == false)
newDependIDs.Add(shaderBundleId); newDependIDs.Add(shaderBundleId);
packageAsset.DependIDs = newDependIDs.ToArray(); packageAsset.DependIDs = newDependIDs.ToArray();
@@ -226,7 +222,7 @@ namespace YooAsset.Editor
// 更新资源包标签 // 更新资源包标签
var packageBundle = manifest.BundleList[shaderBundleId]; var packageBundle = manifest.BundleList[shaderBundleId];
List<string> newTags = new List<string>(packageBundle.Tags); HashSet<string> newTags = new HashSet<string>(packageBundle.Tags);
foreach (var tag in tagTemps) foreach (var tag in tagTemps)
{ {
if (newTags.Contains(tag) == false) if (newTags.Contains(tag) == false)
@@ -251,22 +247,21 @@ namespace YooAsset.Editor
private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000); private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000);
private readonly Dictionary<string, string[]> _cachedBundleDepends = new Dictionary<string, string[]>(10000); private readonly Dictionary<string, string[]> _cachedBundleDepends = new Dictionary<string, string[]>(10000);
private void CacheBundleIDs(PackageManifest manifest)
{
UnityEngine.Debug.Assert(manifest.BundleList.Count != 0, "Manifest bundle list is empty !");
for (int index = 0; index < manifest.BundleList.Count; index++)
{
string bundleName = manifest.BundleList[index].BundleName;
_cachedBundleID.Add(bundleName, index);
}
}
private void UpdateScriptPipelineReference(PackageManifest manifest, TaskBuilding_SBP.BuildResultContext buildResultContext) private void UpdateScriptPipelineReference(PackageManifest manifest, TaskBuilding_SBP.BuildResultContext buildResultContext)
{ {
int progressValue; int progressValue;
int totalCount = manifest.BundleList.Count; int totalCount = manifest.BundleList.Count;
// 缓存资源包ID
_cachedBundleID.Clear();
progressValue = 0;
foreach (var packageBundle in manifest.BundleList)
{
int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest);
_cachedBundleID.Add(packageBundle.BundleName, bundleID);
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
}
EditorTools.ClearProgressBar();
// 缓存资源包依赖 // 缓存资源包依赖
_cachedBundleDepends.Clear(); _cachedBundleDepends.Clear();
progressValue = 0; progressValue = 0;
@@ -283,7 +278,11 @@ namespace YooAsset.Editor
var depends = buildResultContext.Results.BundleInfos[packageBundle.BundleName].Dependencies; var depends = buildResultContext.Results.BundleInfos[packageBundle.BundleName].Dependencies;
_cachedBundleDepends.Add(packageBundle.BundleName, depends); _cachedBundleDepends.Add(packageBundle.BundleName, depends);
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount); int pro = ++progressValue;
if (pro % 100 == 0)
{
EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount);
}
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
@@ -291,7 +290,11 @@ namespace YooAsset.Editor
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle); packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle);
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount); int pro = ++progressValue;
if (pro % 100 == 0)
{
EditorTools.DisplayProgressBar("计算资源包引用关系", pro, totalCount);
}
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
@@ -300,17 +303,6 @@ namespace YooAsset.Editor
int progressValue; int progressValue;
int totalCount = manifest.BundleList.Count; int totalCount = manifest.BundleList.Count;
// 缓存资源包ID
_cachedBundleID.Clear();
progressValue = 0;
foreach (var packageBundle in manifest.BundleList)
{
int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest);
_cachedBundleID.Add(packageBundle.BundleName, bundleID);
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
}
EditorTools.ClearProgressBar();
// 缓存资源包依赖 // 缓存资源包依赖
_cachedBundleDepends.Clear(); _cachedBundleDepends.Clear();
progressValue = 0; progressValue = 0;
@@ -324,7 +316,11 @@ namespace YooAsset.Editor
var depends = buildResultContext.UnityManifest.GetDirectDependencies(packageBundle.BundleName); var depends = buildResultContext.UnityManifest.GetDirectDependencies(packageBundle.BundleName);
_cachedBundleDepends.Add(packageBundle.BundleName, depends); _cachedBundleDepends.Add(packageBundle.BundleName, depends);
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount); int pro = ++progressValue;
if (pro % 100 == 0)
{
EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount);
}
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
@@ -333,7 +329,11 @@ namespace YooAsset.Editor
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle); packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle);
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount); int pro = ++progressValue;
if (pro % 100 == 0)
{
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
}
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
@@ -354,7 +354,7 @@ namespace YooAsset.Editor
} }
} }
List<int> result = new List<int>(); HashSet<int> result = new HashSet<int>();
foreach (var bundleName in referenceList) foreach (var bundleName in referenceList)
{ {
int bundleID = GetCachedBundleID(bundleName); int bundleID = GetCachedBundleID(bundleName);

View File

@@ -33,7 +33,7 @@ namespace YooAsset.Editor
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000); Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
// 1. 检测配置合法性 // 1. 检测配置合法性
AssetBundleCollectorSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckPackageConfigError(packageName);
// 2. 获取所有收集器收集的资源 // 2. 获取所有收集器收集的资源
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName); var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);

View File

@@ -166,7 +166,7 @@ namespace YooAsset.Editor
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory); string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
foreach (string assetPath in findAssets) foreach (string assetPath in findAssets)
{ {
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath)) if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
{ {
if (result.ContainsKey(assetPath) == false) if (result.ContainsKey(assetPath) == false)
{ {
@@ -183,7 +183,7 @@ namespace YooAsset.Editor
else else
{ {
string assetPath = CollectPath; string assetPath = CollectPath;
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath)) if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
{ {
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule); var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
result.Add(assetPath, collectAssetInfo); result.Add(assetPath, collectAssetInfo);
@@ -204,6 +204,12 @@ namespace YooAsset.Editor
{ {
string address = collectInfoPair.Value.Address; string address = collectInfoPair.Value.Address;
string assetPath = collectInfoPair.Value.AssetPath; string assetPath = collectInfoPair.Value.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
if (address.StartsWith("Assets/") || address.StartsWith("assets/"))
throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}");
if (addressTemper.TryGetValue(address, out var existed) == false) if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath); addressTemper.Add(address, assetPath);
else else
@@ -288,11 +294,11 @@ namespace YooAsset.Editor
return true; return true;
} }
private bool IsCollectAsset(string assetPath) private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath)
{ {
// 根据规则设置过滤资源文件 // 根据规则设置过滤资源文件
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName); IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath)); return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath, CollectPath, group.GroupName, UserData));
} }
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath) private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
{ {
@@ -336,11 +342,13 @@ namespace YooAsset.Editor
List<string> result = new List<string>(depends.Length); List<string> result = new List<string>(depends.Length);
foreach (string assetPath in depends) foreach (string assetPath in depends)
{ {
// 注意:排除主资源对象
if (assetPath == mainAssetPath)
continue;
if (IsValidateAsset(assetPath, false)) if (IsValidateAsset(assetPath, false))
{ {
// 注意:排除主资源对象 result.Add(assetPath);
if (assetPath != mainAssetPath)
result.Add(assetPath);
} }
} }
return result; return result;

View File

@@ -44,6 +44,9 @@ namespace YooAsset.Editor
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false) if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}"); throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
// 当分组不是激活状态时,直接不进行检测
if (ActiveRuleName == nameof(DisableGroup)) return;
foreach (var collector in Collectors) foreach (var collector in Collectors)
{ {
collector.CheckConfigError(); collector.CheckConfigError();
@@ -103,6 +106,9 @@ namespace YooAsset.Editor
{ {
string address = collectInfoPair.Value.Address; string address = collectInfoPair.Value.Address;
string assetPath = collectInfoPair.Value.AssetPath; string assetPath = collectInfoPair.Value.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
if (addressTemper.TryGetValue(address, out var existed) == false) if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath); addressTemper.Add(address, assetPath);
else else

View File

@@ -83,6 +83,9 @@ namespace YooAsset.Editor
{ {
string address = collectInfoPair.Value.Address; string address = collectInfoPair.Value.Address;
string assetPath = collectInfoPair.Value.AssetPath; string assetPath = collectInfoPair.Value.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
if (addressTemper.TryGetValue(address, out var existed) == false) if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath); addressTemper.Add(address, assetPath);
else else

View File

@@ -61,9 +61,18 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 检测配置错误 /// 检测包裹配置错误
/// </summary> /// </summary>
public void CheckConfigError() public void CheckPackageConfigError(string packageName)
{
var package = GetPackage(packageName);
package.CheckConfigError();
}
/// <summary>
/// 检测所有配置错误
/// </summary>
public void CheckAllPackageConfigError()
{ {
foreach (var package in Packages) foreach (var package in Packages)
{ {
@@ -72,9 +81,9 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 修复配置错误 /// 修复所有配置错误
/// </summary> /// </summary>
public bool FixConfigError() public bool FixAllPackageConfigError()
{ {
bool isFixed = false; bool isFixed = false;
foreach (var package in Packages) foreach (var package in Packages)
@@ -92,16 +101,8 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public List<string> GetPackageAllTags(string packageName) public List<string> GetPackageAllTags(string packageName)
{ {
foreach (var package in Packages) var package = GetPackage(packageName);
{ return package.GetAllTags();
if (package.PackageName == packageName)
{
return package.GetAllTags();
}
}
Debug.LogWarning($"Not found package : {packageName}");
return new List<string>();
} }
/// <summary> /// <summary>
@@ -110,21 +111,27 @@ namespace YooAsset.Editor
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName) public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
{ {
if (string.IsNullOrEmpty(packageName)) if (string.IsNullOrEmpty(packageName))
throw new Exception("Build package name is null or mepty !"); throw new Exception("Build package name is null or empty !");
var package = GetPackage(packageName);
CollectCommand command = new CollectCommand(buildMode, packageName,
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
/// <summary>
/// 获取包裹类
/// </summary>
public AssetBundleCollectorPackage GetPackage(string packageName)
{
foreach (var package in Packages) foreach (var package in Packages)
{ {
if (package.PackageName == packageName) if (package.PackageName == packageName)
{ return package;
CollectCommand command = new CollectCommand(buildMode, packageName,
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
} }
throw new Exception($"Not found package : {packageName}");
throw new Exception($"Not found collector pacakge : {packageName}");
} }
} }
} }

View File

@@ -94,7 +94,8 @@ namespace YooAsset.Editor
typeof(AddressByFileName), typeof(AddressByFileName),
typeof(AddressByFilePath), typeof(AddressByFilePath),
typeof(AddressByFolderAndFileName), typeof(AddressByFolderAndFileName),
typeof(AddressByGroupAndFileName) typeof(AddressByGroupAndFileName),
typeof(AddressDisable)
}; };
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule)); var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
@@ -161,7 +162,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public static void FixFile() public static void FixFile()
{ {
bool isFixed = Setting.FixConfigError(); bool isFixed = Setting.FixAllPackageConfigError();
if (isFixed) if (isFixed)
{ {
IsDirty = true; IsDirty = true;

View File

@@ -26,6 +26,7 @@ namespace YooAsset.Editor
private List<RuleDisplayName> _filterRuleList; private List<RuleDisplayName> _filterRuleList;
private Button _settingsButton; private Button _settingsButton;
private VisualElement _helpBoxContainer;
private VisualElement _setting1Container; private VisualElement _setting1Container;
private VisualElement _setting2Container; private VisualElement _setting2Container;
private Toggle _showPackageToogle; private Toggle _showPackageToogle;
@@ -82,6 +83,9 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
// 警示栏
_helpBoxContainer = root.Q("HelpBoxContainer");
// 公共设置相关 // 公共设置相关
_settingsButton = root.Q<Button>("SettingsButton"); _settingsButton = root.Q<Button>("SettingsButton");
_settingsButton.clicked += SettingsBtn_clicked; _settingsButton.clicked += SettingsBtn_clicked;
@@ -328,6 +332,26 @@ namespace YooAsset.Editor
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName); _uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias); _showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
// 警示框
#if UNITY_2020_3_OR_NEWER
_helpBoxContainer.Clear();
if (_enableAddressableToogle.value && _locationToLowerToogle.value)
{
var helpBox = new HelpBox("无法同时开启[Enable Addressable]选项和[Location To Lower]选项", HelpBoxMessageType.Error);
_helpBoxContainer.Add(helpBox);
}
if (AssetBundleCollectorSettingData.Setting.Packages.Count > 1 && _uniqueBundleNameToogle.value == false)
{
var helpBox = new HelpBox("检测到当前配置存在多个Package建议开启[Unique Bundle Name]选项", HelpBoxMessageType.Warning);
_helpBoxContainer.Add(helpBox);
}
if (_helpBoxContainer.childCount > 0)
_helpBoxContainer.style.display = DisplayStyle.Flex;
else
_helpBoxContainer.style.display = DisplayStyle.None;
#endif
// 设置栏
if (_showSettings) if (_showSettings)
{ {
_setting1Container.style.display = DisplayStyle.Flex; _setting1Container.style.display = DisplayStyle.Flex;

View File

@@ -1,4 +1,4 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;"> <uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" /> <ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" /> <ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
@@ -6,6 +6,7 @@
<ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" /> <ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar> </uie:Toolbar>
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;"> <ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
<ui:Button text="Settings" display-tooltip-when-elided="true" name="SettingsButton" /> <ui:Button text="Settings" display-tooltip-when-elided="true" name="SettingsButton" />
<ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;"> <ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />

View File

@@ -4,10 +4,16 @@ namespace YooAsset.Editor
public struct FilterRuleData public struct FilterRuleData
{ {
public string AssetPath; public string AssetPath;
public string CollectPath;
public string GroupName;
public string UserData;
public FilterRuleData(string assetPath) public FilterRuleData(string assetPath, string collectPath, string groupName, string userData)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = collectPath;
GroupName = groupName;
UserData = userData;
} }
} }

View File

@@ -8,13 +8,6 @@ namespace YooAsset.Editor
public string GroupName; public string GroupName;
public string UserData; public string UserData;
public PackRuleData(string assetPath)
{
AssetPath = assetPath;
CollectPath = string.Empty;
GroupName = string.Empty;
UserData = string.Empty;
}
public PackRuleData(string assetPath, string collectPath, string groupName, string userData) public PackRuleData(string assetPath, string collectPath, string groupName, string userData)
{ {
AssetPath = assetPath; AssetPath = assetPath;

View File

@@ -2,6 +2,15 @@
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[DisplayName("定位地址: 禁用")]
public class AddressDisable : IAddressRule
{
string IAddressRule.GetAssetAddress(AddressRuleData data)
{
return string.Empty;
}
}
[DisplayName("定位地址: 文件名")] [DisplayName("定位地址: 文件名")]
public class AddressByFileName : IAddressRule public class AddressByFileName : IAddressRule
{ {
@@ -16,7 +25,7 @@ namespace YooAsset.Editor
{ {
string IAddressRule.GetAssetAddress(AddressRuleData data) string IAddressRule.GetAssetAddress(AddressRuleData data)
{ {
return data.AssetPath; throw new System.Exception("可寻址模式下已经默认支持通过资源路径加载!");
} }
} }

View File

@@ -349,10 +349,24 @@ namespace YooAsset.Editor
private void FillIncludeListView(ReportBundleInfo bundleInfo) private void FillIncludeListView(ReportBundleInfo bundleInfo)
{ {
List<ReportAssetInfo> containsList = new List<ReportAssetInfo>(); List<ReportAssetInfo> containsList = new List<ReportAssetInfo>();
HashSet<string> mainAssetDic = new HashSet<string>();
foreach (var assetInfo in _buildReport.AssetInfos) foreach (var assetInfo in _buildReport.AssetInfos)
{ {
if (assetInfo.MainBundleName == bundleInfo.BundleName) if (assetInfo.MainBundleName == bundleInfo.BundleName)
{
mainAssetDic.Add(assetInfo.AssetPath);
containsList.Add(assetInfo); containsList.Add(assetInfo);
}
}
foreach (string assetPath in bundleInfo.AllBuiltinAssets)
{
if (mainAssetDic.Contains(assetPath) == false)
{
var assetInfo = new ReportAssetInfo();
assetInfo.AssetPath = assetPath;
assetInfo.AssetGUID = "--";
containsList.Add(assetInfo);
}
} }
_includeListView.Clear(); _includeListView.Clear();
@@ -376,6 +390,16 @@ namespace YooAsset.Editor
element.Add(label); element.Add(label);
} }
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{ {
var label = new Label(); var label = new Label();
label.name = "Label2"; label.name = "Label2";
@@ -397,6 +421,10 @@ namespace YooAsset.Editor
var label1 = element.Q<Label>("Label1"); var label1 = element.Q<Label>("Label1");
label1.text = assetInfo.AssetPath; label1.text = assetInfo.AssetPath;
// Asset Source
var label3 = element.Q<Label>("Label3");
label3.text = assetInfo.AssetGUID != "--" ? "Main Asset" : "Builtin Asset";
// GUID // GUID
var label2 = element.Q<Label>("Label2"); var label2 = element.Q<Label>("Label2");
label2.text = assetInfo.AssetGUID; label2.text = assetInfo.AssetGUID;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a0319abb8eae03b4b88e8f900fe2276c guid: 8875000dff445624da4d6a2d6ef2f446
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -12,6 +12,7 @@
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;"> <ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;"> <uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" /> <uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Asset Source" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" /> <uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar> </uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" /> <ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 56d6dbe0d65ce334a8996beb19612989 guid: cf2a9340bb457594d9bc1f80b84a89f6
ScriptedImporter: ScriptedImporter:
internalIDToNameTable: [] internalIDToNameTable: []
externalObjects: {} externalObjects: {}

View File

@@ -153,7 +153,7 @@ namespace YooAsset.Editor
guids = AssetDatabase.FindAssets($"t:{searchType}", searchInFolders); guids = AssetDatabase.FindAssets($"t:{searchType}", searchInFolders);
// 注意AssetDatabase.FindAssets()可能会获取到重复的资源 // 注意AssetDatabase.FindAssets()可能会获取到重复的资源
List<string> result = new List<string>(); HashSet<string> result = new HashSet<string>();
for (int i = 0; i < guids.Length; i++) for (int i = 0; i < guids.Length; i++)
{ {
string guid = guids[i]; string guid = guids[i];

View File

@@ -30,17 +30,22 @@ namespace YooAsset.Editor
public class ShaderVariantInfo public class ShaderVariantInfo
{ {
/// <summary> /// <summary>
/// Shader asset path in editor. /// 着色器资源路径.
/// </summary> /// </summary>
public string AssetPath; public string AssetPath;
/// <summary> /// <summary>
/// Shader name. /// 着色器名称
/// </summary> /// </summary>
public string ShaderName; public string ShaderName;
/// <summary> /// <summary>
/// Shader variants elements list. /// 着色器变种总数
/// </summary>
public int ShaderVariantCount = 0;
/// <summary>
/// 着色器变种列表
/// </summary> /// </summary>
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000); public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
} }
@@ -71,6 +76,7 @@ namespace YooAsset.Editor
element.PassType = passType; element.PassType = passType;
element.Keywords = keywords; element.Keywords = keywords;
info.ShaderVariantElements.Add(element); info.ShaderVariantElements.Add(element);
info.ShaderVariantCount++;
} }
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName) private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
{ {

View File

@@ -44,12 +44,16 @@ namespace YooAsset
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return EOperationStatus.None; return EOperationStatus.None;
if (Provider.Status == ProviderBase.EStatus.Failed)
return EOperationStatus.Failed; var status = Provider.Status;
else if (Provider.Status == ProviderBase.EStatus.Succeed) if (status == ProviderBase.EStatus.None)
return EOperationStatus.Succeed;
else
return EOperationStatus.None; return EOperationStatus.None;
else if (status == ProviderBase.EStatus.Succeed)
return EOperationStatus.Succeed;
else if (status == ProviderBase.EStatus.Failed)
return EOperationStatus.Failed;
else
return EOperationStatus.Processing;
} }
} }

View File

@@ -46,7 +46,7 @@ namespace YooAsset
} }
private static string CreateDefaultBuildinRoot() private static string CreateDefaultBuildinRoot()
{ {
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName); return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
} }
private static string CreateDefaultSandboxRoot() private static string CreateDefaultSandboxRoot()
{ {
@@ -54,11 +54,11 @@ namespace YooAsset
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。 // 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath); string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
projectPath = PathUtility.RegularPath(projectPath); projectPath = PathUtility.RegularPath(projectPath);
return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName); return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#elif UNITY_STANDALONE #elif UNITY_STANDALONE
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName); return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#else #else
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName); return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#endif #endif
} }

View File

@@ -28,14 +28,13 @@ namespace YooAsset
public void DeleteFiles() public void DeleteFiles()
{ {
if (File.Exists(DataFilePath)) try
{ {
File.Delete(DataFilePath); Directory.Delete(FileRootPath, true);
} }
catch (System.Exception e)
if (File.Exists(InfoFilePath))
{ {
File.Delete(InfoFilePath); YooLogger.Warning($"Failed delete cache bundle folder : {e}");
} }
} }
} }

View File

@@ -51,6 +51,9 @@ namespace YooAsset
// 准备下载 // 准备下载
if (_steps == ESteps.PrepareDownload) if (_steps == ESteps.PrepareDownload)
{ {
// 获取请求地址
_requestURL = GetRequestURL();
// 重置变量 // 重置变量
_downloadProgress = 0f; _downloadProgress = 0f;
_downloadedBytes = 0; _downloadedBytes = 0;
@@ -59,14 +62,16 @@ namespace YooAsset
_isAbort = false; _isAbort = false;
_latestDownloadBytes = 0; _latestDownloadBytes = 0;
_latestDownloadRealtime = Time.realtimeSinceStartup; _latestDownloadRealtime = Time.realtimeSinceStartup;
// 重置计时器
if(_tryAgainTimer > 0f)
YooLogger.Warning($"Try again download : {_requestURL}");
_tryAgainTimer = 0f; _tryAgainTimer = 0f;
// 删除临时文件 // 删除临时文件
if (File.Exists(_tempFilePath)) if (File.Exists(_tempFilePath))
File.Delete(_tempFilePath); File.Delete(_tempFilePath);
// 获取请求地址
_requestURL = GetRequestURL();
_steps = ESteps.CreateDownloader; _steps = ESteps.CreateDownloader;
} }
@@ -197,7 +202,6 @@ namespace YooAsset
_failedTryAgain--; _failedTryAgain--;
_steps = ESteps.PrepareDownload; _steps = ESteps.PrepareDownload;
ReportWarning(); ReportWarning();
YooLogger.Warning($"Try again download : {_requestURL}");
} }
} }
} }

View File

@@ -91,6 +91,9 @@ namespace YooAsset
// 创建下载器 // 创建下载器
if (_steps == ESteps.PrepareDownload) if (_steps == ESteps.PrepareDownload)
{ {
// 获取请求地址
_requestURL = GetRequestURL();
// 重置变量 // 重置变量
_downloadProgress = 0f; _downloadProgress = 0f;
_downloadedBytes = 0; _downloadedBytes = 0;
@@ -99,11 +102,13 @@ namespace YooAsset
_isAbort = false; _isAbort = false;
_latestDownloadBytes = 0; _latestDownloadBytes = 0;
_latestDownloadRealtime = Time.realtimeSinceStartup; _latestDownloadRealtime = Time.realtimeSinceStartup;
_tryAgainTimer = 0f;
_fileOriginLength = 0; _fileOriginLength = 0;
// 获取请求地址 // 重置计时器
_requestURL = GetRequestURL(); if (_tryAgainTimer > 0f)
YooLogger.Warning($"Try again download : {_requestURL}");
_tryAgainTimer = 0f;
_steps = ESteps.CreateDownloader; _steps = ESteps.CreateDownloader;
} }
@@ -257,7 +262,6 @@ namespace YooAsset
_failedTryAgain--; _failedTryAgain--;
_steps = ESteps.PrepareDownload; _steps = ESteps.PrepareDownload;
ReportWarning(); ReportWarning();
YooLogger.Warning($"Try again download : {_requestURL}");
} }
} }
} }

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
public class RequestHelper
{
/// <summary>
/// 记录网络请求失败事件的次数
/// </summary>
private static readonly Dictionary<string, int> _requestFailedRecorder = new Dictionary<string, int>(1000);
/// <summary>
/// 记录请求失败事件
/// </summary>
public static void RecordRequestFailed(string packageName, string eventName)
{
string key = $"{packageName}_{eventName}";
if (_requestFailedRecorder.ContainsKey(key) == false)
_requestFailedRecorder.Add(key, 0);
_requestFailedRecorder[key]++;
}
/// <summary>
/// 获取请求失败的次数
/// </summary>
public static int GetRequestFailedCount(string packageName, string eventName)
{
string key = $"{packageName}_{eventName}";
if (_requestFailedRecorder.ContainsKey(key) == false)
_requestFailedRecorder.Add(key, 0);
return _requestFailedRecorder[key];
}
}
}

View File

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

View File

@@ -88,7 +88,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 内置资源查询服务接口 /// 内置资源查询服务接口
/// </summary> /// </summary>
public IQueryServices QueryServices = null; public IBuildinQueryServices BuildinQueryServices = null;
/// <summary>
/// 分发资源查询服务接口
/// </summary>
public IDeliveryQueryServices DeliveryQueryServices = null;
/// <summary> /// <summary>
/// 远端资源地址查询服务类 /// 远端资源地址查询服务类
@@ -104,7 +109,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 内置资源查询服务接口 /// 内置资源查询服务接口
/// </summary> /// </summary>
public IQueryServices QueryServices = null; public IBuildinQueryServices BuildinQueryServices = null;
/// <summary> /// <summary>
/// 远端资源地址查询服务类 /// 远端资源地址查询服务类

View File

@@ -73,13 +73,18 @@ namespace YooAsset
internal abstract void Start(); internal abstract void Start();
internal abstract void Update(); internal abstract void Update();
internal void Finish()
internal void SetFinish()
{ {
Progress = 1f; Progress = 1f;
_callback?.Invoke(this); _callback?.Invoke(this); //注意如果完成回调内发生异常会导致Task无限期等待
if (_taskCompletionSource != null) if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null); _taskCompletionSource.TrySetResult(null);
} }
internal void SetStart()
{
Status = EOperationStatus.Processing;
}
/// <summary> /// <summary>
/// 清空完成回调 /// 清空完成回调

View File

@@ -4,6 +4,7 @@ namespace YooAsset
public enum EOperationStatus public enum EOperationStatus
{ {
None, None,
Processing,
Succeed, Succeed,
Failed Failed
} }

View File

@@ -7,8 +7,7 @@ namespace YooAsset
internal class OperationSystem internal class OperationSystem
{ {
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100); private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
private static readonly List<AsyncOperationBase> _addList = new List<AsyncOperationBase>(100); private static readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100);
private static readonly List<AsyncOperationBase> _removeList = new List<AsyncOperationBase>(100);
// 计时器相关 // 计时器相关
private static Stopwatch _watch; private static Stopwatch _watch;
@@ -47,39 +46,26 @@ namespace YooAsset
_frameTime = _watch.ElapsedMilliseconds; _frameTime = _watch.ElapsedMilliseconds;
// 添加新的异步操作 // 添加新的异步操作
if (_addList.Count > 0) if (_newList.Count > 0)
{ {
for (int i = 0; i < _addList.Count; i++) _operations.AddRange(_newList);
{ _newList.Clear();
var operation = _addList[i];
_operations.Add(operation);
}
_addList.Clear();
} }
// 更新所有的异步操作 // 更新所有的异步操作
foreach (var operation in _operations) for (int i = _operations.Count - 1; i >= 0; i--)
{ {
if (IsBusy) if (IsBusy)
break; break;
var operation = _operations[i];
operation.Update(); operation.Update();
if (operation.IsDone) if (operation.IsDone)
{ {
_removeList.Add(operation); _operations.RemoveAt(i);
operation.Finish(); operation.SetFinish(); //注意:如果业务端发生异常,保证异步操作提前移除。
} }
} }
// 移除已经完成的异步操作
if (_removeList.Count > 0)
{
foreach (var operation in _removeList)
{
_operations.Remove(operation);
}
_removeList.Clear();
}
} }
/// <summary> /// <summary>
@@ -88,8 +74,7 @@ namespace YooAsset
public static void DestroyAll() public static void DestroyAll()
{ {
_operations.Clear(); _operations.Clear();
_addList.Clear(); _newList.Clear();
_removeList.Clear();
_watch = null; _watch = null;
_frameTime = 0; _frameTime = 0;
MaxTimeSlice = long.MaxValue; MaxTimeSlice = long.MaxValue;
@@ -100,7 +85,8 @@ namespace YooAsset
/// </summary> /// </summary>
public static void StartOperation(AsyncOperationBase operation) public static void StartOperation(AsyncOperationBase operation)
{ {
_addList.Add(operation); _newList.Add(operation);
operation.SetStart();
operation.Start(); operation.Start();
} }
} }

View File

@@ -97,7 +97,7 @@ namespace YooAsset
Manifest.AssetDic = new Dictionary<string, PackageAsset>(_packageAssetCount); Manifest.AssetDic = new Dictionary<string, PackageAsset>(_packageAssetCount);
if (Manifest.EnableAddressable) if (Manifest.EnableAddressable)
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount); Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 3);
else else
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 2); Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 2);
@@ -130,15 +130,6 @@ namespace YooAsset
Manifest.AssetDic.Add(assetPath, packageAsset); Manifest.AssetDic.Add(assetPath, packageAsset);
// 填充AssetPathMapping1 // 填充AssetPathMapping1
if (Manifest.EnableAddressable)
{
string location = packageAsset.Address;
if (Manifest.AssetPathMapping1.ContainsKey(location))
throw new System.Exception($"Address have existed : {location}");
else
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
}
else
{ {
string location = packageAsset.AssetPath; string location = packageAsset.AssetPath;
if (Manifest.LocationToLower) if (Manifest.LocationToLower)
@@ -146,7 +137,7 @@ namespace YooAsset
// 添加原生路径的映射 // 添加原生路径的映射
if (Manifest.AssetPathMapping1.ContainsKey(location)) if (Manifest.AssetPathMapping1.ContainsKey(location))
throw new System.Exception($"AssetPath have existed : {location}"); throw new System.Exception($"Location have existed : {location}");
else else
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath); Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
@@ -155,11 +146,22 @@ namespace YooAsset
{ {
string locationWithoutExtension = PathUtility.RemoveExtension(location); string locationWithoutExtension = PathUtility.RemoveExtension(location);
if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension)) if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}"); YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
else else
Manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath); Manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
} }
} }
if (Manifest.EnableAddressable)
{
string location = packageAsset.Address;
if (string.IsNullOrEmpty(location) == false)
{
if (Manifest.AssetPathMapping1.ContainsKey(location))
throw new System.Exception($"Location have existed : {location}");
else
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
}
}
// 填充AssetPathMapping2 // 填充AssetPathMapping2
if (Manifest.IncludeAssetGUID) if (Manifest.IncludeAssetGUID)
@@ -209,6 +211,10 @@ namespace YooAsset
packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle); packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle); Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
// 注意原始文件可能存在相同的CacheGUID
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
Manifest.CacheGUIDs.Add(packageBundle.CacheGUID);
_packageBundleCount--; _packageBundleCount--;
Progress = 1f - _packageBundleCount / _progressTotalValue; Progress = 1f - _packageBundleCount / _progressTotalValue;
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)

View File

@@ -11,7 +11,6 @@ namespace YooAsset
Done, Done,
} }
private static int RequestCount = 0;
private readonly IRemoteServices _remoteServices; private readonly IRemoteServices _remoteServices;
private readonly string _packageName; private readonly string _packageName;
private readonly string _packageVersion; private readonly string _packageVersion;
@@ -19,6 +18,7 @@ namespace YooAsset
private UnityWebFileRequester _downloader1; private UnityWebFileRequester _downloader1;
private UnityWebFileRequester _downloader2; private UnityWebFileRequester _downloader2;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private int _requestCount = 0;
internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout) internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
{ {
@@ -29,7 +29,7 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
RequestCount++; _requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(DownloadManifestOperation));
_steps = ESteps.DownloadPackageHashFile; _steps = ESteps.DownloadPackageHashFile;
} }
internal override void Update() internal override void Update()
@@ -58,6 +58,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloader1.GetError(); Error = _downloader1.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(DownloadManifestOperation));
} }
else else
{ {
@@ -88,6 +89,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloader2.GetError(); Error = _downloader2.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(DownloadManifestOperation));
} }
else else
{ {
@@ -102,10 +104,10 @@ namespace YooAsset
private string GetDownloadRequestURL(string fileName) private string GetDownloadRequestURL(string fileName)
{ {
// 轮流返回请求地址 // 轮流返回请求地址
if (RequestCount % 2 == 0) if (_requestCount % 2 == 0)
return _remoteServices.GetRemoteFallbackURL(fileName);
else
return _remoteServices.GetRemoteMainURL(fileName); return _remoteServices.GetRemoteMainURL(fileName);
else
return _remoteServices.GetRemoteFallbackURL(fileName);
} }
} }
} }

View File

@@ -13,7 +13,6 @@ namespace YooAsset
Done, Done,
} }
private static int RequestCount = 0;
private readonly IRemoteServices _remoteServices; private readonly IRemoteServices _remoteServices;
private readonly string _packageName; private readonly string _packageName;
private readonly string _packageVersion; private readonly string _packageVersion;
@@ -23,6 +22,7 @@ namespace YooAsset
private DeserializeManifestOperation _deserializer; private DeserializeManifestOperation _deserializer;
private byte[] _fileData; private byte[] _fileData;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary> /// <summary>
/// 加载的清单实例 /// 加载的清单实例
@@ -39,7 +39,7 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
RequestCount++; _requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(LoadRemoteManifestOperation));
_steps = ESteps.DownloadPackageHashFile; _steps = ESteps.DownloadPackageHashFile;
} }
internal override void Update() internal override void Update()
@@ -90,6 +90,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloader.GetError(); Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(LoadRemoteManifestOperation));
} }
else else
{ {
@@ -141,10 +142,10 @@ namespace YooAsset
private string GetDownloadRequestURL(string fileName) private string GetDownloadRequestURL(string fileName)
{ {
// 轮流返回请求地址 // 轮流返回请求地址
if (RequestCount % 2 == 0) if (_requestCount % 2 == 0)
return _remoteServices.GetRemoteFallbackURL(fileName);
else
return _remoteServices.GetRemoteMainURL(fileName); return _remoteServices.GetRemoteMainURL(fileName);
else
return _remoteServices.GetRemoteFallbackURL(fileName);
} }
} }
} }

View File

@@ -10,13 +10,13 @@ namespace YooAsset
Done, Done,
} }
private static int RequestCount = 0;
private readonly IRemoteServices _remoteServices; private readonly IRemoteServices _remoteServices;
private readonly string _packageName; private readonly string _packageName;
private readonly string _packageVersion; private readonly string _packageVersion;
private readonly int _timeout; private readonly int _timeout;
private UnityWebDataRequester _downloader; private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary> /// <summary>
/// 包裹哈希值 /// 包裹哈希值
@@ -33,7 +33,7 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
RequestCount++; _requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageHashOperation));
_steps = ESteps.DownloadPackageHash; _steps = ESteps.DownloadPackageHash;
} }
internal override void Update() internal override void Update()
@@ -62,6 +62,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloader.GetError(); Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageHashOperation));
} }
else else
{ {
@@ -88,10 +89,10 @@ namespace YooAsset
string url; string url;
// 轮流返回请求地址 // 轮流返回请求地址
if (RequestCount % 2 == 0) if (_requestCount % 2 == 0)
url = _remoteServices.GetRemoteFallbackURL(fileName);
else
url = _remoteServices.GetRemoteMainURL(fileName); url = _remoteServices.GetRemoteMainURL(fileName);
else
url = _remoteServices.GetRemoteFallbackURL(fileName);
return url; return url;
} }

View File

@@ -10,13 +10,13 @@ namespace YooAsset
Done, Done,
} }
private static int RequestCount = 0;
private readonly IRemoteServices _remoteServices; private readonly IRemoteServices _remoteServices;
private readonly string _packageName; private readonly string _packageName;
private readonly bool _appendTimeTicks; private readonly bool _appendTimeTicks;
private readonly int _timeout; private readonly int _timeout;
private UnityWebDataRequester _downloader; private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary> /// <summary>
/// 包裹版本 /// 包裹版本
@@ -33,7 +33,7 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
RequestCount++; _requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageVersionOperation));
_steps = ESteps.DownloadPackageVersion; _steps = ESteps.DownloadPackageVersion;
} }
internal override void Update() internal override void Update()
@@ -62,6 +62,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _downloader.GetError(); Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageVersionOperation));
} }
else else
{ {
@@ -88,10 +89,10 @@ namespace YooAsset
string url; string url;
// 轮流返回请求地址 // 轮流返回请求地址
if (RequestCount % 2 == 0) if (_requestCount % 2 == 0)
url = _remoteServices.GetRemoteFallbackURL(fileName);
else
url = _remoteServices.GetRemoteMainURL(fileName); url = _remoteServices.GetRemoteMainURL(fileName);
else
url = _remoteServices.GetRemoteFallbackURL(fileName);
// 在URL末尾添加时间戳 // 在URL末尾添加时间戳
if (_appendTimeTicks) if (_appendTimeTicks)

View File

@@ -82,6 +82,12 @@ namespace YooAsset
[NonSerialized] [NonSerialized]
public Dictionary<string, string> AssetPathMapping2; public Dictionary<string, string> AssetPathMapping2;
/// <summary>
/// 该资源清单所有文件的缓存GUID集合
/// </summary>
[NonSerialized]
public HashSet<string> CacheGUIDs = new HashSet<string>();
/// <summary> /// <summary>
/// 尝试映射为资源路径 /// 尝试映射为资源路径
@@ -191,12 +197,7 @@ namespace YooAsset
/// </summary> /// </summary>
public bool IsIncludeBundleFile(string cacheGUID) public bool IsIncludeBundleFile(string cacheGUID)
{ {
foreach (var packageBundle in BundleList) return CacheGUIDs.Contains(cacheGUID);
{
if (packageBundle.CacheGUID == cacheGUID)
return true;
}
return false;
} }
/// <summary> /// <summary>

View File

@@ -10,7 +10,8 @@ namespace YooAsset
// 参数相关 // 参数相关
private string _packageName; private string _packageName;
private IQueryServices _queryServices; private IBuildinQueryServices _buildinQueryServices;
private IDeliveryQueryServices _deliveryQueryServices;
private IRemoteServices _remoteServices; private IRemoteServices _remoteServices;
public IRemoteServices RemoteServices public IRemoteServices RemoteServices
@@ -21,10 +22,11 @@ namespace YooAsset
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices) public InitializationOperation InitializeAsync(string packageName, IBuildinQueryServices buildinQueryServices, IDeliveryQueryServices deliveryQueryServices, IRemoteServices remoteServices)
{ {
_packageName = packageName; _packageName = packageName;
_queryServices = queryServices; _buildinQueryServices = buildinQueryServices;
_deliveryQueryServices = deliveryQueryServices;
_remoteServices = remoteServices; _remoteServices = remoteServices;
var operation = new HostPlayModeInitializationOperation(this, packageName); var operation = new HostPlayModeInitializationOperation(this, packageName);
@@ -54,7 +56,7 @@ namespace YooAsset
// 查询相关 // 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle) private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{ {
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName); return _buildinQueryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
} }
private bool IsCachedPackageBundle(PackageBundle packageBundle) private bool IsCachedPackageBundle(PackageBundle packageBundle)
{ {
@@ -62,11 +64,11 @@ namespace YooAsset
} }
private bool IsDeliveryPackageBundle(PackageBundle packageBundle) private bool IsDeliveryPackageBundle(PackageBundle packageBundle)
{ {
return _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName); return _deliveryQueryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
} }
private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle) private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle)
{ {
return _queryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName); return _deliveryQueryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName);
} }
#region IPlayModeServices接口 #region IPlayModeServices接口

View File

@@ -10,7 +10,7 @@ namespace YooAsset
// 参数相关 // 参数相关
private string _packageName; private string _packageName;
private IQueryServices _queryServices; private IBuildinQueryServices _buildinQueryServices;
private IRemoteServices _remoteServices; private IRemoteServices _remoteServices;
public IRemoteServices RemoteServices public IRemoteServices RemoteServices
@@ -21,10 +21,10 @@ namespace YooAsset
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices) public InitializationOperation InitializeAsync(string packageName, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
{ {
_packageName = packageName; _packageName = packageName;
_queryServices = queryServices; _buildinQueryServices = buildinQueryServices;
_remoteServices = remoteServices; _remoteServices = remoteServices;
var operation = new WebPlayModeInitializationOperation(this, packageName); var operation = new WebPlayModeInitializationOperation(this, packageName);
@@ -44,7 +44,7 @@ namespace YooAsset
// 查询相关 // 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle) private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{ {
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName); return _buildinQueryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
} }
#region IPlayModeServices接口 #region IPlayModeServices接口

View File

@@ -122,7 +122,8 @@ namespace YooAsset
var initializeParameters = parameters as HostPlayModeParameters; var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync( initializeOperation = hostPlayModeImpl.InitializeAsync(
PackageName, PackageName,
initializeParameters.QueryServices, initializeParameters.BuildinQueryServices,
initializeParameters.DeliveryQueryServices,
initializeParameters.RemoteServices initializeParameters.RemoteServices
); );
} }
@@ -138,7 +139,7 @@ namespace YooAsset
var initializeParameters = parameters as WebPlayModeParameters; var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync( initializeOperation = webPlayModeImpl.InitializeAsync(
PackageName, PackageName,
initializeParameters.QueryServices, initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices initializeParameters.RemoteServices
); );
} }
@@ -187,8 +188,10 @@ namespace YooAsset
if (parameters is HostPlayModeParameters) if (parameters is HostPlayModeParameters)
{ {
var hostPlayModeParameters = parameters as HostPlayModeParameters; var hostPlayModeParameters = parameters as HostPlayModeParameters;
if (hostPlayModeParameters.QueryServices == null) if (hostPlayModeParameters.BuildinQueryServices == null)
throw new Exception($"{nameof(IQueryServices)} is null."); throw new Exception($"{nameof(IBuildinQueryServices)} is null.");
if (hostPlayModeParameters.DeliveryQueryServices == null)
throw new Exception($"{nameof(IDeliveryQueryServices)} is null.");
if (hostPlayModeParameters.RemoteServices == null) if (hostPlayModeParameters.RemoteServices == null)
throw new Exception($"{nameof(IRemoteServices)} is null."); throw new Exception($"{nameof(IRemoteServices)} is null.");
} }
@@ -365,17 +368,7 @@ namespace YooAsset
{ {
DebugCheckInitialize(); DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
if (assetInfo.IsInvalid) return IsNeedDownloadFromRemoteInternal(assetInfo);
{
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
else
return false;
} }
/// <summary> /// <summary>
@@ -385,17 +378,7 @@ namespace YooAsset
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo) public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
if (assetInfo.IsInvalid) return IsNeedDownloadFromRemoteInternal(assetInfo);
{
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
else
return false;
} }
/// <summary> /// <summary>
@@ -449,6 +432,28 @@ namespace YooAsset
string assetPath = _playModeServices.ActiveManifest.TryMappingToAssetPath(location); string assetPath = _playModeServices.ActiveManifest.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false; return string.IsNullOrEmpty(assetPath) == false;
} }
private bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo)
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
return false;
}
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
BundleInfo[] depends = _bundleServices.GetAllDependBundleInfos(assetInfo);
foreach (var depend in depends)
{
if (depend.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
return true;
}
return false;
}
#endregion #endregion
#region #region

View File

@@ -0,0 +1,11 @@

namespace YooAsset
{
public interface IBuildinQueryServices
{
/// <summary>
/// 查询应用程序里的内置资源是否存在
/// </summary>
bool QueryStreamingAssets(string packageName, string fileName);
}
}

View File

@@ -10,13 +10,8 @@ namespace YooAsset
public ulong DeliveryFileOffset; public ulong DeliveryFileOffset;
} }
public interface IQueryServices public interface IDeliveryQueryServices
{ {
/// <summary>
/// 查询应用程序里的内置资源是否存在
/// </summary>
bool QueryStreamingAssets(string packageName, string fileName);
/// <summary> /// <summary>
/// 查询是否为开发者分发的资源 /// 查询是否为开发者分发的资源
/// </summary> /// </summary>

View File

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

View File

@@ -10,6 +10,10 @@ namespace YooAsset
/// </summary> /// </summary>
public string ManifestFileName = "PackageManifest"; public string ManifestFileName = "PackageManifest";
/// <summary>
/// 默认的YooAsset文件夹名称
/// </summary>
public string DefaultYooFolderName = "yoo";
/// <summary> /// <summary>
/// 清单文件头标记 /// 清单文件头标记
@@ -37,11 +41,6 @@ namespace YooAsset
/// </summary> /// </summary>
public const string CacheBundleInfoFileName = "__info"; public const string CacheBundleInfoFileName = "__info";
/// <summary>
/// 默认的YooAsset文件夹名称
/// </summary>
public const string DefaultYooFolderName = "yoo";
/// <summary> /// <summary>
/// 缓存的资源文件的文件夹名称 /// 缓存的资源文件的文件夹名称
/// </summary> /// </summary>

View File

@@ -1,5 +1,6 @@
{ {
"name": "YooAsset", "name": "YooAsset",
"rootNamespace": "",
"references": [], "references": [],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],

View File

@@ -69,19 +69,20 @@ internal class FsmInitialize : IStateNode
string fallbackHostServer = GetHostServerURL(); string fallbackHostServer = GetHostServerURL();
var createParameters = new HostPlayModeParameters(); var createParameters = new HostPlayModeParameters();
createParameters.DecryptionServices = new GameDecryptionServices(); createParameters.DecryptionServices = new GameDecryptionServices();
createParameters.QueryServices = new GameQueryServices(); createParameters.BuildinQueryServices = new GameQueryServices();
createParameters.DeliveryQueryServices = new DefaultDeliveryQueryServices();
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
initializationOperation = package.InitializeAsync(createParameters); initializationOperation = package.InitializeAsync(createParameters);
} }
// WebGL运行模式 // WebGL运行模式
if(playMode == EPlayMode.WebPlayMode) if (playMode == EPlayMode.WebPlayMode)
{ {
string defaultHostServer = GetHostServerURL(); string defaultHostServer = GetHostServerURL();
string fallbackHostServer = GetHostServerURL(); string fallbackHostServer = GetHostServerURL();
var createParameters = new WebPlayModeParameters(); var createParameters = new WebPlayModeParameters();
createParameters.DecryptionServices = new GameDecryptionServices(); createParameters.DecryptionServices = new GameDecryptionServices();
createParameters.QueryServices = new GameQueryServices(); createParameters.BuildinQueryServices = new GameQueryServices();
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer); createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
initializationOperation = package.InitializeAsync(createParameters); initializationOperation = package.InitializeAsync(createParameters);
} }
@@ -178,4 +179,19 @@ internal class FsmInitialize : IStateNode
return 1024; return 1024;
} }
} }
/// <summary>
/// 默认的分发资源查询服务类
/// </summary>
private class DefaultDeliveryQueryServices : IDeliveryQueryServices
{
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{
throw new NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
}
}
} }

View File

@@ -6,18 +6,8 @@ using YooAsset;
/// <summary> /// <summary>
/// 资源文件查询服务类 /// 资源文件查询服务类
/// </summary> /// </summary>
public class GameQueryServices : IQueryServices public class GameQueryServices : IBuildinQueryServices
{ {
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{
throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
}
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)
{ {
// 注意fileName包含文件格式 // 注意fileName包含文件格式

View File

@@ -9,18 +9,8 @@ using YooAsset;
/// <summary> /// <summary>
/// 资源文件查询服务类 /// 资源文件查询服务类
/// </summary> /// </summary>
public class GameQueryServices2 : IQueryServices public class GameQueryServices2 : IBuildinQueryServices
{ {
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{
throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
}
public bool QueryStreamingAssets(string packageName, string fileName) public bool QueryStreamingAssets(string packageName, string fileName)
{ {
return StreamingAssetsHelper2.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}"); return StreamingAssetsHelper2.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");

View File

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