Compare commits

...

14 Commits

Author SHA1 Message Date
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
28 changed files with 274 additions and 164 deletions

View File

@@ -2,6 +2,50 @@
All notable changes to this package will be documented in this file.
## [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同学

View File

@@ -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}/";
}
}
}

View File

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

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}

View File

@@ -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)
{

View File

@@ -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}");
@@ -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)
{

View File

@@ -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

View File

@@ -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

View File

@@ -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));

View File

@@ -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)

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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
{

View File

@@ -46,7 +46,7 @@ namespace YooAsset
}
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()
{
@@ -54,11 +54,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
}

View File

@@ -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}");
}
}
}

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

@@ -77,9 +77,9 @@ namespace YooAsset
internal void SetFinish()
{
Progress = 1f;
_callback?.Invoke(this);
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
_callback?.Invoke(this);
}
internal void SetStart()
{

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -368,17 +368,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 +378,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 +432,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

View File

@@ -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>

View File

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