Compare commits
14 Commits
2.3.10
...
1.5.5-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d6a1d0066 | ||
|
|
bdfaaa0973 | ||
|
|
30854e4b93 | ||
|
|
54d89d957a | ||
|
|
ade97605f9 | ||
|
|
bcb6443300 | ||
|
|
11386a7ec2 | ||
|
|
6fc45a758c | ||
|
|
dcdf41b7c2 | ||
|
|
1aaf569396 | ||
|
|
101960f6d8 | ||
|
|
49b188964c | ||
|
|
5539d81c93 | ||
|
|
ac3154e2ae |
@@ -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同学)。
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs
Normal file
36
Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs.meta
Normal file
11
Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca9b2c6456d21bb4e9eecd9dc820a641
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 原生文件
|
||||
|
||||
@@ -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.5-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user