mirror of https://github.com/tuyoogame/YooAsset
Compare commits
35 Commits
2.3.2-prev
...
main
Author | SHA1 | Date |
---|---|---|
|
2c68e5dfd5 | |
|
1c6e54df21 | |
|
a4d378894e | |
|
9d5a90e8fa | |
|
bb1c64e444 | |
|
92ac301716 | |
|
135d5b4f5b | |
|
23931e5d58 | |
|
619b5dbdaf | |
|
3105521fa9 | |
|
b180fd8fc6 | |
|
769678a4b5 | |
|
f90530e9f4 | |
|
2630a7e793 | |
|
45b016ae0f | |
|
c8ab0a43dd | |
|
9457a804b4 | |
|
880d498618 | |
|
ca89113c67 | |
|
29d840b168 | |
|
41d1586109 | |
|
8d6a1d0066 | |
|
bdfaaa0973 | |
|
30854e4b93 | |
|
54d89d957a | |
|
ade97605f9 | |
|
bcb6443300 | |
|
11386a7ec2 | |
|
6fc45a758c | |
|
dcdf41b7c2 | |
|
1aaf569396 | |
|
101960f6d8 | |
|
49b188964c | |
|
5539d81c93 | |
|
ac3154e2ae |
|
@ -2,6 +2,82 @@
|
|||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.5.8] - 2024-8-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#175) 修复了Mac平台URL路径有空格的情况,会报Malformed URL错误。
|
||||
- (#177) 修复了加载一个地址的主资源或子资源之后无法再加载另一种的问题。
|
||||
- (#266) 修复了资源系统遍历IsBusy次数过多,导致过多的耗时的问题。
|
||||
- (#276) 修复了HostPlayMode模式下,如果内置清单是最新版本,每次运行都会触发拷贝行为。
|
||||
- (#295) 修复了在安卓平台,华为和三星真机上有极小概率加载资源包失败 : Unable to open archive file。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增资源导入器。
|
||||
- 新增获取缓存文件信息的方法。
|
||||
|
||||
### Changed
|
||||
|
||||
- 支持鸿蒙操作系统。
|
||||
- 支持资源下载器合并。
|
||||
|
||||
## [1.5.7] - 2023-10-07
|
||||
|
||||
### Changed
|
||||
|
||||
- WebGL平台支持创建下载器。
|
||||
|
||||
## [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同学)。
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public static string GetDefaultStreamingAssetsRoot()
|
||||
{
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettings.DefaultYooFolderName}/";
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,11 @@ namespace YooAsset.Editor
|
|||
/// 缓存服务器端口
|
||||
/// </summary>
|
||||
public int CacheServerPort;
|
||||
|
||||
/// <summary>
|
||||
/// 修复图集资源冗余问题
|
||||
/// </summary>
|
||||
public bool FixSpriteAtlasRedundancy = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -8,63 +8,61 @@ using System.Linq;
|
|||
|
||||
namespace UnityEditor.Build.Pipeline.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Ref https://zhuanlan.zhihu.com/p/586918159
|
||||
/// </summary>
|
||||
public class RemoveSpriteAtlasRedundancy : IBuildTask
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Version => 1;
|
||||
/// <summary>
|
||||
/// Ref https://zhuanlan.zhihu.com/p/586918159
|
||||
/// </summary>
|
||||
public class RemoveSpriteAtlasRedundancy : IBuildTask
|
||||
{
|
||||
public int Version => 1;
|
||||
|
||||
[InjectContext]
|
||||
IBundleWriteData writeDataParam;
|
||||
[InjectContext]
|
||||
IBundleWriteData writeDataParam;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReturnCode Run()
|
||||
{
|
||||
BundleWriteData writeData = (BundleWriteData)writeDataParam;
|
||||
public ReturnCode Run()
|
||||
{
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
BundleWriteData writeData = (BundleWriteData)writeDataParam;
|
||||
|
||||
// 所有图集散图的 guid 集合
|
||||
HashSet<GUID> spriteGuids = new HashSet<GUID>();
|
||||
// 图集引用的精灵图片集合
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历资源包里的资源记录其中图集的散图 guid
|
||||
foreach (var pair in writeData.FileToObjects)
|
||||
{
|
||||
foreach (ObjectIdentifier objectIdentifier in pair.Value)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
|
||||
Object asset = AssetDatabase.LoadAssetAtPath<Object>(path);
|
||||
if (asset is SpriteAtlas)
|
||||
{
|
||||
List<string> spritePaths = AssetDatabase.GetDependencies(path, false).ToList();
|
||||
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
|
||||
|
||||
// 将 writeData.FileToObjects 包含的图集散图的 texture 删掉避免冗余
|
||||
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)
|
||||
{
|
||||
// 删除图集散图的冗余 texture
|
||||
objectIdentifiers.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
return ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,10 +9,10 @@ namespace UnityEditor.Build.Pipeline.Tasks
|
|||
{
|
||||
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>();
|
||||
|
||||
|
||||
// Setup
|
||||
buildTasks.Add(new SwitchToBuildPlatform());
|
||||
buildTasks.Add(new RebuildSpriteAtlasCache());
|
||||
|
@ -33,20 +33,21 @@ namespace UnityEditor.Build.Pipeline.Tasks
|
|||
|
||||
// Packing
|
||||
buildTasks.Add(new GenerateBundlePacking());
|
||||
buildTasks.Add(new RemoveSpriteAtlasRedundancy()); // Fix for SpriteAtlas Redundancy
|
||||
if (fixSpriteAtlasRedundancy)
|
||||
buildTasks.Add(new RemoveSpriteAtlasRedundancy());
|
||||
buildTasks.Add(new UpdateBundleObjectLayout());
|
||||
buildTasks.Add(new GenerateBundleCommands());
|
||||
buildTasks.Add(new GenerateSubAssetPathMaps());
|
||||
buildTasks.Add(new GenerateBundleMaps());
|
||||
buildTasks.Add(new PostPackingCallback());
|
||||
|
||||
|
||||
// Writing
|
||||
buildTasks.Add(new WriteSerializedFiles());
|
||||
buildTasks.Add(new ArchiveAndCompressBundles());
|
||||
buildTasks.Add(new AppendBundleHash());
|
||||
buildTasks.Add(new GenerateLinkXml());
|
||||
buildTasks.Add(new PostWritingCallback());
|
||||
|
||||
|
||||
return buildTasks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace YooAsset.Editor
|
|||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
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);
|
||||
if (exitCode < 0)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
@ -130,7 +131,7 @@ namespace YooAsset.Editor
|
|||
{
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
|
@ -150,5 +151,32 @@ namespace YooAsset.Editor
|
|||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
protected string GetFilePathTempHash(string filePath)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(filePath);
|
||||
return HashUtility.BytesMD5(bytes);
|
||||
|
||||
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
|
||||
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
|
||||
}
|
||||
protected long GetBundleTempSize(BuildBundleInfo bundleInfo)
|
||||
{
|
||||
long tempSize = 0;
|
||||
|
||||
var assetPaths = bundleInfo.GetAllMainAssetPaths();
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
long size = FileUtility.GetFileSize(assetPath);
|
||||
tempSize += size;
|
||||
}
|
||||
|
||||
if (tempSize == 0)
|
||||
{
|
||||
string message = $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}";
|
||||
throw new Exception(message);
|
||||
}
|
||||
return tempSize;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -166,7 +166,7 @@ namespace YooAsset.Editor
|
|||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath))
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ namespace YooAsset.Editor
|
|||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(assetPath))
|
||||
if (IsValidateAsset(assetPath, isRawFilePackRule) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath, isRawFilePackRule);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
|
@ -204,6 +204,8 @@ namespace YooAsset.Editor
|
|||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
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}");
|
||||
|
@ -249,7 +251,7 @@ namespace YooAsset.Editor
|
|||
|
||||
// 忽略编辑器下的类型资源
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(LightingDataAsset))
|
||||
if (assetType == typeof(LightingDataAsset) || assetType == typeof(LightmapParameters))
|
||||
return false;
|
||||
|
||||
// 检测原生文件是否合规
|
||||
|
@ -292,11 +294,11 @@ namespace YooAsset.Editor
|
|||
|
||||
return true;
|
||||
}
|
||||
private bool IsCollectAsset(string assetPath)
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath)
|
||||
{
|
||||
// 根据规则设置过滤资源文件
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,10 @@ namespace YooAsset.Editor
|
|||
{
|
||||
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
|
||||
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
|
||||
|
||||
|
||||
// 当分组不是激活状态时,直接不进行检测
|
||||
if (ActiveRuleName == nameof(DisableGroup)) return;
|
||||
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
|
@ -103,6 +106,9 @@ namespace YooAsset.Editor
|
|||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
|
|
|
@ -83,6 +83,9 @@ namespace YooAsset.Editor
|
|||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
|
|
|
@ -94,7 +94,8 @@ namespace YooAsset.Editor
|
|||
typeof(AddressByFileName),
|
||||
typeof(AddressByFilePath),
|
||||
typeof(AddressByFolderAndFileName),
|
||||
typeof(AddressByGroupAndFileName)
|
||||
typeof(AddressByGroupAndFileName),
|
||||
typeof(AddressDisable)
|
||||
};
|
||||
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
|
||||
|
|
|
@ -333,6 +333,7 @@ namespace YooAsset.Editor
|
|||
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
|
||||
|
||||
// 警示框
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
_helpBoxContainer.Clear();
|
||||
if (_enableAddressableToogle.value && _locationToLowerToogle.value)
|
||||
{
|
||||
|
@ -348,6 +349,7 @@ namespace YooAsset.Editor
|
|||
_helpBoxContainer.style.display = DisplayStyle.Flex;
|
||||
else
|
||||
_helpBoxContainer.style.display = DisplayStyle.None;
|
||||
#endif
|
||||
|
||||
// 设置栏
|
||||
if (_showSettings)
|
||||
|
|
|
@ -4,10 +4,16 @@ namespace YooAsset.Editor
|
|||
public struct FilterRuleData
|
||||
{
|
||||
public string AssetPath;
|
||||
|
||||
public FilterRuleData(string assetPath)
|
||||
public string CollectPath;
|
||||
public string GroupName;
|
||||
public string UserData;
|
||||
|
||||
public FilterRuleData(string assetPath, string collectPath, string groupName, string userData)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
CollectPath = collectPath;
|
||||
GroupName = groupName;
|
||||
UserData = userData;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,6 @@ namespace YooAsset.Editor
|
|||
public string GroupName;
|
||||
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)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
|
@ -41,7 +34,7 @@ namespace YooAsset.Editor
|
|||
public string GetMainBundleName(string packageName, bool uniqueBundleName)
|
||||
{
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
|
@ -59,7 +52,7 @@ namespace YooAsset.Editor
|
|||
return string.Empty;
|
||||
|
||||
string fullName;
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
|
||||
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').Replace(" ", "_").ToLower();
|
||||
if (uniqueBundleName)
|
||||
fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
|
||||
else
|
||||
|
|
|
@ -2,6 +2,15 @@
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[DisplayName("定位地址: 禁用")]
|
||||
public class AddressDisable : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("定位地址: 文件名")]
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
|
|
|
@ -72,9 +72,14 @@ namespace YooAsset
|
|||
_isUnloadSafe = false;
|
||||
for (int i = 0; i < _providerList.Count; i++)
|
||||
{
|
||||
var provider = _providerList[i];
|
||||
if (provider.IsDone)
|
||||
continue;
|
||||
|
||||
provider.Update();
|
||||
|
||||
if (IsBusy)
|
||||
break;
|
||||
_providerList[i].Update();
|
||||
}
|
||||
_isUnloadSafe = true;
|
||||
}
|
||||
|
@ -199,7 +204,7 @@ namespace YooAsset
|
|||
return completedProvider.CreateHandle<AssetOperationHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = assetInfo.GUID;
|
||||
string providerGUID = nameof(LoadAssetAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
|
@ -227,7 +232,7 @@ namespace YooAsset
|
|||
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = assetInfo.GUID;
|
||||
string providerGUID = nameof(LoadSubAssetsAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
|
@ -255,7 +260,7 @@ namespace YooAsset
|
|||
return completedProvider.CreateHandle<AllAssetsOperationHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = assetInfo.GUID;
|
||||
string providerGUID = nameof(LoadAllAssetsAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
|
@ -283,7 +288,7 @@ namespace YooAsset
|
|||
return completedProvider.CreateHandle<RawFileOperationHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = assetInfo.GUID;
|
||||
string providerGUID = nameof(LoadRawFileAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
|
|
|
@ -270,22 +270,47 @@ namespace YooAsset
|
|||
// Check error
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
var result = CacheSystem.VerifyingRecordFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
|
||||
if (result != EVerifyResult.Succeed)
|
||||
if (result == EVerifyResult.Succeed)
|
||||
{
|
||||
YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}");
|
||||
// 说明:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
// 大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||
byte[] fileData = FileUtility.ReadAllBytes(FileLoadPath);
|
||||
if (fileData != null && fileData.Length > 0)
|
||||
CacheBundle = AssetBundle.LoadFromMemory(fileData);
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle from memory : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}";
|
||||
YooLogger.Error(LastError);
|
||||
CacheSystem.DiscardFile(MainBundleInfo.Bundle.PackageName, MainBundleInfo.Bundle.CacheGUID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -95,9 +95,6 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
|
||||
// 注意:释放下载句柄
|
||||
_downloader.DisposeHandler();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,15 @@ namespace YooAsset
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取记录对象
|
||||
/// </summary>
|
||||
public static PackageCache.RecordWrapper TryGetWrapper(string packageName, string cacheGUID)
|
||||
{
|
||||
var cache = GetOrCreateCache(packageName);
|
||||
return cache.TryGetWrapper(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证缓存文件(子线程内操作)
|
||||
/// </summary>
|
||||
|
@ -165,9 +174,9 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 获取所有的缓存文件
|
||||
/// </summary>
|
||||
public static List<string> GetAllCacheGUIDs(ResourcePackage package)
|
||||
public static List<string> GetAllCacheGUIDs(string packageName)
|
||||
{
|
||||
var cache = GetOrCreateCache(package.PackageName);
|
||||
var cache = GetOrCreateCache(packageName);
|
||||
return cache.GetAllKeys();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace YooAsset
|
|||
|
||||
if (_steps == ESteps.GetAllCacheFiles)
|
||||
{
|
||||
_allCacheGUIDs = CacheSystem.GetAllCacheGUIDs(_package);
|
||||
_allCacheGUIDs = CacheSystem.GetAllCacheGUIDs(_package.PackageName);
|
||||
_fileTotalCount = _allCacheGUIDs.Count;
|
||||
YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
|
||||
_steps = ESteps.ClearAllCacheFiles;
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class GetAllCacheFileInfosOperation : AsyncOperationBase
|
||||
{
|
||||
public class CacheInfo
|
||||
{
|
||||
public string FishHash { private set; get; }
|
||||
public string FilePath { private set; get; }
|
||||
public string FileCRC { private set; get; }
|
||||
public long FileSize { private set; get; }
|
||||
|
||||
public CacheInfo(string fishHash, string filePath, string fileCRC, long fileSize)
|
||||
{
|
||||
FishHash = fishHash;
|
||||
FilePath = filePath;
|
||||
FileCRC = fileCRC;
|
||||
FileSize = fileSize;
|
||||
}
|
||||
}
|
||||
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetCacheFileInfos,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private List<CacheInfo> _cacheFileInfos;
|
||||
|
||||
/// <summary>
|
||||
/// 搜索结果
|
||||
/// </summary>
|
||||
public List<CacheInfo> Result
|
||||
{
|
||||
get { return _cacheFileInfos; }
|
||||
}
|
||||
|
||||
internal GetAllCacheFileInfosOperation(string packageName)
|
||||
{
|
||||
_packageName = packageName;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.GetCacheFileInfos;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetCacheFileInfos)
|
||||
{
|
||||
var allCachedGUIDs = CacheSystem.GetAllCacheGUIDs(_packageName);
|
||||
_cacheFileInfos = new List<CacheInfo>(allCachedGUIDs.Count);
|
||||
for (int i = 0; i < allCachedGUIDs.Count; i++)
|
||||
{
|
||||
var cachedGUID = allCachedGUIDs[i];
|
||||
var wrapper = CacheSystem.TryGetWrapper(_packageName, cachedGUID);
|
||||
if (wrapper != null)
|
||||
{
|
||||
string directoryName = Path.GetDirectoryName(wrapper.DataFilePath);
|
||||
var directoryInfo = new DirectoryInfo(directoryName);
|
||||
if (directoryInfo.Exists)
|
||||
{
|
||||
string fishHash = directoryInfo.Name;
|
||||
var cacheFileInfo = new CacheInfo(fishHash, wrapper.DataFilePath, wrapper.DataFileCRC, wrapper.DataFileSize);
|
||||
_cacheFileInfos.Add(cacheFileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 注意:总是返回成功
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d37e37f5d78ddf8468adcf2dff1edfbb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -46,7 +46,12 @@ namespace YooAsset
|
|||
}
|
||||
private static string CreateDefaultBuildinRoot()
|
||||
{
|
||||
return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettings.DefaultYooFolderName);
|
||||
string path = PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#if UNITY_OPENHARMONY
|
||||
return $"file://{path}";
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
private static string CreateDefaultSandboxRoot()
|
||||
{
|
||||
|
@ -54,11 +59,11 @@ namespace YooAsset
|
|||
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
|
||||
string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
|
||||
projectPath = PathUtility.RegularPath(projectPath);
|
||||
return PathUtility.Combine(projectPath, YooAssetSettings.DefaultYooFolderName);
|
||||
return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#elif UNITY_STANDALONE
|
||||
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettings.DefaultYooFolderName);
|
||||
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#else
|
||||
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettings.DefaultYooFolderName);
|
||||
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -128,6 +133,7 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public void SaveSandboxPackageVersionFile(string version)
|
||||
{
|
||||
YooLogger.Log($"Save package version : {version}");
|
||||
string filePath = GetSandboxPackageVersionFilePath();
|
||||
FileUtility.WriteAllText(filePath, version);
|
||||
}
|
||||
|
|
|
@ -37,14 +37,23 @@ namespace YooAsset
|
|||
{
|
||||
#if UNITY_EDITOR
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_IPHONE
|
||||
return StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_ANDROID
|
||||
return path;
|
||||
#elif UNITY_STANDALONE
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_WEBGL
|
||||
return path;
|
||||
#elif UNITY_IPHONE
|
||||
return StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_ANDROID
|
||||
if (path.StartsWith("jar:file://"))
|
||||
return path;
|
||||
else
|
||||
return StringUtility.Format("jar:file://{0}", path);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
return new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE
|
||||
return StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_OPENHARMONY
|
||||
return path;
|
||||
#else
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,13 @@ namespace YooAsset
|
|||
|
||||
public void DeleteFiles()
|
||||
{
|
||||
if (File.Exists(DataFilePath))
|
||||
try
|
||||
{
|
||||
File.Delete(DataFilePath);
|
||||
Directory.Delete(FileRootPath, true);
|
||||
}
|
||||
|
||||
if (File.Exists(InfoFilePath))
|
||||
catch (System.Exception e)
|
||||
{
|
||||
File.Delete(InfoFilePath);
|
||||
YooLogger.Warning($"Failed delete cache bundle folder : {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private bool _keepDownloadHandleLife = false;
|
||||
private DownloadHandlerAssetBundle _downloadhandler;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
private bool _getAssetBundle = false;
|
||||
private AssetBundle _cacheAssetBundle;
|
||||
|
||||
public WebDownloader(BundleInfo bundleInfo, int failedTryAgain, int timeout) : base(bundleInfo, failedTryAgain, timeout)
|
||||
{
|
||||
|
@ -34,7 +34,10 @@ namespace YooAsset
|
|||
{
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_keepDownloadHandleLife = (bool)param[0];
|
||||
if (param.Length > 0)
|
||||
{
|
||||
_getAssetBundle = (bool)param[0];
|
||||
}
|
||||
_steps = ESteps.PrepareDownload;
|
||||
}
|
||||
}
|
||||
|
@ -135,11 +138,18 @@ namespace YooAsset
|
|||
_lastCode = 0;
|
||||
}
|
||||
|
||||
// 最终释放请求
|
||||
DisposeRequest();
|
||||
if (_getAssetBundle)
|
||||
{
|
||||
_cacheAssetBundle = _downloadhandler.assetBundle;
|
||||
if (_cacheAssetBundle == null)
|
||||
{
|
||||
_lastError = "assetBundle is null";
|
||||
_steps = ESteps.TryAgain;
|
||||
}
|
||||
}
|
||||
|
||||
if (_keepDownloadHandleLife == false)
|
||||
DisposeHandler();
|
||||
// 最终释放请求
|
||||
DisposeRequest();
|
||||
}
|
||||
|
||||
// 重新尝试下载
|
||||
|
@ -148,7 +158,6 @@ namespace YooAsset
|
|||
if (_failedTryAgain <= 0)
|
||||
{
|
||||
DisposeRequest();
|
||||
DisposeHandler();
|
||||
ReportError();
|
||||
_status = EStatus.Failed;
|
||||
_steps = ESteps.Done;
|
||||
|
@ -175,7 +184,6 @@ namespace YooAsset
|
|||
_lastCode = 0;
|
||||
|
||||
DisposeRequest();
|
||||
DisposeHandler();
|
||||
}
|
||||
}
|
||||
private void DisposeRequest()
|
||||
|
@ -185,6 +193,11 @@ namespace YooAsset
|
|||
_webRequest.Dispose();
|
||||
_webRequest = null;
|
||||
}
|
||||
if (_downloadhandler != null)
|
||||
{
|
||||
_downloadhandler.Dispose();
|
||||
_downloadhandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -192,22 +205,7 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public AssetBundle GetAssetBundle()
|
||||
{
|
||||
if (_downloadhandler != null)
|
||||
return _downloadhandler.assetBundle;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放下载句柄
|
||||
/// </summary>
|
||||
public void DisposeHandler()
|
||||
{
|
||||
if (_downloadhandler != null)
|
||||
{
|
||||
_downloadhandler.Dispose();
|
||||
_downloadhandler = null;
|
||||
}
|
||||
return _cacheAssetBundle;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca9b2c6456d21bb4e9eecd9dc820a641
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -77,7 +77,7 @@ namespace YooAsset
|
|||
internal void SetFinish()
|
||||
{
|
||||
Progress = 1f;
|
||||
_callback?.Invoke(this);
|
||||
_callback?.Invoke(this); //注意:如果完成回调内发生异常,会导致Task无限期等待
|
||||
if (_taskCompletionSource != null)
|
||||
_taskCompletionSource.TrySetResult(null);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ namespace YooAsset
|
|||
internal class OperationSystem
|
||||
{
|
||||
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> _removeList = new List<AsyncOperationBase>(100);
|
||||
private static readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100);
|
||||
|
||||
// 计时器相关
|
||||
private static Stopwatch _watch;
|
||||
|
@ -47,39 +46,26 @@ namespace YooAsset
|
|||
_frameTime = _watch.ElapsedMilliseconds;
|
||||
|
||||
// 添加新的异步操作
|
||||
if (_addList.Count > 0)
|
||||
if (_newList.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < _addList.Count; i++)
|
||||
{
|
||||
var operation = _addList[i];
|
||||
_operations.Add(operation);
|
||||
}
|
||||
_addList.Clear();
|
||||
_operations.AddRange(_newList);
|
||||
_newList.Clear();
|
||||
}
|
||||
|
||||
// 更新所有的异步操作
|
||||
foreach (var operation in _operations)
|
||||
for (int i = _operations.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (IsBusy)
|
||||
break;
|
||||
|
||||
var operation = _operations[i];
|
||||
operation.Update();
|
||||
if (operation.IsDone)
|
||||
{
|
||||
_removeList.Add(operation);
|
||||
operation.SetFinish();
|
||||
_operations.RemoveAt(i);
|
||||
operation.SetFinish(); //注意:如果业务端发生异常,保证异步操作提前移除。
|
||||
}
|
||||
}
|
||||
|
||||
// 移除已经完成的异步操作
|
||||
if (_removeList.Count > 0)
|
||||
{
|
||||
foreach (var operation in _removeList)
|
||||
{
|
||||
_operations.Remove(operation);
|
||||
}
|
||||
_removeList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -88,8 +74,7 @@ namespace YooAsset
|
|||
public static void DestroyAll()
|
||||
{
|
||||
_operations.Clear();
|
||||
_addList.Clear();
|
||||
_removeList.Clear();
|
||||
_newList.Clear();
|
||||
_watch = null;
|
||||
_frameTime = 0;
|
||||
MaxTimeSlice = long.MaxValue;
|
||||
|
@ -100,7 +85,7 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public static void StartOperation(AsyncOperationBase operation)
|
||||
{
|
||||
_addList.Add(operation);
|
||||
_newList.Add(operation);
|
||||
operation.SetStart();
|
||||
operation.Start();
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace YooAsset
|
|||
return _providerGUID;
|
||||
|
||||
if (AssetType == null)
|
||||
_providerGUID = $"{AssetPath}[null]";
|
||||
_providerGUID = $"[{AssetPath}][null]";
|
||||
else
|
||||
_providerGUID = $"{AssetPath}[{AssetType.Name}]";
|
||||
_providerGUID = $"[{AssetPath}][{AssetType.Name}]";
|
||||
return _providerGUID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,10 +154,12 @@ namespace YooAsset
|
|||
|
||||
// 填充BundleDic
|
||||
manifest.BundleDic = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
packageBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle);
|
||||
manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
}
|
||||
|
||||
// 填充AssetDic
|
||||
|
@ -210,7 +212,18 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量转换为解压BundleInfo
|
||||
/// 转换为导入BundleInfo
|
||||
/// </summary>
|
||||
public static BundleInfo ConvertToImportInfo(PackageBundle packageBundle, string filePath)
|
||||
{
|
||||
// 注意:我们把本地文件路径指定为远端下载地址
|
||||
string persistentPath = PersistentTools.ConvertToWWWPath(filePath);
|
||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.None, persistentPath, persistentPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量转换解压为BundleInfo
|
||||
/// </summary>
|
||||
public static List<BundleInfo> ConvertToUnpackInfos(List<PackageBundle> unpackList)
|
||||
{
|
||||
|
|
|
@ -91,14 +91,7 @@ namespace YooAsset
|
|||
_failedTryAgain = failedTryAgain;
|
||||
_timeout = timeout;
|
||||
|
||||
if (downloadList != null)
|
||||
{
|
||||
TotalDownloadCount = downloadList.Count;
|
||||
foreach (var packageBundle in downloadList)
|
||||
{
|
||||
TotalDownloadBytes += packageBundle.Bundle.FileSize;
|
||||
}
|
||||
}
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
|
@ -206,6 +199,57 @@ namespace YooAsset
|
|||
}
|
||||
}
|
||||
}
|
||||
private void CalculatDownloaderInfo()
|
||||
{
|
||||
if (_downloadList != null)
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = _downloadList.Count;
|
||||
foreach (var packageBundle in _downloadList)
|
||||
{
|
||||
TotalDownloadBytes += packageBundle.Bundle.FileSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并其它下载器
|
||||
/// </summary>
|
||||
/// <param name="downloader">合并的下载器</param>
|
||||
public void Combine(DownloaderOperation downloader)
|
||||
{
|
||||
if (_steps != ESteps.None)
|
||||
{
|
||||
YooLogger.Error("The downloader is running, can not combine with other downloader !");
|
||||
return;
|
||||
}
|
||||
|
||||
HashSet<string> temper = new HashSet<string>();
|
||||
foreach (var bundleInfo in _downloadList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.Bundle.CachedDataFilePath) == false)
|
||||
{
|
||||
temper.Add(bundleInfo.Bundle.CachedDataFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并下载列表
|
||||
foreach (var bundleInfo in downloader._downloadList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.Bundle.CachedDataFilePath) == false)
|
||||
{
|
||||
_downloadList.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新统计下载信息
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载
|
||||
|
@ -282,4 +326,21 @@ namespace YooAsset
|
|||
return operation;
|
||||
}
|
||||
}
|
||||
public sealed class ResourceImporterOperation : DownloaderOperation
|
||||
{
|
||||
internal ResourceImporterOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建空的导入器
|
||||
/// </summary>
|
||||
internal static ResourceImporterOperation CreateEmptyImporter(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||
var operation = new ResourceImporterOperation(downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,11 @@ namespace YooAsset
|
|||
public abstract class InitializationOperation : AsyncOperationBase
|
||||
{
|
||||
public string PackageVersion { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地记录的资源包裹的版本
|
||||
/// </summary>
|
||||
public string RecordVersion { protected set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -242,6 +247,7 @@ namespace YooAsset
|
|||
|
||||
if (_queryCachePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
RecordVersion = _queryCachePackageVersionOp.PackageVersion;
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
}
|
||||
else
|
||||
|
@ -336,6 +342,7 @@ namespace YooAsset
|
|||
{
|
||||
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
|
||||
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
|
||||
_impl.FlushManifestVersionFile();
|
||||
_steps = ESteps.PackageCaching;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -142,9 +142,9 @@ namespace YooAsset
|
|||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
// 添加无后缀名路径的映射
|
||||
if (Path.HasExtension(location))
|
||||
string locationWithoutExtension = Path.ChangeExtension(location, null);
|
||||
if (!ReferenceEquals(location, locationWithoutExtension))
|
||||
{
|
||||
string locationWithoutExtension = PathUtility.RemoveExtension(location);
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
|
@ -154,10 +154,13 @@ namespace YooAsset
|
|||
if (Manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
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
|
||||
|
@ -186,6 +189,8 @@ namespace YooAsset
|
|||
_packageBundleCount = _buffer.ReadInt32();
|
||||
Manifest.BundleList = new List<PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic2 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic3 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
|
@ -207,10 +212,11 @@ namespace YooAsset
|
|||
|
||||
packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
|
||||
Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
|
||||
Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
|
||||
// 注意:原始文件可能存在相同的CacheGUID
|
||||
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
|
||||
Manifest.CacheGUIDs.Add(packageBundle.CacheGUID);
|
||||
if (Manifest.BundleDic3.ContainsKey(packageBundle.CacheGUID) == false)
|
||||
Manifest.BundleDic3.Add(packageBundle.CacheGUID, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
|
|
|
@ -10,8 +10,7 @@ namespace YooAsset
|
|||
DownloadManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private static int RequestCount = 0;
|
||||
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
|
@ -19,6 +18,7 @@ namespace YooAsset
|
|||
private UnityWebFileRequester _downloader1;
|
||||
private UnityWebFileRequester _downloader2;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace YooAsset
|
|||
}
|
||||
internal override void Start()
|
||||
{
|
||||
RequestCount++;
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(DownloadManifestOperation));
|
||||
_steps = ESteps.DownloadPackageHashFile;
|
||||
}
|
||||
internal override void Update()
|
||||
|
@ -58,6 +58,7 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader1.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(DownloadManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -88,6 +89,7 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader2.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(DownloadManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -102,10 +104,10 @@ namespace YooAsset
|
|||
private string GetDownloadRequestURL(string fileName)
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
if (RequestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
else
|
||||
if (_requestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private static int RequestCount = 0;
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
|
@ -23,6 +22,7 @@ namespace YooAsset
|
|||
private DeserializeManifestOperation _deserializer;
|
||||
private byte[] _fileData;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 加载的清单实例
|
||||
|
@ -39,7 +39,7 @@ namespace YooAsset
|
|||
}
|
||||
internal override void Start()
|
||||
{
|
||||
RequestCount++;
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(LoadRemoteManifestOperation));
|
||||
_steps = ESteps.DownloadPackageHashFile;
|
||||
}
|
||||
internal override void Update()
|
||||
|
@ -90,6 +90,7 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(LoadRemoteManifestOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -141,10 +142,10 @@ namespace YooAsset
|
|||
private string GetDownloadRequestURL(string fileName)
|
||||
{
|
||||
// 轮流返回请求地址
|
||||
if (RequestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
else
|
||||
if (_requestCount % 2 == 0)
|
||||
return _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
return _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private static int RequestCount = 0;
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹哈希值
|
||||
|
@ -33,7 +33,7 @@ namespace YooAsset
|
|||
}
|
||||
internal override void Start()
|
||||
{
|
||||
RequestCount++;
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageHashOperation));
|
||||
_steps = ESteps.DownloadPackageHash;
|
||||
}
|
||||
internal override void Update()
|
||||
|
@ -62,6 +62,7 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageHashOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -88,10 +89,10 @@ namespace YooAsset
|
|||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (RequestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
else
|
||||
if (_requestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ namespace YooAsset
|
|||
Done,
|
||||
}
|
||||
|
||||
private static int RequestCount = 0;
|
||||
private readonly IRemoteServices _remoteServices;
|
||||
private readonly string _packageName;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private UnityWebDataRequester _downloader;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _requestCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
|
@ -33,7 +33,7 @@ namespace YooAsset
|
|||
}
|
||||
internal override void Start()
|
||||
{
|
||||
RequestCount++;
|
||||
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageVersionOperation));
|
||||
_steps = ESteps.DownloadPackageVersion;
|
||||
}
|
||||
internal override void Update()
|
||||
|
@ -62,6 +62,7 @@ namespace YooAsset
|
|||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloader.GetError();
|
||||
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageVersionOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -88,10 +89,10 @@ namespace YooAsset
|
|||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (RequestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
else
|
||||
if (_requestCount % 2 == 0)
|
||||
url = _remoteServices.GetRemoteMainURL(fileName);
|
||||
else
|
||||
url = _remoteServices.GetRemoteFallbackURL(fileName);
|
||||
|
||||
// 在URL末尾添加时间戳
|
||||
if (_appendTimeTicks)
|
||||
|
|
|
@ -64,6 +64,18 @@ namespace YooAsset
|
|||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供FileName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供CacheGUID获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
/// <summary>
|
||||
/// 资源映射集合(提供AssetPath获取PackageAsset)
|
||||
/// </summary>
|
||||
|
@ -82,12 +94,6 @@ namespace YooAsset
|
|||
[NonSerialized]
|
||||
public Dictionary<string, string> AssetPathMapping2;
|
||||
|
||||
/// <summary>
|
||||
/// 该资源清单所有文件的缓存GUID集合
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public HashSet<string> CacheGUIDs = new HashSet<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 尝试映射为资源路径
|
||||
|
@ -192,12 +198,28 @@ namespace YooAsset
|
|||
return BundleDic.TryGetValue(bundleName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByFileName(string fileName, out PackageBundle result)
|
||||
{
|
||||
return BundleDic2.TryGetValue(fileName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByCacheGUID(string cacheGUID, out PackageBundle result)
|
||||
{
|
||||
return BundleDic3.TryGetValue(cacheGUID, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
return CacheGUIDs.Contains(cacheGUID);
|
||||
return BundleDic3.ContainsKey(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -74,6 +74,11 @@ namespace YooAsset
|
|||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
|
|
@ -284,6 +284,39 @@ namespace YooAsset
|
|||
|
||||
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = ManifestTools.ConvertToImportInfo(packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
|
|
@ -117,6 +117,35 @@ namespace YooAsset
|
|||
|
||||
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = ManifestTools.ConvertToImportInfo(packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
|
|
@ -33,6 +33,16 @@ namespace YooAsset
|
|||
}
|
||||
|
||||
// 下载相关
|
||||
private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
|
||||
foreach (var packageBundle in downloadList)
|
||||
{
|
||||
var bundleInfo = ConvertToDownloadInfo(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||
{
|
||||
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||
|
@ -84,15 +94,101 @@ namespace YooAsset
|
|||
|
||||
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
|
||||
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
|
||||
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 如果未带任何标记,则统一下载
|
||||
if (packageBundle.HasAnyTags() == false)
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 查询DLC资源
|
||||
if (packageBundle.HasTag(tags))
|
||||
{
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
||||
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
|
||||
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos)
|
||||
{
|
||||
// 获取资源对象的资源包和所有依赖资源包
|
||||
List<PackageBundle> checkList = new List<PackageBundle>();
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
|
||||
if (checkList.Contains(mainBundle) == false)
|
||||
checkList.Add(mainBundle);
|
||||
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
|
||||
foreach (var dependBundle in dependBundles)
|
||||
{
|
||||
if (checkList.Contains(dependBundle) == false)
|
||||
checkList.Add(dependBundle);
|
||||
}
|
||||
}
|
||||
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
downloadList.Add(packageBundle);
|
||||
}
|
||||
|
||||
return ConvertToDownloadList(downloadList);
|
||||
}
|
||||
|
||||
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
|
@ -103,6 +199,11 @@ namespace YooAsset
|
|||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
|
|
@ -299,6 +299,17 @@ namespace YooAsset
|
|||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定版本的缓存信息
|
||||
/// </summary>
|
||||
public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new GetAllCacheFileInfosOperation(PackageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地包裹的版本信息
|
||||
/// </summary>
|
||||
|
@ -335,7 +346,7 @@ namespace YooAsset
|
|||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.BuildinRoot;
|
||||
return persistent.BuildinPackageRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -345,7 +356,17 @@ namespace YooAsset
|
|||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.SandboxRoot;
|
||||
return persistent.SandboxPackageRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的沙盒文件AB文件的缓存目录
|
||||
/// </summary>
|
||||
public string GetPackageSandboxCacheBundleRootDirectory()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.SandboxCacheBundleFilesRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -368,17 +389,7 @@ namespace YooAsset
|
|||
{
|
||||
DebugCheckInitialize();
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
|
||||
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return IsNeedDownloadFromRemoteInternal(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -388,17 +399,7 @@ namespace YooAsset
|
|||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Warning(assetInfo.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
|
||||
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return IsNeedDownloadFromRemoteInternal(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -452,6 +453,28 @@ namespace YooAsset
|
|||
string assetPath = _playModeServices.ActiveManifest.TryMappingToAssetPath(location);
|
||||
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
|
||||
|
||||
#region 原生文件
|
||||
|
@ -1024,6 +1047,21 @@ namespace YooAsset
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region 资源导入
|
||||
/// <summary>
|
||||
/// 创建资源导入器
|
||||
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
|
||||
/// </summary>
|
||||
/// <param name="filePaths">资源路径列表</param>
|
||||
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
|
||||
/// <param name="failedTryAgain">导入失败的重试次数</param>
|
||||
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeServices.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain, int.MaxValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
|
|
|
@ -36,5 +36,8 @@ namespace YooAsset
|
|||
// 解压相关
|
||||
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
|
||||
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout);
|
||||
|
||||
// 导入相关
|
||||
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,10 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string ManifestFileName = "PackageManifest";
|
||||
|
||||
/// <summary>
|
||||
/// 默认的YooAsset文件夹名称
|
||||
/// </summary>
|
||||
public string DefaultYooFolderName = "yoo";
|
||||
|
||||
/// <summary>
|
||||
/// 清单文件头标记
|
||||
|
@ -37,11 +41,6 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public const string CacheBundleInfoFileName = "__info";
|
||||
|
||||
/// <summary>
|
||||
/// 默认的YooAsset文件夹名称
|
||||
/// </summary>
|
||||
public const string DefaultYooFolderName = "yoo";
|
||||
|
||||
/// <summary>
|
||||
/// 缓存的资源文件的文件夹名称
|
||||
/// </summary>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.5.4-preview",
|
||||
"version": "1.5.8",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
|
Loading…
Reference in New Issue