更新YooAsset 2.3.3 -> 2.3.7 优化YooAsset.RuntimeExtension以及YooAsset.EditorExtension目录结构

更新YooAsset 2.3.3 -> 2.3.7 优化YooAsset.RuntimeExtension以及YooAsset.EditorExtension目录结构
This commit is contained in:
Alex-Rachel
2025-04-17 12:59:23 +08:00
parent 32418326b1
commit 227283864f
206 changed files with 1641 additions and 461 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
namespace YooAsset
{
internal static class HandleFactory
{
private static readonly Dictionary<Type, Func<ProviderOperation, HandleBase>> _handleFactory = new Dictionary<Type, Func<ProviderOperation, HandleBase>>()
{
{ typeof(AssetHandle), op => new AssetHandle(op) },
{ typeof(SceneHandle), op => new SceneHandle(op) },
{ typeof(SubAssetsHandle), op => new SubAssetsHandle(op) },
{ typeof(AllAssetsHandle), op => new AllAssetsHandle(op) },
{ typeof(RawFileHandle), op => new RawFileHandle(op) }
};
public static HandleBase CreateHandle(ProviderOperation operation, Type type)
{
if (_handleFactory.TryGetValue(type, out var factory) == false)
{
throw new NotImplementedException($"Handle type {type.FullName} is not supported.");
}
return factory(operation);
}
}
}

View File

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

View File

@@ -9,7 +9,8 @@ namespace YooAsset
private enum ESteps
{
None,
LoadFile,
CheckConcurrency,
LoadBundleFile,
Done,
}
@@ -57,17 +58,32 @@ namespace YooAsset
}
internal override void InternalStart()
{
_steps = ESteps.LoadFile;
_steps = ESteps.CheckConcurrency;
}
internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadFile)
if (_steps == ESteps.CheckConcurrency)
{
if (IsWaitForAsyncComplete)
{
_steps = ESteps.LoadBundleFile;
}
else
{
if (_resourceManager.BundleLoadingIsBusy())
return;
_steps = ESteps.LoadBundleFile;
}
}
if (_steps == ESteps.LoadBundleFile)
{
if (_loadBundleOp == null)
{
_resourceManager.BundleLoadingCounter++;
_loadBundleOp = LoadBundleInfo.LoadBundleFile();
_loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp);
@@ -103,6 +119,9 @@ namespace YooAsset
Status = EOperationStatus.Failed;
Error = _loadBundleOp.Error;
}
// 统计计数减少
_resourceManager.BundleLoadingCounter--;
}
}
internal override void InternalWaitForAsyncComplete()

View File

@@ -15,6 +15,7 @@ namespace YooAsset
private readonly ResourceManager _resManager;
private readonly int _loopCount;
private int _loopCounter = 0;
private ESteps _steps = ESteps.None;
internal UnloadUnusedAssetsOperation(ResourceManager resourceManager, int loopCount)
@@ -25,6 +26,7 @@ namespace YooAsset
internal override void InternalStart()
{
_steps = ESteps.UnloadUnused;
_loopCounter = _loopCount;
}
internal override void InternalUpdate()
{
@@ -33,13 +35,23 @@ namespace YooAsset
if (_steps == ESteps.UnloadUnused)
{
for (int i = 0; i < _loopCount; i++)
while (_loopCounter > 0)
{
_loopCounter--;
LoopUnloadUnused();
if (IsWaitForAsyncComplete == false)
{
if (OperationSystem.IsBusy)
break;
}
}
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
if (_loopCounter <= 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
internal override void InternalWaitForAsyncComplete()

View File

@@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System;
using System.Linq;
namespace YooAsset
{
@@ -69,8 +69,8 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
private readonly LoadBundleFileOperation _mainBundleLoader;
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>();
private readonly List<HandleBase> _handles = new List<HandleBase>();
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>(10);
private readonly HashSet<HandleBase> _handles = new HashSet<HandleBase>();
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
@@ -220,20 +220,7 @@ namespace YooAsset
// 引用计数增加
RefCount++;
HandleBase handle;
if (typeof(T) == typeof(AssetHandle))
handle = new AssetHandle(this);
else if (typeof(T) == typeof(SceneHandle))
handle = new SceneHandle(this);
else if (typeof(T) == typeof(SubAssetsHandle))
handle = new SubAssetsHandle(this);
else if (typeof(T) == typeof(AllAssetsHandle))
handle = new AllAssetsHandle(this);
else if (typeof(T) == typeof(RawFileHandle))
handle = new RawFileHandle(this);
else
throw new System.NotImplementedException();
HandleBase handle = HandleFactory.CreateHandle(this, typeof(T));
_handles.Add(handle);
return handle as T;
}
@@ -258,9 +245,9 @@ namespace YooAsset
/// </summary>
public void ReleaseAllHandles()
{
for (int i = _handles.Count - 1; i >= 0; i--)
List<HandleBase> tempers = _handles.ToList();
foreach (var handle in tempers)
{
var handle = _handles[i];
handle.Release();
}
}
@@ -276,7 +263,7 @@ namespace YooAsset
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
// 注意:回调方法如果发生异常,会阻断列表里的后续回调方法!
List<HandleBase> tempers = new List<HandleBase>(_handles);
List<HandleBase> tempers = _handles.ToList();
foreach (var hande in tempers)
{
if (hande.IsValid)

View File

@@ -14,6 +14,7 @@ namespace YooAsset
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
private long _sceneCreateIndex = 0;
private IBundleQuery _bundleQuery;
private int _bundleLoadingMaxConcurrency;
/// <summary>
/// 所属包裹
@@ -25,6 +26,11 @@ namespace YooAsset
/// </summary>
public bool LockLoadOperation = false;
/// <summary>
/// 统计正在加载的Bundle文件数量
/// </summary>
public int BundleLoadingCounter = 0;
public ResourceManager(string packageName)
{
@@ -34,8 +40,9 @@ namespace YooAsset
/// <summary>
/// 初始化
/// </summary>
public void Initialize(IBundleQuery bundleServices)
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
{
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
_bundleQuery = bundleServices;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
@@ -310,6 +317,10 @@ namespace YooAsset
{
return LoaderDic.Count > 0;
}
internal bool BundleLoadingIsBusy()
{
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency;
}
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
{