mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
基于资源框架实现对标签WEBGL_PRELOAD、PRELOAD的预加载。 接口GameModule.Resource.GetPreLoadAsset<T>(location)
基于资源框架实现对标签WEBGL_PRELOAD、PRELOAD的预加载。 接口GameModule.Resource.GetPreLoadAsset<T>(location)
This commit is contained in:
@@ -14,6 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
ShowPackageView: 0
|
||||
EnableAddressable: 1
|
||||
LocationToLower: 0
|
||||
IncludeAssetGUID: 0
|
||||
UniqueBundleName: 0
|
||||
ShowEditorAlias: 0
|
||||
Packages:
|
||||
@@ -78,7 +80,7 @@ MonoBehaviour:
|
||||
AddressRuleName: AddressByFileName
|
||||
PackRuleName: PackDirectory
|
||||
FilterRuleName: CollectAll
|
||||
AssetTags:
|
||||
AssetTags: WEBGL_PRELOAD
|
||||
UserData:
|
||||
- GroupName: DLL
|
||||
GroupDesc: "\u4EE3\u7801"
|
||||
|
@@ -304,5 +304,20 @@ namespace TEngine
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>原生文件资源实例。</returns>
|
||||
UniTask<T[]> LoadAllSubAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
public void PushPreLoadAsset(string location, Object assetObject);
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location) where T : Object;
|
||||
}
|
||||
}
|
@@ -101,6 +101,7 @@ namespace TEngine
|
||||
|
||||
internal override void Shutdown()
|
||||
{
|
||||
ReleasePreLoadAssets();
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
@@ -878,5 +879,53 @@ namespace TEngine
|
||||
|
||||
return cancelOrFailed ? null : handle.GetSubAssetObjects<T>();
|
||||
}
|
||||
|
||||
#region 预加载
|
||||
|
||||
private readonly Dictionary<string, Object> _preLoadMaps = new Dictionary<string, Object>();
|
||||
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
public void PushPreLoadAsset(string location, Object assetObject)
|
||||
{
|
||||
if (_preLoadMaps.ContainsKey(location))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_preLoadMaps.Add(location, assetObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location) where T : Object
|
||||
{
|
||||
if (_preLoadMaps.TryGetValue(location,out Object assetObject))
|
||||
{
|
||||
return assetObject as T;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
private void ReleasePreLoadAssets()
|
||||
{
|
||||
using var iter = _preLoadMaps.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
var assetObject = iter.Current.Value;
|
||||
if (assetObject != null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(assetObject);
|
||||
}
|
||||
}
|
||||
_preLoadMaps.Clear();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
@@ -658,5 +657,28 @@ namespace TEngine
|
||||
{
|
||||
return await m_ResourceManager.LoadAllSubAssetAsync<T>(location, cancellationToken);
|
||||
}
|
||||
|
||||
#region 预加载
|
||||
/// <summary>
|
||||
/// 放入预加载对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="assetObject">预加载对象。</param>
|
||||
public void PushPreLoadAsset(string location, UnityEngine.Object assetObject)
|
||||
{
|
||||
m_ResourceManager.PushPreLoadAsset(location, assetObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取预加载的实例对象。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <typeparam name="T">资源实例类型。</typeparam>
|
||||
/// <returns>预加载对象。</returns>
|
||||
public T GetPreLoadAsset<T>(string location) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.GetPreLoadAsset<T>(location);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user