From ce62dbc27f5a067393b7d06425c83b0b2bcbbe4c Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 25 Oct 2023 18:28:55 +0800 Subject: [PATCH] update resource manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 所有异步加载方法增加权重参数。 --- .../Provider/BundledAllAssetsProvider.cs | 2 +- .../Provider/BundledAssetProvider.cs | 2 +- .../Provider/BundledRawFileProvider.cs | 2 +- .../Provider/BundledSceneProvider.cs | 6 +- .../Provider/BundledSubAssetsProvider.cs | 2 +- .../Provider/CompletedProvider.cs | 2 +- .../Provider/DatabaseAllAssetsProvider.cs | 2 +- .../Provider/DatabaseAssetProvider.cs | 2 +- .../Provider/DatabaseRawFileProvider.cs | 2 +- .../Provider/DatabaseSceneProvider.cs | 6 +- .../Provider/DatabaseSubAssetsProvider.cs | 2 +- .../ResourceManager/Provider/ProviderBase.cs | 19 ++- .../ResourceManager/ResourceManager.cs | 50 +++++--- .../ResourcePackage/ResourcePackage.cs | 109 +++++++++--------- Assets/YooAsset/Runtime/YooAssetsExtension.cs | 60 +++++----- 15 files changed, 152 insertions(+), 116 deletions(-) diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs index db0b388..3bb1c09 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs index 158ccda..a202c1a 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs index 6f89bab..788a04e 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs index f632ba2..abaf96e 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs @@ -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; } diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs index ca958e7..02b6261 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs index c87ad37..e674215 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs index 1931f02..c0f49ca 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs index 87fc107..3974213 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs index 6e96659..c9cd24d 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs index b3612dd..17223da 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs @@ -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; } diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs index 8e1478e..a6cf1b3 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs @@ -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() diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs index d457399..1605a7c 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs @@ -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 { public enum EStatus { @@ -22,6 +23,11 @@ namespace YooAsset /// public string ProviderGUID { private set; get; } + /// + /// 资源加载的优先级 + /// + public uint ProviderPriority { private set; get; } + /// /// 所属资源系统 /// @@ -97,10 +103,11 @@ namespace YooAsset private readonly List _handles = new List(); - 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 /// public abstract void Update(); + /// + /// 排序接口实现方法 + /// + public int CompareTo(ProviderBase other) + { + return this.ProviderPriority.CompareTo(other.ProviderPriority); + } + /// /// 销毁资源提供者 /// diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index 54e0eab..0e76617 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -220,7 +220,7 @@ namespace YooAsset /// /// 加载场景 /// - 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(); @@ -258,7 +262,7 @@ namespace YooAsset /// /// 加载资源对象 /// - 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(); } @@ -286,7 +294,7 @@ namespace YooAsset /// /// 加载子资源对象 /// - 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(); } @@ -314,7 +326,7 @@ namespace YooAsset /// /// 加载所有资源对象 /// - 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(); } @@ -342,7 +358,7 @@ namespace YooAsset /// /// 加载原生文件 /// - 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(); } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 0af4ee2..f09c259 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -548,7 +548,7 @@ namespace YooAsset public RawFileHandle LoadRawFileSync(AssetInfo assetInfo) { DebugCheckInitialize(); - return LoadRawFileInternal(assetInfo, true); + return LoadRawFileInternal(assetInfo, true, 0); } /// @@ -559,35 +559,35 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return LoadRawFileInternal(assetInfo, true); + return LoadRawFileInternal(assetInfo, true, 0); } /// /// 异步加载原生文件 /// /// 资源信息 - public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo) + public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0) { DebugCheckInitialize(); - return LoadRawFileInternal(assetInfo, false); + return LoadRawFileInternal(assetInfo, false, priority); } /// /// 异步加载原生文件 /// /// 资源的定位地址 - 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 /// 场景加载模式 /// 场景加载到90%自动挂起 /// 优先级 - 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 /// 场景加载模式 /// 场景加载到90%自动挂起 /// 优先级 - 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); } /// @@ -645,7 +645,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); - return LoadAssetInternal(assetInfo, true); + return LoadAssetInternal(assetInfo, true, 0); } /// @@ -657,7 +657,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); - return LoadAssetInternal(assetInfo, true); + return LoadAssetInternal(assetInfo, true, 0); } /// @@ -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 /// 异步加载资源对象 /// /// 资源信息 - public AssetHandle LoadAssetAsync(AssetInfo assetInfo) + public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0) { DebugCheckInitialize(); - return LoadAssetInternal(assetInfo, false); + return LoadAssetInternal(assetInfo, false, priority); } /// @@ -688,11 +688,11 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public AssetHandle LoadAssetAsync(string location) where TObject : UnityEngine.Object + public AssetHandle LoadAssetAsync(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); } /// @@ -700,31 +700,31 @@ namespace YooAsset /// /// 资源的定位地址 /// 资源类型 - 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); } /// /// 异步加载资源对象 /// /// 资源的定位地址 - 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); } /// @@ -751,7 +751,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); - return LoadSubAssetsInternal(assetInfo, true); + return LoadSubAssetsInternal(assetInfo, true, 0); } /// @@ -763,7 +763,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); - return LoadSubAssetsInternal(assetInfo, true); + return LoadSubAssetsInternal(assetInfo, true, 0); } /// @@ -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 /// 异步加载子资源对象 /// /// 资源信息 - public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo) + public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0) { DebugCheckInitialize(); - return LoadSubAssetsInternal(assetInfo, false); + return LoadSubAssetsInternal(assetInfo, false, priority); } /// @@ -794,11 +794,11 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public SubAssetsHandle LoadSubAssetsAsync(string location) where TObject : UnityEngine.Object + public SubAssetsHandle LoadSubAssetsAsync(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); } /// @@ -806,31 +806,31 @@ namespace YooAsset /// /// 资源的定位地址 /// 子对象类型 - 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); } /// /// 异步加载子资源对象 /// /// 资源的定位地址 - 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); } /// @@ -857,7 +857,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); - return LoadAllAssetsInternal(assetInfo, true); + return LoadAllAssetsInternal(assetInfo, true, 0); } /// @@ -869,7 +869,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); - return LoadAllAssetsInternal(assetInfo, true); + return LoadAllAssetsInternal(assetInfo, true, 0); } /// @@ -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 /// 异步加载资源包内所有资源对象 /// /// 资源信息 - public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo) + public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0) { DebugCheckInitialize(); - return LoadAllAssetsInternal(assetInfo, false); + return LoadAllAssetsInternal(assetInfo, false, priority); } /// @@ -900,11 +900,11 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public AllAssetsHandle LoadAllAssetsAsync(string location) where TObject : UnityEngine.Object + public AllAssetsHandle LoadAllAssetsAsync(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); } /// @@ -912,31 +912,31 @@ namespace YooAsset /// /// 资源的定位地址 /// 子对象类型 - 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); } /// /// 异步加载资源包内所有资源对象 /// /// 资源的定位地址 - 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} !"); diff --git a/Assets/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/YooAsset/Runtime/YooAssetsExtension.cs index 1d581d1..ef4dcd6 100644 --- a/Assets/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/YooAsset/Runtime/YooAssetsExtension.cs @@ -138,20 +138,20 @@ namespace YooAsset /// 异步加载原生文件 /// /// 资源信息 - 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); } /// /// 异步加载原生文件 /// /// 资源的定位地址 - 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 /// 场景加载模式 /// 场景加载到90%自动挂起 /// 优先级 - 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 /// 场景加载模式 /// 场景加载到90%自动挂起 /// 优先级 - 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 /// 异步加载资源对象 /// /// 资源信息 - 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); } /// @@ -242,10 +242,10 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public static AssetHandle LoadAssetAsync(string location) where TObject : UnityEngine.Object + public static AssetHandle LoadAssetAsync(string location, uint priority = 0) where TObject : UnityEngine.Object { DebugCheckDefaultPackageValid(); - return _defaultPackage.LoadAssetAsync(location); + return _defaultPackage.LoadAssetAsync(location, priority); } /// @@ -253,20 +253,20 @@ namespace YooAsset /// /// 资源的定位地址 /// 资源类型 - 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); } /// /// 异步加载资源对象 /// /// 资源的定位地址 - 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 /// 异步加载子资源对象 /// /// 资源信息 - 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); } /// @@ -329,10 +329,10 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public static SubAssetsHandle LoadSubAssetsAsync(string location) where TObject : UnityEngine.Object + public static SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object { DebugCheckDefaultPackageValid(); - return _defaultPackage.LoadSubAssetsAsync(location); + return _defaultPackage.LoadSubAssetsAsync(location, priority); } /// @@ -340,20 +340,20 @@ namespace YooAsset /// /// 资源的定位地址 /// 子对象类型 - 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); } /// /// 异步加载子资源对象 /// /// 资源的定位地址 - 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 /// 异步加载资源包内所有资源对象 /// /// 资源信息 - 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); } /// @@ -416,10 +416,10 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public static AllAssetsHandle LoadAllAssetsAsync(string location) where TObject : UnityEngine.Object + public static AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object { DebugCheckDefaultPackageValid(); - return _defaultPackage.LoadAllAssetsAsync(location); + return _defaultPackage.LoadAllAssetsAsync(location, priority); } /// @@ -427,20 +427,20 @@ namespace YooAsset /// /// 资源的定位地址 /// 子对象类型 - 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); } /// /// 异步加载资源包内所有资源对象 /// /// 资源的定位地址 - 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