update resource manager

所有异步加载方法增加权重参数。
pull/229/head
hevinci 2023-10-25 18:28:55 +08:00
parent 5b4a188c0b
commit ce62dbc27f
15 changed files with 152 additions and 116 deletions

View File

@ -8,7 +8,7 @@ namespace YooAsset
{
private AssetBundleRequest _cacheRequest;
public BundledAllAssetsProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public BundledAllAssetsProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -8,7 +8,7 @@ namespace YooAsset
{
private AssetBundleRequest _cacheRequest;
public BundledAssetProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public BundledAssetProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -3,7 +3,7 @@ namespace YooAsset
{
internal class BundledRawFileProvider : ProviderBase
{
public BundledRawFileProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public BundledRawFileProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -11,15 +11,13 @@ namespace YooAsset
public readonly LoadSceneMode SceneMode;
private readonly string _sceneName;
private readonly bool _suspendLoad;
private readonly int _priority;
private AsyncOperation _asyncOperation;
public BundledSceneProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, int priority) : base(impl, providerGUID, assetInfo)
public BundledSceneProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(impl, providerGUID, providerPriority, assetInfo)
{
SceneMode = sceneMode;
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
_priority = priority;
}
public override void Update()
{
@ -68,7 +66,7 @@ namespace YooAsset
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.priority = _priority;
_asyncOperation.priority = (int)ProviderPriority;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
Status = EStatus.Checking;
}

View File

@ -8,7 +8,7 @@ namespace YooAsset
{
private AssetBundleRequest _cacheRequest;
public BundledSubAssetsProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public BundledSubAssetsProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -3,7 +3,7 @@ namespace YooAsset
{
internal sealed class CompletedProvider : ProviderBase
{
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, 0, assetInfo)
{
}
public override void Update()

View File

@ -6,7 +6,7 @@ namespace YooAsset
{
internal sealed class DatabaseAllAssetsProvider : ProviderBase
{
public DatabaseAllAssetsProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public DatabaseAllAssetsProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -6,7 +6,7 @@ namespace YooAsset
{
internal sealed class DatabaseAssetProvider : ProviderBase
{
public DatabaseAssetProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public DatabaseAssetProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -3,7 +3,7 @@ namespace YooAsset
{
internal class DatabaseRawFileProvider : ProviderBase
{
public DatabaseRawFileProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public DatabaseRawFileProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -7,14 +7,12 @@ namespace YooAsset
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
private readonly int _priority;
private AsyncOperation _asyncOperation;
public DatabaseSceneProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, int priority) : base(impl, providerGUID, assetInfo)
public DatabaseSceneProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(impl, providerGUID, providerPriority, assetInfo)
{
SceneMode = sceneMode;
_suspendLoad = suspendLoad;
_priority = priority;
}
public override void Update()
{
@ -58,7 +56,7 @@ namespace YooAsset
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.priority = _priority;
_asyncOperation.priority = (int)ProviderPriority;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
Status = EStatus.Checking;
}

View File

@ -6,7 +6,7 @@ namespace YooAsset
{
internal sealed class DatabaseSubAssetsProvider : ProviderBase
{
public DatabaseSubAssetsProvider(ResourceManager impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
public DatabaseSubAssetsProvider(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(impl, providerGUID, providerPriority, assetInfo)
{
}
public override void Update()

View File

@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System;
namespace YooAsset
{
internal abstract class ProviderBase
internal abstract class ProviderBase : IComparable<ProviderBase>
{
public enum EStatus
{
@ -22,6 +23,11 @@ namespace YooAsset
/// </summary>
public string ProviderGUID { private set; get; }
/// <summary>
/// 资源加载的优先级
/// </summary>
public uint ProviderPriority { private set; get; }
/// <summary>
/// 所属资源系统
/// </summary>
@ -97,10 +103,11 @@ namespace YooAsset
private readonly List<HandleBase> _handles = new List<HandleBase>();
public ProviderBase(ResourceManager impl, string providerGUID, AssetInfo assetInfo)
public ProviderBase(ResourceManager impl, string providerGUID, uint providerPriority, AssetInfo assetInfo)
{
Impl = impl;
ProviderGUID = providerGUID;
ProviderPriority = providerPriority;
MainAssetInfo = assetInfo;
// 创建资源包加载器
@ -121,6 +128,14 @@ namespace YooAsset
/// </summary>
public abstract void Update();
/// <summary>
/// 排序接口实现方法
/// </summary>
public int CompareTo(ProviderBase other)
{
return this.ProviderPriority.CompareTo(other.ProviderPriority);
}
/// <summary>
/// 销毁资源提供者
/// </summary>

View File

@ -220,7 +220,7 @@ namespace YooAsset
/// <summary>
/// 加载场景
/// </summary>
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, int priority)
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
{
if (assetInfo.IsInvalid)
{
@ -241,12 +241,16 @@ namespace YooAsset
ProviderBase provider;
{
if (_simulationOnEditor)
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad, priority);
provider = new DatabaseSceneProvider(this, providerGUID, priority, assetInfo, sceneMode, suspendLoad);
else
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad, priority);
provider = new BundledSceneProvider(this, providerGUID, priority, assetInfo, sceneMode, suspendLoad);
provider.InitSpawnDebugInfo();
_providerList.Add(provider);
_providerDic.Add(providerGUID, provider);
if (priority > 0)
{
_providerList.Sort();
}
}
var handle = provider.CreateHandle<SceneHandle>();
@ -258,7 +262,7 @@ namespace YooAsset
/// <summary>
/// 加载资源对象
/// </summary>
public AssetHandle LoadAssetAsync(AssetInfo assetInfo)
public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority)
{
if (assetInfo.IsInvalid)
{
@ -273,12 +277,16 @@ namespace YooAsset
if (provider == null)
{
if (_simulationOnEditor)
provider = new DatabaseAssetProvider(this, providerGUID, assetInfo);
provider = new DatabaseAssetProvider(this, providerGUID, priority, assetInfo);
else
provider = new BundledAssetProvider(this, providerGUID, assetInfo);
provider = new BundledAssetProvider(this, providerGUID, priority, assetInfo);
provider.InitSpawnDebugInfo();
_providerList.Add(provider);
_providerDic.Add(providerGUID, provider);
if (priority > 0)
{
_providerList.Sort();
}
}
return provider.CreateHandle<AssetHandle>();
}
@ -286,7 +294,7 @@ namespace YooAsset
/// <summary>
/// 加载子资源对象
/// </summary>
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo)
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority)
{
if (assetInfo.IsInvalid)
{
@ -301,12 +309,16 @@ namespace YooAsset
if (provider == null)
{
if (_simulationOnEditor)
provider = new DatabaseSubAssetsProvider(this, providerGUID, assetInfo);
provider = new DatabaseSubAssetsProvider(this, providerGUID, priority, assetInfo);
else
provider = new BundledSubAssetsProvider(this, providerGUID, assetInfo);
provider = new BundledSubAssetsProvider(this, providerGUID, priority, assetInfo);
provider.InitSpawnDebugInfo();
_providerList.Add(provider);
_providerDic.Add(providerGUID, provider);
if (priority > 0)
{
_providerList.Sort();
}
}
return provider.CreateHandle<SubAssetsHandle>();
}
@ -314,7 +326,7 @@ namespace YooAsset
/// <summary>
/// 加载所有资源对象
/// </summary>
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo)
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority)
{
if (assetInfo.IsInvalid)
{
@ -329,12 +341,16 @@ namespace YooAsset
if (provider == null)
{
if (_simulationOnEditor)
provider = new DatabaseAllAssetsProvider(this, providerGUID, assetInfo);
provider = new DatabaseAllAssetsProvider(this, providerGUID, priority, assetInfo);
else
provider = new BundledAllAssetsProvider(this, providerGUID, assetInfo);
provider = new BundledAllAssetsProvider(this, providerGUID, priority, assetInfo);
provider.InitSpawnDebugInfo();
_providerList.Add(provider);
_providerDic.Add(providerGUID, provider);
if (priority > 0)
{
_providerList.Sort();
}
}
return provider.CreateHandle<AllAssetsHandle>();
}
@ -342,7 +358,7 @@ namespace YooAsset
/// <summary>
/// 加载原生文件
/// </summary>
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo)
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority)
{
if (assetInfo.IsInvalid)
{
@ -357,12 +373,16 @@ namespace YooAsset
if (provider == null)
{
if (_simulationOnEditor)
provider = new DatabaseRawFileProvider(this, providerGUID, assetInfo);
provider = new DatabaseRawFileProvider(this, providerGUID, priority, assetInfo);
else
provider = new BundledRawFileProvider(this, providerGUID, assetInfo);
provider = new BundledRawFileProvider(this, providerGUID, priority, assetInfo);
provider.InitSpawnDebugInfo();
_providerList.Add(provider);
_providerDic.Add(providerGUID, provider);
if (priority > 0)
{
_providerList.Sort();
}
}
return provider.CreateHandle<RawFileHandle>();
}

View File

@ -548,7 +548,7 @@ namespace YooAsset
public RawFileHandle LoadRawFileSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
return LoadRawFileInternal(assetInfo, true);
return LoadRawFileInternal(assetInfo, true, 0);
}
/// <summary>
@ -559,35 +559,35 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, true);
return LoadRawFileInternal(assetInfo, true, 0);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo)
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
return LoadRawFileInternal(assetInfo, false);
return LoadRawFileInternal(assetInfo, false, priority);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public RawFileHandle LoadRawFileAsync(string location)
public RawFileHandle LoadRawFileAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
return LoadRawFileInternal(assetInfo, false);
return LoadRawFileInternal(assetInfo, false, priority);
}
private RawFileHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
private RawFileHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckRawFileLoadMethod(nameof(LoadRawFileAsync));
var handle = _resourceMgr.LoadRawFileAsync(assetInfo);
var handle = _resourceMgr.LoadRawFileAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@ -602,7 +602,7 @@ namespace YooAsset
/// <param name="sceneMode">场景加载模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
public SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
@ -617,7 +617,7 @@ namespace YooAsset
/// <param name="sceneMode">场景加载模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
{
DebugCheckInitialize();
var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
@ -633,7 +633,7 @@ namespace YooAsset
public AssetHandle LoadAssetSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
return LoadAssetInternal(assetInfo, true);
return LoadAssetInternal(assetInfo, true, 0);
}
/// <summary>
@ -645,7 +645,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetInfo, true);
return LoadAssetInternal(assetInfo, true, 0);
}
/// <summary>
@ -657,7 +657,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, true);
return LoadAssetInternal(assetInfo, true, 0);
}
/// <summary>
@ -669,7 +669,7 @@ namespace YooAsset
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, true);
return LoadAssetInternal(assetInfo, true, 0);
}
@ -677,10 +677,10 @@ namespace YooAsset
/// 异步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AssetHandle LoadAssetAsync(AssetInfo assetInfo)
public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
return LoadAssetInternal(assetInfo, false);
return LoadAssetInternal(assetInfo, false, priority);
}
/// <summary>
@ -688,11 +688,11 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AssetHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object
public AssetHandle LoadAssetAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAssetInternal(assetInfo, false);
return LoadAssetInternal(assetInfo, false, priority);
}
/// <summary>
@ -700,31 +700,31 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public AssetHandle LoadAssetAsync(string location, System.Type type)
public AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, false);
return LoadAssetInternal(assetInfo, false, priority);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AssetHandle LoadAssetAsync(string location)
public AssetHandle LoadAssetAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAssetInternal(assetInfo, false);
return LoadAssetInternal(assetInfo, false, priority);
}
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadAssetAsync(assetInfo);
var handle = _resourceMgr.LoadAssetAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@ -739,7 +739,7 @@ namespace YooAsset
public SubAssetsHandle LoadSubAssetsSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
return LoadSubAssetsInternal(assetInfo, true);
return LoadSubAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -751,7 +751,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetInfo, true);
return LoadSubAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -763,7 +763,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, true);
return LoadSubAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -775,7 +775,7 @@ namespace YooAsset
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, true);
return LoadSubAssetsInternal(assetInfo, true, 0);
}
@ -783,10 +783,10 @@ namespace YooAsset
/// 异步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo)
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
return LoadSubAssetsInternal(assetInfo, false);
return LoadSubAssetsInternal(assetInfo, false, priority);
}
/// <summary>
@ -794,11 +794,11 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public SubAssetsHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
public SubAssetsHandle LoadSubAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadSubAssetsInternal(assetInfo, false);
return LoadSubAssetsInternal(assetInfo, false, priority);
}
/// <summary>
@ -806,31 +806,31 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type)
public SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, false);
return LoadSubAssetsInternal(assetInfo, false, priority);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public SubAssetsHandle LoadSubAssetsAsync(string location)
public SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadSubAssetsInternal(assetInfo, false);
return LoadSubAssetsInternal(assetInfo, false, priority);
}
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadSubAssetsAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadSubAssetsAsync(assetInfo);
var handle = _resourceMgr.LoadSubAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@ -845,7 +845,7 @@ namespace YooAsset
public AllAssetsHandle LoadAllAssetsSync(AssetInfo assetInfo)
{
DebugCheckInitialize();
return LoadAllAssetsInternal(assetInfo, true);
return LoadAllAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -857,7 +857,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAllAssetsInternal(assetInfo, true);
return LoadAllAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -869,7 +869,7 @@ namespace YooAsset
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, true);
return LoadAllAssetsInternal(assetInfo, true, 0);
}
/// <summary>
@ -881,7 +881,7 @@ namespace YooAsset
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, true);
return LoadAllAssetsInternal(assetInfo, true, 0);
}
@ -889,10 +889,10 @@ namespace YooAsset
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo)
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
return LoadAllAssetsInternal(assetInfo, false);
return LoadAllAssetsInternal(assetInfo, false, priority);
}
/// <summary>
@ -900,11 +900,11 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public AllAssetsHandle LoadAllAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
public AllAssetsHandle LoadAllAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject));
return LoadAllAssetsInternal(assetInfo, false);
return LoadAllAssetsInternal(assetInfo, false, priority);
}
/// <summary>
@ -912,31 +912,31 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type)
public AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, false);
return LoadAllAssetsInternal(assetInfo, false, priority);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public AllAssetsHandle LoadAllAssetsAsync(string location)
public AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
Type type = typeof(UnityEngine.Object);
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
return LoadAllAssetsInternal(assetInfo, false);
return LoadAllAssetsInternal(assetInfo, false, priority);
}
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadAllAssetsAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadAllAssetsAsync(assetInfo);
var handle = _resourceMgr.LoadAllAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@ -1158,6 +1158,11 @@ namespace YooAsset
if (type == null)
return;
if (typeof(UnityEngine.Behaviour).IsAssignableFrom(type))
{
throw new Exception($"Load asset type is invalid : {type.FullName} !");
}
if (typeof(UnityEngine.Object).IsAssignableFrom(type) == false)
{
throw new Exception($"Load asset type is invalid : {type.FullName} !");

View File

@ -138,20 +138,20 @@ namespace YooAsset
/// 异步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static RawFileHandle LoadRawFileAsync(AssetInfo assetInfo)
public static RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(assetInfo);
return _defaultPackage.LoadRawFileAsync(assetInfo, priority);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public static RawFileHandle LoadRawFileAsync(string location)
public static RawFileHandle LoadRawFileAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(location);
return _defaultPackage.LoadRawFileAsync(location, priority);
}
#endregion
@ -163,7 +163,7 @@ namespace YooAsset
/// <param name="sceneMode">场景加载模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(location, sceneMode, suspendLoad, priority);
@ -176,7 +176,7 @@ namespace YooAsset
/// <param name="sceneMode">场景加载模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100)
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
@ -231,10 +231,10 @@ namespace YooAsset
/// 异步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AssetHandle LoadAssetAsync(AssetInfo assetInfo)
public static AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(assetInfo);
return _defaultPackage.LoadAssetAsync(assetInfo, priority);
}
/// <summary>
@ -242,10 +242,10 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetAsync<TObject>(string location) where TObject : UnityEngine.Object
public static AssetHandle LoadAssetAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync<TObject>(location);
return _defaultPackage.LoadAssetAsync<TObject>(location, priority);
}
/// <summary>
@ -253,20 +253,20 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public static AssetHandle LoadAssetAsync(string location, System.Type type)
public static AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, type);
return _defaultPackage.LoadAssetAsync(location, type, priority);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetAsync(string location)
public static AssetHandle LoadAssetAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location);
return _defaultPackage.LoadAssetAsync(location, priority);
}
#endregion
@ -318,10 +318,10 @@ namespace YooAsset
/// 异步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo)
public static SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(assetInfo);
return _defaultPackage.LoadSubAssetsAsync(assetInfo, priority);
}
/// <summary>
@ -329,10 +329,10 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
public static SubAssetsHandle LoadSubAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync<TObject>(location);
return _defaultPackage.LoadSubAssetsAsync<TObject>(location, priority);
}
/// <summary>
@ -340,20 +340,20 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type)
public static SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, type);
return _defaultPackage.LoadSubAssetsAsync(location, type, priority);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsAsync(string location)
public static SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location);
return _defaultPackage.LoadSubAssetsAsync(location, priority);
}
#endregion
@ -405,10 +405,10 @@ namespace YooAsset
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo)
public static AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(assetInfo);
return _defaultPackage.LoadAllAssetsAsync(assetInfo, priority);
}
/// <summary>
@ -416,10 +416,10 @@ namespace YooAsset
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsAsync<TObject>(string location) where TObject : UnityEngine.Object
public static AllAssetsHandle LoadAllAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync<TObject>(location);
return _defaultPackage.LoadAllAssetsAsync<TObject>(location, priority);
}
/// <summary>
@ -427,20 +427,20 @@ namespace YooAsset
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type)
public static AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, type);
return _defaultPackage.LoadAllAssetsAsync(location, type, priority);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsAsync(string location)
public static AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location);
return _defaultPackage.LoadAllAssetsAsync(location, priority);
}
#endregion