mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Compare commits
14 Commits
TEngine4.0
...
TEngine4.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d8f8514f9d | ||
![]() |
f2f6b2422f | ||
![]() |
3a9cad9397 | ||
![]() |
5e70e7972e | ||
![]() |
8d2b4200d6 | ||
![]() |
b983e85416 | ||
![]() |
99d2afdbd7 | ||
![]() |
57ce836b3c | ||
![]() |
8dce78d6fb | ||
![]() |
6d41adffd9 | ||
![]() |
cb9129261b | ||
![]() |
89dd6214d4 | ||
![]() |
1aec76d64c | ||
![]() |
859f654f6d |
@@ -42,8 +42,7 @@ namespace GameLogic
|
||||
|
||||
public void SetSprite(string sprite)
|
||||
{
|
||||
m_image.sprite = LoadAsset<Sprite>(sprite);
|
||||
m_image.SetNativeSize();
|
||||
m_image.SetSprite(sprite);
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
|
@@ -34,6 +34,7 @@ namespace TEngine.Editor.Inspector
|
||||
private SerializedProperty m_MaxUnloadUnusedAssetsInterval = null;
|
||||
private SerializedProperty m_DownloadingMaxNum = null;
|
||||
private SerializedProperty m_FailedTryAgain = null;
|
||||
private SerializedProperty m_adaptiveReplacementCacheCapacity = null;
|
||||
|
||||
private int m_ResourceModeIndex = 0;
|
||||
private int m_PackageIndex = 0;
|
||||
@@ -54,6 +55,7 @@ namespace TEngine.Editor.Inspector
|
||||
m_MaxUnloadUnusedAssetsInterval = serializedObject.FindProperty("maxUnloadUnusedAssetsInterval");
|
||||
m_DownloadingMaxNum = serializedObject.FindProperty("downloadingMaxNum");
|
||||
m_FailedTryAgain = serializedObject.FindProperty("failedTryAgain");
|
||||
m_adaptiveReplacementCacheCapacity = serializedObject.FindProperty("adaptiveReplacementCacheCapacity");
|
||||
|
||||
RefreshModes();
|
||||
RefreshTypeNames();
|
||||
@@ -199,6 +201,19 @@ namespace TEngine.Editor.Inspector
|
||||
m_FailedTryAgain.intValue = (int)failedTryAgain;
|
||||
}
|
||||
}
|
||||
|
||||
int adaptiveReplacementCacheCapacity = (int)EditorGUILayout.Slider("ARC Table Capacity", m_adaptiveReplacementCacheCapacity.intValue, 8f, 128f);
|
||||
if (adaptiveReplacementCacheCapacity != m_adaptiveReplacementCacheCapacity.intValue)
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
t.adaptiveReplacementCacheCapacity = adaptiveReplacementCacheCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_adaptiveReplacementCacheCapacity.intValue = adaptiveReplacementCacheCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||
|
@@ -397,6 +397,10 @@ public static class EditorSpriteSaveInfo
|
||||
atlas.Add(spriteList.ToArray());
|
||||
|
||||
AssetDatabase.CreateAsset(atlas, path);
|
||||
if (File.Exists(pathv2))
|
||||
{
|
||||
AssetDatabase.DeleteAsset(pathv2);
|
||||
}
|
||||
File.Move(path, pathv2);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
@@ -413,6 +417,7 @@ public static class EditorSpriteSaveInfo
|
||||
Init();
|
||||
List<string> needSaveAtlas = new List<string>();
|
||||
m_tempAllASprites.Clear();
|
||||
m_allASprites.Clear();
|
||||
var findAssets = AssetDatabase.FindAssets("t:sprite", new[] { UIAtlasPath });
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
|
@@ -231,5 +231,35 @@ namespace TEngine
|
||||
|
||||
CheckModify();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回调调用。
|
||||
/// </summary>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <param name="arg3">事件参数3。</param>
|
||||
/// <param name="arg4">事件参数4。</param>
|
||||
/// <param name="arg5">事件参数5。</param>
|
||||
/// <param name="arg6">事件参数6。</param>
|
||||
/// <typeparam name="TArg1">事件参数1类型。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数2类型。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数3类型。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数4类型。</typeparam>
|
||||
/// <typeparam name="TArg5">事件参数5类型。</typeparam>
|
||||
/// <typeparam name="TArg6">事件参数6类型。</typeparam>
|
||||
public void Callback<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
|
||||
{
|
||||
_isExecute = true;
|
||||
for (var i = 0; i < _listExist.Count; i++)
|
||||
{
|
||||
var d = _listExist[i];
|
||||
if (d is Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6> action)
|
||||
{
|
||||
action(arg1, arg2, arg3, arg4, arg5, arg6);
|
||||
}
|
||||
}
|
||||
|
||||
CheckModify();
|
||||
}
|
||||
}
|
||||
}
|
@@ -151,6 +151,29 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送事件。
|
||||
/// </summary>
|
||||
/// <param name="eventType">事件类型。</param>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <param name="arg3">事件参数3。</param>
|
||||
/// <param name="arg4">事件参数4。</param>
|
||||
/// <param name="arg5">事件参数5。</param>
|
||||
/// <param name="arg6">事件参数6。</param>
|
||||
/// <typeparam name="TArg1">事件参数1类型。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数2类型。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数3类型。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数4类型。</typeparam>
|
||||
/// <typeparam name="TArg5">事件参数5类型。</typeparam>
|
||||
/// <typeparam name="TArg6">事件参数6类型。</typeparam>
|
||||
public void Send<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(int eventType, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
|
||||
{
|
||||
if (_eventTable.TryGetValue(eventType, out var d))
|
||||
{
|
||||
d.Callback(arg1, arg2, arg3, arg4, arg5, arg6);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -94,6 +94,23 @@ namespace TEngine
|
||||
{
|
||||
return _eventMgr.Dispatcher.AddEventListener(eventType, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加事件监听。
|
||||
/// </summary>
|
||||
/// <param name="eventType">事件类型。</param>
|
||||
/// <param name="handler">事件处理回调。</param>
|
||||
/// <typeparam name="TArg1">事件参数1类型。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数2类型。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数3类型。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数4类型。</typeparam>
|
||||
/// <typeparam name="TArg5">事件参数5类型。</typeparam>
|
||||
/// <typeparam name="TArg6">事件参数6类型。</typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool AddEventListener<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(int eventType, Action<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6> handler)
|
||||
{
|
||||
return _eventMgr.Dispatcher.AddEventListener(eventType, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除事件监听。
|
||||
@@ -534,6 +551,27 @@ namespace TEngine
|
||||
{
|
||||
_eventMgr.Dispatcher.Send(RuntimeId.ToRuntimeId(eventType), arg1, arg2, arg3, arg4, arg5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="eventType">事件类型。</param>
|
||||
/// <param name="arg1">事件参数1。</param>
|
||||
/// <param name="arg2">事件参数2。</param>
|
||||
/// <param name="arg3">事件参数3。</param>
|
||||
/// <param name="arg4">事件参数4。</param>
|
||||
/// <param name="arg5">事件参数5。</param>
|
||||
/// <param name="arg6">事件参数6。</param>
|
||||
/// <typeparam name="TArg1">事件参数1类型。</typeparam>
|
||||
/// <typeparam name="TArg2">事件参数2类型。</typeparam>
|
||||
/// <typeparam name="TArg3">事件参数3类型。</typeparam>
|
||||
/// <typeparam name="TArg4">事件参数4类型。</typeparam>
|
||||
/// <typeparam name="TArg5">事件参数5类型。</typeparam>
|
||||
/// <typeparam name="TArg6">事件参数6类型。</typeparam>
|
||||
public static void Send<TArg1, TArg2, TArg3, TArg4, TArg5, TArg6>(int eventType, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
|
||||
{
|
||||
_eventMgr.Dispatcher.Send(eventType, arg1, arg2, arg3, arg4, arg5, arg6);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@@ -48,7 +48,7 @@ namespace TEngine
|
||||
_listHandles.Clear();
|
||||
}
|
||||
|
||||
private void AddEvent(int eventType, Delegate handler)
|
||||
private void AddEventImp(int eventType, Delegate handler)
|
||||
{
|
||||
_listEventTypes.Add(eventType);
|
||||
_listHandles.Add(handler);
|
||||
@@ -56,51 +56,51 @@ namespace TEngine
|
||||
|
||||
#region UIEvent
|
||||
|
||||
public void AddUIEvent(int eventType, Action handler)
|
||||
public void AddEvent(int eventType, Action handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUIEvent<T>(int eventType, Action<T> handler)
|
||||
public void AddEvent<T>(int eventType, Action<T> handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUIEvent<T1, T2>(int eventType, Action<T1, T2> handler)
|
||||
public void AddEvent<T1, T2>(int eventType, Action<T1, T2> handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUIEvent<T1, T2, T3>(int eventType, Action<T1, T2, T3> handler)
|
||||
public void AddEvent<T1, T2, T3>(int eventType, Action<T1, T2, T3> handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUIEvent<T1, T2, T3, T4>(int eventType, Action<T1, T2, T3, T4> handler)
|
||||
public void AddEvent<T1, T2, T3, T4>(int eventType, Action<T1, T2, T3, T4> handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddUIEvent<T1, T2, T3, T4, T5>(int eventType, Action<T1, T2, T3, T4, T5> handler)
|
||||
public void AddEvent<T1, T2, T3, T4, T5>(int eventType, Action<T1, T2, T3, T4, T5> handler)
|
||||
{
|
||||
if (GameEvent.AddEventListener(eventType, handler))
|
||||
{
|
||||
AddEvent(eventType, handler);
|
||||
AddEventImp(eventType, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -159,7 +159,7 @@ namespace TEngine
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
goto Dispose;
|
||||
return;
|
||||
}
|
||||
|
||||
image.sprite = operation.AssetObject as Sprite;
|
||||
@@ -167,9 +167,6 @@ namespace TEngine
|
||||
{
|
||||
image.SetNativeSize();
|
||||
}
|
||||
|
||||
Dispose:
|
||||
operation.Dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -204,13 +201,10 @@ namespace TEngine
|
||||
{
|
||||
if (spriteRenderer == null)
|
||||
{
|
||||
goto Dispose;
|
||||
return;
|
||||
}
|
||||
|
||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||
|
||||
Dispose:
|
||||
operation.Dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -143,7 +143,7 @@ namespace TEngine
|
||||
m_InstanceRoot.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
AudioModuleImp.Initialize(m_AudioGroupConfigs, m_InstanceRoot);
|
||||
AudioModuleImp.Initialize(m_AudioGroupConfigs, m_InstanceRoot, m_AudioMixer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -324,8 +324,9 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="audioGroupConfigs">音频轨道组配置。</param>
|
||||
/// <param name="instanceRoot">实例化根节点。</param>
|
||||
/// <param name="audioMixer">音频混响器。</param>
|
||||
/// <exception cref="GameFrameworkException"></exception>
|
||||
public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null)
|
||||
public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null,AudioMixer audioMixer = null)
|
||||
{
|
||||
if (_instanceRoot == null)
|
||||
{
|
||||
@@ -364,6 +365,11 @@ namespace TEngine
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
|
||||
if (audioMixer != null)
|
||||
{
|
||||
_audioMixer = audioMixer;
|
||||
}
|
||||
|
||||
if (_audioMixer == null)
|
||||
{
|
||||
_audioMixer = Resources.Load<AudioMixer>("AudioMixer");
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
@@ -60,7 +61,9 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="audioGroupConfigs">音频轨道组配置。</param>
|
||||
/// <param name="instanceRoot">实例化根节点。</param>
|
||||
public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null);
|
||||
/// <param name="audioMixer">音频混响器。</param>
|
||||
/// <exception cref="GameFrameworkException"></exception>
|
||||
public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null, AudioMixer audioMixer = null);
|
||||
|
||||
/// <summary>
|
||||
/// 重启音频模块。
|
||||
|
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// Adaptive Replacement Cache缓存表。
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">Adaptive Replacement CacheKey。</typeparam>
|
||||
/// <typeparam name="TValue">Adaptive Replacement CacheValue</typeparam>
|
||||
/// <remarks>缓存替换策略(Cache Replacement Policy)- ARC(Adaptive Replacement Cache)。</remarks>
|
||||
public class ArcCacheTable<TKey, TValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// ARC缓存表哈希表。
|
||||
/// <remarks>Dictionary 中存储 key 和 QueueNode 中节点的映射关系。</remarks>
|
||||
/// <remarks>算法优化的关键在于如何降低链表的删除操作的时间复杂度。不管是在插入、删除、查找缓存的时候,都可以通过这种联系来将时间复杂度降低到 O(1)。</remarks>
|
||||
/// </summary>
|
||||
protected readonly Dictionary<TKey, QueueNode<TKey, TValue>> CacheStorageMap;
|
||||
|
||||
private readonly QueueNode<TKey, TValue> _t1Head;
|
||||
private readonly QueueNode<TKey, TValue> _t2Head;
|
||||
private readonly QueueNode<TKey, TValue> _b1Head;
|
||||
private readonly QueueNode<TKey, TValue> _b2Head;
|
||||
|
||||
private int _adaptiveParameter;
|
||||
private int _t1Size;
|
||||
private int _t2Size;
|
||||
private int _b1Size;
|
||||
private int _b2Size;
|
||||
protected readonly int Capacity;
|
||||
|
||||
public delegate void OnAdd(TKey key,TValue data);
|
||||
|
||||
public delegate void OnRemove(TKey key,TValue data);
|
||||
|
||||
/// <summary>
|
||||
/// ARC缓存表添加成功回调。
|
||||
/// </summary>
|
||||
public readonly OnAdd OnAddCallback;
|
||||
|
||||
/// <summary>
|
||||
/// ARC缓存表移除回调。
|
||||
/// </summary>
|
||||
public readonly OnRemove OnRemoveCallback;
|
||||
|
||||
/// <summary>
|
||||
/// ARC缓存表哈希表构造。
|
||||
/// </summary>
|
||||
/// <param name="capacity">容量。</param>
|
||||
/// <param name="onAdd">LRU缓存表添加成功回调。</param>
|
||||
/// <param name="onRemove">LRU缓存表移除回调。</param>
|
||||
public ArcCacheTable(int capacity, OnAdd onAdd = null, OnRemove onRemove = null)
|
||||
{
|
||||
Capacity = capacity;
|
||||
OnAddCallback = onAdd;
|
||||
OnRemoveCallback = onRemove;
|
||||
CacheStorageMap = new Dictionary<TKey, QueueNode<TKey, TValue>>();
|
||||
_t1Head = new QueueNode<TKey, TValue>();
|
||||
_t2Head = new QueueNode<TKey, TValue>();
|
||||
_b1Head = new QueueNode<TKey, TValue>();
|
||||
_b2Head = new QueueNode<TKey, TValue>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象推入ARC缓存表。
|
||||
/// </summary>
|
||||
/// <param name="key">键。</param>
|
||||
/// <param name="value">值。</param>
|
||||
public void PutCache(TKey key, TValue value)
|
||||
{
|
||||
CacheStorageMap.TryGetValue(key, out QueueNode<TKey, TValue> queueNode);
|
||||
|
||||
if (queueNode == null)
|
||||
{
|
||||
OnMissOnAllQueue(key, value);
|
||||
OnAddCallback?.Invoke(key,value);
|
||||
}
|
||||
else if (queueNode.QueueType == QueueType.B1)
|
||||
{
|
||||
queueNode.Set(value);
|
||||
OnHitOnB1(queueNode);
|
||||
}
|
||||
else if (queueNode.QueueType == QueueType.B2)
|
||||
{
|
||||
queueNode.Set(value);
|
||||
OnHitOnB2(queueNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
queueNode.Set(value);
|
||||
OnHitOnT1orT2(queueNode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从ARC缓存表取出对象。
|
||||
/// </summary>
|
||||
/// <param name="key">键。</param>
|
||||
/// <returns>TValue from cache if exists or null。</returns>
|
||||
public TValue GetCache(TKey key)
|
||||
{
|
||||
CacheStorageMap.TryGetValue(key, out QueueNode<TKey, TValue> queueNode);
|
||||
|
||||
if (queueNode == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
else
|
||||
{
|
||||
return queueNode.Get();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在所有队列中未命中时执行任务(Case:Key不在(T1 u B1 u T2 u B2))。
|
||||
/// </summary>
|
||||
/// <param name="key">key cache key。</param>
|
||||
/// <param name="value">value to inset in cache。</param>
|
||||
private void OnMissOnAllQueue(TKey key, TValue value)
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNode = new QueueNode<TKey, TValue>(key, value);
|
||||
queueNode.QueueType = QueueType.T1;
|
||||
|
||||
int sizeL1 = _t1Size + _b1Size;
|
||||
int sizeL2 = _t2Size + _b2Size;
|
||||
if (sizeL1 == Capacity)
|
||||
{
|
||||
if (_t1Size < Capacity)
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNodeToBeRemoved = _b1Head.Next;
|
||||
RemoveFromQueue(queueNodeToBeRemoved);
|
||||
queueNodeToBeRemoved.Remove();
|
||||
_b1Size--;
|
||||
|
||||
Replace(queueNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNodeToBeRemoved = _t1Head.Next;
|
||||
RemoveFromQueue(queueNodeToBeRemoved);
|
||||
queueNodeToBeRemoved.Remove();
|
||||
_t1Size--;
|
||||
}
|
||||
}
|
||||
else if (sizeL1 < Capacity && sizeL1 + sizeL2 >= Capacity)
|
||||
{
|
||||
if (sizeL1 + sizeL2 >= 2 * Capacity)
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNodeToBeRemoved = _b2Head.Next;
|
||||
RemoveFromQueue(queueNodeToBeRemoved);
|
||||
queueNodeToBeRemoved.Remove();
|
||||
_b2Size--;
|
||||
}
|
||||
|
||||
Replace(queueNode);
|
||||
}
|
||||
|
||||
_t1Size++;
|
||||
CacheStorageMap.Add(key, queueNode);
|
||||
queueNode.AddToLast(_t1Head);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行任务命中B1 (Case:Key在B1中)。
|
||||
/// </summary>
|
||||
/// <param name="queueNode">queueNode queue node。</param>
|
||||
private void OnHitOnB1(QueueNode<TKey, TValue> queueNode)
|
||||
{
|
||||
_adaptiveParameter = Math.Min(Capacity, _adaptiveParameter + Math.Max(_b2Size / _b1Size, 1));
|
||||
Replace(queueNode);
|
||||
|
||||
_t2Size++;
|
||||
_b1Size--;
|
||||
queueNode.Remove();
|
||||
queueNode.QueueType = QueueType.T2;
|
||||
queueNode.AddToLast(_t2Head);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行任务命中B2 (Case:Key在B2中)。
|
||||
/// </summary>
|
||||
/// <param name="queueNode">queueNode queue node。</param>
|
||||
private void OnHitOnB2(QueueNode<TKey, TValue> queueNode)
|
||||
{
|
||||
_adaptiveParameter = Math.Max(0, _adaptiveParameter - Math.Max(_b1Size / _b2Size, 1));
|
||||
Replace(queueNode);
|
||||
|
||||
_t2Size++;
|
||||
_b2Size--;
|
||||
queueNode.Remove();
|
||||
queueNode.QueueType = QueueType.T2;
|
||||
queueNode.AddToLast(_t2Head);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行任务命中T1或者T2 (Case:Key在T1或者T2中)。
|
||||
/// </summary>
|
||||
/// <param name="queueNode">queueNode queue node。</param>
|
||||
private void OnHitOnT1orT2(QueueNode<TKey, TValue> queueNode)
|
||||
{
|
||||
if (queueNode.QueueType == QueueType.T1)
|
||||
{
|
||||
_t1Size--;
|
||||
_t2Size++;
|
||||
}
|
||||
|
||||
queueNode.Remove();
|
||||
queueNode.QueueType = QueueType.T2;
|
||||
queueNode.AddToLast(_t2Head);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 替换队列节点(情况:L1(T1 u B1)少于c个)
|
||||
/// </summary>
|
||||
/// <param name="queueNode">queueNode queue node。</param>
|
||||
private void Replace(QueueNode<TKey, TValue> queueNode)
|
||||
{
|
||||
if (_t1Size >= 1 && ((queueNode.QueueType == QueueType.B2 && _t1Size == _adaptiveParameter) || _t1Size > _adaptiveParameter))
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNodeToBeRemoved = _t1Head.Next;
|
||||
queueNodeToBeRemoved.Remove();
|
||||
queueNodeToBeRemoved.QueueType = QueueType.B1;
|
||||
queueNodeToBeRemoved.AddToLast(_b1Head);
|
||||
_t1Size--;
|
||||
_b1Size++;
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueNode<TKey, TValue> queueNodeToBeRemoved = _t2Head.Next;
|
||||
queueNodeToBeRemoved.Remove();
|
||||
queueNodeToBeRemoved.QueueType = QueueType.B2;
|
||||
queueNodeToBeRemoved.AddToLast(_b2Head);
|
||||
_t2Size--;
|
||||
_b2Size++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove TValue data from queue and dispose it
|
||||
/// </summary>
|
||||
/// <param name="queueNodeToBeRemoved">queueNodeToBeRemoved queue node to be remove from queue</param>
|
||||
public void RemoveFromQueue(QueueNode<TKey, TValue> queueNodeToBeRemoved)
|
||||
{
|
||||
CacheStorageMap.Remove(queueNodeToBeRemoved.Key);
|
||||
TValue value = queueNodeToBeRemoved.Get();
|
||||
try
|
||||
{
|
||||
OnRemoveCallback?.Invoke(queueNodeToBeRemoved.Key,value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public void PrintCacheIdsFromQueue()
|
||||
{
|
||||
String keys = "";
|
||||
foreach (var queueNode in CacheStorageMap)
|
||||
{
|
||||
var key = queueNode.Key;
|
||||
if (keys == "")
|
||||
keys += key;
|
||||
else
|
||||
keys += " | " + key;
|
||||
}
|
||||
|
||||
Debug.Log("All Existing Keys in Cache are : " + keys);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2486d1f34ad744b7bb19b1b220952ee9
|
||||
timeCreated: 1697174054
|
@@ -245,7 +245,7 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GameModule.Resource.LoadAssetGetOperation<T>(assetName);
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
|
||||
Reference(handle);
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
assetOperationHandle = GameModule.Resource.LoadAssetGetOperation<T>(assetName);
|
||||
assetOperationHandle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
|
||||
Reference(assetOperationHandle);
|
||||
|
||||
@@ -334,7 +334,7 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
assetOperationHandle = GameModule.Resource.LoadAssetGetOperation<T>(assetName);
|
||||
assetOperationHandle = YooAssets.LoadAssetSync<T>(assetName);
|
||||
|
||||
Reference(assetOperationHandle);
|
||||
|
||||
@@ -354,11 +354,10 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
// ReSharper disable once UnusedParameter.Global
|
||||
// ReSharper disable once RedundantAssignment
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken,AssetOperationHandle assetOperationHandle = null) where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetName))
|
||||
{
|
||||
@@ -379,7 +378,7 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = GameModule.Resource.LoadAssetAsyncHandle<T>(assetName);
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetAsync<T>(assetName);
|
||||
|
||||
Reference(handle);
|
||||
|
||||
@@ -391,8 +390,6 @@ namespace TEngine
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
assetOperationHandle = handle;
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
@@ -411,21 +408,9 @@ namespace TEngine
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await LoadAssetAsync<GameObject>(assetName,cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="assetOperationHandle">资源操作句柄。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken,AssetOperationHandle assetOperationHandle)
|
||||
{
|
||||
return await LoadAssetAsync<GameObject>(assetName,cancellationToken,assetOperationHandle);
|
||||
}
|
||||
}
|
||||
}
|
@@ -195,8 +195,7 @@ namespace TEngine
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken)
|
||||
where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken = default) where T : Object
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadAssetAsync<T>(assetName, cancellationToken);
|
||||
@@ -208,7 +207,7 @@ namespace TEngine
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
DirtyInitAssetGroup();
|
||||
return await _assetGroup.LoadGameObjectAsync(assetName, cancellationToken);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -61,6 +62,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
long Milliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源缓存表容量。
|
||||
/// </summary>
|
||||
int ARCTableCapacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置资源只读区路径。
|
||||
/// </summary>
|
||||
@@ -158,27 +164,32 @@ namespace TEngine
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location) where T : Object;
|
||||
T LoadAsset<T>(string location, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, bool needInstance, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
@@ -186,25 +197,28 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object;
|
||||
T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object;
|
||||
AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象。
|
||||
@@ -226,6 +240,14 @@ namespace TEngine
|
||||
/// <param name="assetInfo">资源信息。</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景。
|
||||
/// </summary>
|
||||
@@ -234,7 +256,7 @@ namespace TEngine
|
||||
/// <param name="suspendLoad">加载完毕时是否主动挂起。</param>
|
||||
/// <param name="priority">优先级。</param>
|
||||
/// <returns>异步加载场景句柄。</returns>
|
||||
SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false,int priority = 100);
|
||||
SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景.
|
||||
@@ -252,17 +274,20 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object;
|
||||
UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object;
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
@@ -270,8 +295,9 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default);
|
||||
UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false);
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载原生文件。
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b36f61f6af84adcb3bdba5976c7d9e6
|
||||
timeCreated: 1696849773
|
@@ -0,0 +1,125 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过资源标识加载资源。
|
||||
/// </summary>
|
||||
/// <typeparam name="TObject">资源实例类型。</typeparam>
|
||||
public class LoadAssetsByTagOperation<TObject> : GameAsyncOperation where TObject : UnityEngine.Object
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadAssets,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _tag;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private List<AssetOperationHandle> _handles;
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象集合
|
||||
/// </summary>
|
||||
public List<TObject> AssetObjects { private set; get; }
|
||||
|
||||
|
||||
public LoadAssetsByTagOperation(string tag)
|
||||
{
|
||||
_tag = tag;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
_steps = ESteps.LoadAssets;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadAssets)
|
||||
{
|
||||
AssetInfo[] assetInfos = YooAssets.GetAssetInfos(_tag);
|
||||
_handles = new List<AssetOperationHandle>(assetInfos.Length);
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
var handle = YooAssets.LoadAssetAsync(assetInfo);
|
||||
_handles.Add(handle);
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
if (handle.IsDone == false)
|
||||
{
|
||||
Progress = (float)index / _handles.Count;
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
AssetObjects = new List<TObject>(_handles.Count);
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
if (handle.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var assetObject = handle.AssetObject as TObject;
|
||||
if (assetObject != null)
|
||||
{
|
||||
AssetObjects.Add(assetObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"资源类型转换失败:{handle.AssetObject.name}";
|
||||
Debug.LogError($"{error}");
|
||||
AssetObjects.Clear();
|
||||
SetFinish(false, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"{handle.LastError}");
|
||||
AssetObjects.Clear();
|
||||
SetFinish(false, handle.LastError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetFinish(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFinish(bool succeed, string error = "")
|
||||
{
|
||||
Error = error;
|
||||
Status = succeed ? EOperationStatus.Succeed : EOperationStatus.Failed;
|
||||
_steps = ESteps.Done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void ReleaseHandle()
|
||||
{
|
||||
foreach (var handle in _handles)
|
||||
{
|
||||
handle.Release();
|
||||
}
|
||||
|
||||
_handles.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b49f6372b68a4871baed40595ac22c61
|
||||
timeCreated: 1696849782
|
@@ -0,0 +1,82 @@
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// 队列类型。
|
||||
/// T1, recent cache entries.
|
||||
/// T2, ghost entries recently evicted from the T1 cache.
|
||||
/// B1, frequent entries.
|
||||
/// B2, ghost entries recently evicted from the T2 cache.
|
||||
/// <remarks></remarks>
|
||||
/// </summary>
|
||||
public enum QueueType
|
||||
{
|
||||
None,
|
||||
/// <summary>
|
||||
/// T1, recent cache entries.
|
||||
/// </summary>
|
||||
T1,
|
||||
/// <summary>
|
||||
/// B1, frequent entries.
|
||||
/// </summary>
|
||||
B1,
|
||||
/// <summary>
|
||||
/// T2, ghost entries recently evicted from the T1 cache.
|
||||
/// </summary>
|
||||
T2,
|
||||
/// <summary>
|
||||
/// B2, ghost entries recently evicted from the T2 cache.
|
||||
/// </summary>
|
||||
B2
|
||||
}
|
||||
|
||||
public class QueueNode<TKey, TValue>
|
||||
{
|
||||
public readonly TKey Key;
|
||||
public QueueNode<TKey, TValue> Prev;
|
||||
public QueueNode<TKey, TValue> Next;
|
||||
public QueueType QueueType;
|
||||
public TValue Value;
|
||||
|
||||
public QueueNode()
|
||||
{
|
||||
this.Prev = this;
|
||||
this.Next = this;
|
||||
}
|
||||
|
||||
public QueueNode(TKey key, TValue data)
|
||||
{
|
||||
this.Key = key;
|
||||
this.Value = data;
|
||||
}
|
||||
|
||||
public TValue Get()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public void Set(TValue value)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public void AddToLast(QueueNode<TKey, TValue> head)
|
||||
{
|
||||
QueueNode<TKey, TValue> tail = head.Prev;
|
||||
head.Prev = this;
|
||||
tail.Next = this;
|
||||
Next = head;
|
||||
Prev = tail;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
if (Prev != null && Next != null)
|
||||
{
|
||||
Prev.Next = Next;
|
||||
Next.Prev = Prev;
|
||||
Prev = Next = null;
|
||||
QueueType = QueueType.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a9c1bf1a1e443eaaf17b46fe6b29277
|
||||
timeCreated: 1697174054
|
@@ -1,4 +1,5 @@
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -85,6 +86,11 @@ namespace TEngine
|
||||
/// <remarks>优先级较高的模块会优先轮询,并且关闭操作会后进行。</remarks>
|
||||
internal override int Priority => 4;
|
||||
|
||||
/// <summary>
|
||||
/// 资源缓存表容量。
|
||||
/// </summary>
|
||||
public int ARCTableCapacity { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
@@ -96,10 +102,45 @@ namespace TEngine
|
||||
|
||||
internal override void Shutdown()
|
||||
{
|
||||
YooAssets.Destroy();
|
||||
ReleaseAllHandle();
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
ResourcePool.Destroy();
|
||||
}
|
||||
|
||||
private void ReleaseAllHandle()
|
||||
{
|
||||
var iter = _releaseMaps.Values.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
AssetOperationHandle handle = iter.Current;
|
||||
if (handle != null)
|
||||
{
|
||||
handle.Dispose();
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
iter.Dispose();
|
||||
_releaseMaps.Clear();
|
||||
|
||||
iter = _operationHandlesMaps.Values.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
AssetOperationHandle handle = iter.Current;
|
||||
if (handle != null)
|
||||
{
|
||||
handle.Dispose();
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
iter.Dispose();
|
||||
_operationHandlesMaps.Clear();
|
||||
_arcCacheTable = new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 设置接口
|
||||
@@ -134,6 +175,87 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
private Dictionary<string, AssetOperationHandle> _releaseMaps;
|
||||
|
||||
private Dictionary<string, AssetOperationHandle> _operationHandlesMaps;
|
||||
|
||||
private ArcCacheTable<string, AssetOperationHandle> _arcCacheTable;
|
||||
|
||||
|
||||
private void OnAddAsset(string location, AssetOperationHandle handle)
|
||||
{
|
||||
_operationHandlesMaps[location] = handle;
|
||||
if (_releaseMaps.ContainsKey(location))
|
||||
{
|
||||
_releaseMaps.Remove(location);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemoveAsset(string location, AssetOperationHandle handle)
|
||||
{
|
||||
if (_operationHandlesMaps.ContainsKey(location))
|
||||
{
|
||||
_operationHandlesMaps.Remove(location);
|
||||
}
|
||||
|
||||
_releaseMaps[location] = handle;
|
||||
GameModule.Resource.UnloadUnusedAssets(performGCCollect: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从缓存中获取同步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleSync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
|
||||
if (handle == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
}
|
||||
|
||||
// 对象推入ARC缓存表。
|
||||
_arcCacheTable.PutCache(location, handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从缓存中获取异步资源句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源句柄。</returns>
|
||||
private AssetOperationHandle GetHandleAsync<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
if (!needCache)
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
AssetOperationHandle handle = null;
|
||||
// 尝试从从ARC缓存表取出对象。
|
||||
handle = _arcCacheTable.GetCache(location);
|
||||
|
||||
if (handle == null)
|
||||
{
|
||||
handle = YooAssets.LoadAssetAsync<T>(location);
|
||||
}
|
||||
|
||||
// 对象推入ARC缓存表。
|
||||
_arcCacheTable.PutCache(location, handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源模块。
|
||||
/// </summary>
|
||||
@@ -154,6 +276,10 @@ namespace TEngine
|
||||
}
|
||||
|
||||
ResourcePool.Initialize(GameModule.Get<ResourceModule>().gameObject);
|
||||
|
||||
_releaseMaps ??= new Dictionary<string, AssetOperationHandle>(ARCTableCapacity);
|
||||
_operationHandlesMaps ??= new Dictionary<string, AssetOperationHandle>(ARCTableCapacity);
|
||||
_arcCacheTable ??= new ArcCacheTable<string, AssetOperationHandle>(ARCTableCapacity, OnAddAsset, OnRemoveAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -209,7 +335,7 @@ namespace TEngine
|
||||
createParameters.RemoteServices = new RemoteServices();
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
|
||||
// WebGL运行模式
|
||||
if (playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
@@ -239,6 +365,20 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public void UnloadUnusedAssets()
|
||||
{
|
||||
var iter = _releaseMaps.Values.GetEnumerator();
|
||||
while (iter.MoveNext())
|
||||
{
|
||||
AssetOperationHandle handle = iter.Current;
|
||||
if (handle != null)
|
||||
{
|
||||
handle.Dispose();
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
iter.Dispose();
|
||||
_releaseMaps.Clear();
|
||||
|
||||
if (DefaultPackage == null)
|
||||
{
|
||||
throw new GameFrameworkException("Package is invalid.");
|
||||
@@ -370,9 +510,11 @@ namespace TEngine
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location) where T : Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -380,20 +522,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
AssetReference.BindAssetReference(ret, handle, location);
|
||||
return ret as T;
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -401,9 +550,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -411,20 +562,27 @@ namespace TEngine
|
||||
return default;
|
||||
}
|
||||
|
||||
AssetOperationHandle handle = YooAssets.LoadAssetSync<T>(location);
|
||||
AssetOperationHandle handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
AssetReference.BindAssetReference(ret, handle, location);
|
||||
return ret as T;
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
T ret = handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -432,12 +590,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
Log.Error("Asset name is invalid.");
|
||||
@@ -446,13 +604,20 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -460,12 +625,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : Object
|
||||
{
|
||||
handle = YooAssets.LoadAssetSync<T>(location);
|
||||
handle = GetHandleSync<T>(location, needCache);
|
||||
|
||||
if (string.IsNullOrEmpty(location))
|
||||
{
|
||||
@@ -475,35 +641,44 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync(parent);
|
||||
return ret as T;
|
||||
GameObject gameObject = handle.InstantiateSync(parent);
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return YooAssets.LoadAssetSync<T>(location);
|
||||
return GetHandleSync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : Object
|
||||
{
|
||||
return YooAssets.LoadAssetAsync<T>(location);
|
||||
return GetHandleAsync<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -535,6 +710,22 @@ namespace TEngine
|
||||
return YooAssets.LoadSubAssetsSync(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object
|
||||
{
|
||||
LoadAssetsByTagOperation<T> operation = new LoadAssetsByTagOperation<T>(assetTag);
|
||||
YooAssets.StartOperation(operation);
|
||||
await operation.ToUniTask();
|
||||
List<T> assetObjects = operation.AssetObjects;
|
||||
operation.ReleaseHandle();
|
||||
return assetObjects;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景。
|
||||
/// </summary>
|
||||
@@ -569,10 +760,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : Object
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -583,16 +776,23 @@ namespace TEngine
|
||||
|
||||
if (typeof(T) == typeof(GameObject))
|
||||
{
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
|
||||
AssetReference.BindAssetReference(ret, handle, location);
|
||||
|
||||
return ret as T;
|
||||
if (needInstance)
|
||||
{
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject as T;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
T ret = handle.AssetObject as T;
|
||||
if (!needCache)
|
||||
{
|
||||
return handle.AssetObject as T;
|
||||
handle.Dispose();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -600,10 +800,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location);
|
||||
AssetOperationHandle handle = LoadAssetAsyncHandle<GameObject>(location, needCache);
|
||||
|
||||
bool cancelOrFailed = await handle.ToUniTask().AttachExternalCancellation(cancellationToken).SuppressCancellationThrow();
|
||||
|
||||
@@ -612,11 +813,12 @@ namespace TEngine
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject ret = handle.InstantiateSync();
|
||||
|
||||
AssetReference.BindAssetReference(ret, handle, location);
|
||||
|
||||
return ret;
|
||||
GameObject gameObject = handle.InstantiateSync();
|
||||
if (!needCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(gameObject, handle, location);
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -625,10 +827,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken);
|
||||
GameObject gameObject = await LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
if (parent != null)
|
||||
{
|
||||
gameObject.transform.SetParent(parent);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
@@ -97,6 +98,11 @@ namespace TEngine
|
||||
public int downloadingMaxNum = 3;
|
||||
public int failedTryAgain = 3;
|
||||
|
||||
/// <summary>
|
||||
/// 资源缓存表容量。
|
||||
/// </summary>
|
||||
public int adaptiveReplacementCacheCapacity = 32;
|
||||
|
||||
private IResourceManager m_ResourceManager;
|
||||
private AsyncOperation m_AsyncOperation = null;
|
||||
private bool m_ForceUnloadUnusedAssets = false;
|
||||
@@ -213,6 +219,7 @@ namespace TEngine
|
||||
m_ResourceManager.PlayMode = playMode;
|
||||
m_ResourceManager.VerifyLevel = verifyLevel;
|
||||
m_ResourceManager.Milliseconds = milliseconds;
|
||||
m_ResourceManager.ARCTableCapacity = adaptiveReplacementCacheCapacity;
|
||||
m_ResourceManager.Initialize();
|
||||
Log.Info($"ResourceModule Run Mode:{playMode}");
|
||||
if (playMode == EPlayMode.EditorSimulateMode && !m_InitPackageByProcedure)
|
||||
@@ -293,10 +300,28 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public void ClearSandbox()
|
||||
{
|
||||
// TODO
|
||||
// YooAssets.ClearSandbox();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源。
|
||||
/// </summary>
|
||||
/// <param name="asset">要卸载的资源。</param>
|
||||
public void UnloadAsset(object asset)
|
||||
{
|
||||
m_ResourceManager.UnloadAsset(asset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预订执行释放未被使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="performGCCollect">是否使用垃圾回收。</param>
|
||||
public void UnloadUnusedAssets(bool performGCCollect)
|
||||
{
|
||||
m_PreorderUnloadUnusedAssets = true;
|
||||
m_PerformGCCollect = performGCCollect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制执行释放未被使用的资源。
|
||||
/// </summary>
|
||||
@@ -316,8 +341,10 @@ namespace TEngine
|
||||
private void Update()
|
||||
{
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds += GameTime.unscaledDeltaTime;
|
||||
if (m_AsyncOperation == null && (m_ForceUnloadUnusedAssets || m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval ||
|
||||
m_PreorderUnloadUnusedAssets && m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval))
|
||||
if (m_AsyncOperation == null &&
|
||||
(m_ForceUnloadUnusedAssets ||
|
||||
m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval ||
|
||||
m_PreorderUnloadUnusedAssets && m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval))
|
||||
{
|
||||
Log.Info("Unload unused assets...");
|
||||
m_ForceUnloadUnusedAssets = false;
|
||||
@@ -421,11 +448,13 @@ namespace TEngine
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location);
|
||||
return m_ResourceManager.LoadAsset<T>(location, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -433,11 +462,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -445,11 +476,12 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -458,11 +490,12 @@ namespace TEngine
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle) where T : UnityEngine.Object
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -470,10 +503,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="callback">回调函数。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null) where T : UnityEngine.Object
|
||||
public void LoadAssetAsync<T>(string location, Action<AssetOperationHandle> callback = null, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
AssetOperationHandle handle = m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
|
||||
handle.Completed += callback;
|
||||
}
|
||||
@@ -482,22 +516,24 @@ namespace TEngine
|
||||
/// 同步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>同步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetGetOperation<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location);
|
||||
return m_ResourceManager.LoadAssetGetOperation<T>(location, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源并获取句柄。
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步加载资源句柄。</returns>
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location) where T : UnityEngine.Object
|
||||
public AssetOperationHandle LoadAssetAsyncHandle<T>(string location, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location);
|
||||
return m_ResourceManager.LoadAssetAsyncHandle<T>(location, needCache);
|
||||
}
|
||||
|
||||
|
||||
@@ -537,6 +573,17 @@ namespace TEngine
|
||||
return m_ResourceManager.LoadSubAssetsSync(assetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过Tag加载资源对象集合。
|
||||
/// </summary>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <typeparam name="T">资源类型。</typeparam>
|
||||
/// <returns>资源对象集合。</returns>
|
||||
public async UniTask<List<T>> LoadAssetsByTagAsync<T>(string assetTag) where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetsByTagAsync<T>(assetTag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载场景。
|
||||
/// </summary>
|
||||
@@ -570,11 +617,13 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needInstance">是否需要实例化。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default) where T : UnityEngine.Object
|
||||
public async UniTask<T> LoadAssetAsync<T>(string location, CancellationToken cancellationToken = default, bool needInstance = true, bool needCache = false) where T : UnityEngine.Object
|
||||
{
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadAssetAsync<T>(location, cancellationToken, needInstance, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -582,10 +631,11 @@ namespace TEngine
|
||||
/// </summary>
|
||||
/// <param name="location">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -594,10 +644,11 @@ namespace TEngine
|
||||
/// <param name="location">资源定位地址。</param>
|
||||
/// <param name="parent">父节点位置。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <param name="needCache">是否需要缓存。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default)
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string location, Transform parent, CancellationToken cancellationToken = default, bool needCache = false)
|
||||
{
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken);
|
||||
return await m_ResourceManager.LoadGameObjectAsync(location, parent, cancellationToken, needCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -73,11 +73,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public AssetOperationHandle Handle { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源引用数据。
|
||||
/// </summary>
|
||||
public AssetReference AssetReference { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源是否准备完毕。
|
||||
/// </summary>
|
||||
@@ -211,27 +206,27 @@ namespace TEngine
|
||||
|
||||
public void AddUIEvent(int eventType, Action handler)
|
||||
{
|
||||
EventMgr.AddUIEvent(eventType, handler);
|
||||
EventMgr.AddEvent(eventType, handler);
|
||||
}
|
||||
|
||||
protected void AddUIEvent<T>(int eventType, Action<T> handler)
|
||||
{
|
||||
EventMgr.AddUIEvent(eventType, handler);
|
||||
EventMgr.AddEvent(eventType, handler);
|
||||
}
|
||||
|
||||
protected void AddUIEvent<T, U>(int eventType, Action<T, U> handler)
|
||||
{
|
||||
EventMgr.AddUIEvent(eventType, handler);
|
||||
EventMgr.AddEvent(eventType, handler);
|
||||
}
|
||||
|
||||
protected void AddUIEvent<T, U, V>(int eventType, Action<T, U, V> handler)
|
||||
{
|
||||
EventMgr.AddUIEvent(eventType, handler);
|
||||
EventMgr.AddEvent(eventType, handler);
|
||||
}
|
||||
|
||||
protected void AddUIEvent<T, U, V, W>(int eventType, Action<T, U, V, W> handler)
|
||||
{
|
||||
EventMgr.AddUIEvent(eventType, handler);
|
||||
EventMgr.AddEvent(eventType, handler);
|
||||
}
|
||||
|
||||
protected void RemoveAllUIEvent()
|
||||
@@ -316,13 +311,7 @@ namespace TEngine
|
||||
/// <returns>UIWidget实例。</returns>
|
||||
public T CreateWidgetByPath<T>(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new()
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"CreateWidgetByPath Failed => {this}.AssetReference is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject goInst = AssetReference.LoadAsset<GameObject>(assetLocation, parentTrans);
|
||||
GameObject goInst = GameModule.Resource.LoadAsset<GameObject>(assetLocation, parentTrans);
|
||||
return CreateWidget<T>(goInst, visible);
|
||||
}
|
||||
|
||||
@@ -336,13 +325,7 @@ namespace TEngine
|
||||
/// <returns>UIWidget实例。</returns>
|
||||
public async UniTask<T> CreateWidgetByPathAsync<T>(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new()
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"CreateWidgetByPath Failed => {this}.AssetReference is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject goInst = await AssetReference.LoadAssetAsync<GameObject>(assetLocation, gameObject.GetCancellationTokenOnDestroy());
|
||||
GameObject goInst = await GameModule.Resource.LoadAssetAsync<GameObject>(assetLocation, gameObject.GetCancellationTokenOnDestroy());
|
||||
goInst.transform.SetParent(parentTrans);
|
||||
return CreateWidget<T>(goInst, visible);
|
||||
}
|
||||
@@ -531,163 +514,6 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
#region AssetRefrence Methods
|
||||
|
||||
/// <summary>
|
||||
/// 引用资源数据到资源组内。
|
||||
/// </summary>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <returns>是否注册成功。</returns>
|
||||
public bool Reference(AssetOperationHandle handle, string assetTag = "")
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"Reference Failed => {this}.AssetReference is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetReference.Reference(handle, assetTag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 引用资源数据到资源组内。
|
||||
/// </summary>
|
||||
/// <param name="address">资源定位地址。</param>
|
||||
/// <param name="handle">资源操作句柄。</param>
|
||||
/// <param name="assetTag">资源标识。</param>
|
||||
/// <returns>是否注册成功。</returns>
|
||||
public bool Reference(string address, AssetOperationHandle handle, string assetTag = "")
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"Reference Failed => {this}.AssetReference is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetReference.Reference(address, handle, assetTag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从资源组内释放资源数据。
|
||||
/// </summary>
|
||||
/// <param name="assetTag"></param>
|
||||
/// <returns></returns>
|
||||
public bool ReleaseByTag(string assetTag)
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"Release Failed => {this}.AssetReference is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetReference.ReleaseByTag(assetTag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从资源组内释放资源数据。
|
||||
/// </summary>
|
||||
/// <param name="handle"></param>
|
||||
/// <returns></returns>
|
||||
public bool Release(AssetOperationHandle handle)
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"Release Failed => {this}.AssetReference is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetReference.Release(handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从资源组内释放资源数据。
|
||||
/// </summary>
|
||||
/// <param name="address">资源定位地址。</param>
|
||||
/// <returns>是否释放成功。</returns>
|
||||
public bool Release(string address)
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"Release Failed => {this}.AssetReference is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return AssetReference.Release(address);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName) where T : UnityEngine.Object
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"LoadAsset Failed => {this}.AssetReference is null");
|
||||
return default;
|
||||
}
|
||||
|
||||
return AssetReference.LoadAsset<T>(assetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载资源的名称。</param>
|
||||
/// <param name="parentTrans">父节点位置。</param>
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>资源实例。</returns>
|
||||
public T LoadAsset<T>(string assetName, Transform parentTrans) where T : UnityEngine.Object
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"LoadAsset Failed => {this}.AssetReference is null");
|
||||
return default;
|
||||
}
|
||||
|
||||
return AssetReference.LoadAsset<T>(assetName, parentTrans);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源实例。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的实例名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>资源实实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(string assetName, CancellationToken cancellationToken)
|
||||
where T : UnityEngine.Object
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"LoadAssetAsync Failed => {this}.AssetReference is null");
|
||||
return default;
|
||||
}
|
||||
|
||||
return await AssetReference.LoadAssetAsync<T>(assetName, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载游戏物体。
|
||||
/// </summary>
|
||||
/// <param name="assetName">要加载的游戏物体名称。</param>
|
||||
/// <param name="cancellationToken">取消操作Token。</param>
|
||||
/// <returns>异步游戏物体实例。</returns>
|
||||
public async UniTask<GameObject> LoadGameObjectAsync(string assetName, CancellationToken cancellationToken)
|
||||
{
|
||||
if (AssetReference == null)
|
||||
{
|
||||
Log.Fatal($"LoadAssetAsync Failed => {this}.AssetReference is null");
|
||||
return default;
|
||||
}
|
||||
|
||||
return await AssetReference.LoadGameObjectAsync(assetName, cancellationToken);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UIElement
|
||||
|
||||
/// <summary>
|
||||
|
@@ -400,7 +400,7 @@ namespace TEngine
|
||||
throw new Exception($"Window {type.FullName} not found {nameof(WindowAttribute)} attribute.");
|
||||
|
||||
string assetName = string.IsNullOrEmpty(attribute.Location) ? type.Name : attribute.Location;
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources);
|
||||
window.Init(type.FullName, attribute.WindowLayer, attribute.FullScreen, assetName, attribute.FromResources, attribute.NeedCache);
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@@ -149,7 +149,7 @@ namespace TEngine
|
||||
/// <returns></returns>
|
||||
public bool CreateByPath(string resPath, UIBase parentUI, Transform parentTrans = null, bool visible = true)
|
||||
{
|
||||
GameObject goInst = parentUI.AssetReference.LoadAsset<GameObject>(resPath, parentTrans);
|
||||
GameObject goInst = GameModule.Resource.LoadAsset<GameObject>(resPath, parentTrans);
|
||||
if (goInst == null)
|
||||
{
|
||||
return false;
|
||||
@@ -191,11 +191,6 @@ namespace TEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AssetReference == null)
|
||||
{
|
||||
AssetReference = AssetReference.BindAssetReference(widgetRoot, parent: parentUI.AssetReference);
|
||||
}
|
||||
|
||||
RestChildCanvas(parentUI);
|
||||
parent = parentUI;
|
||||
Parent.ListChild.Add(this);
|
||||
@@ -203,6 +198,7 @@ namespace TEngine
|
||||
BindMemberProperty();
|
||||
RegisterEvent();
|
||||
OnCreate();
|
||||
OnRefresh();
|
||||
IsPrepare = true;
|
||||
|
||||
if (!visible)
|
||||
@@ -269,14 +265,6 @@ namespace TEngine
|
||||
uiChild.OnDestroyWidget();
|
||||
}
|
||||
|
||||
if (Handle != null)
|
||||
{
|
||||
if (AssetReference != null && AssetReference.Parent != null)
|
||||
{
|
||||
AssetReference.Parent.Release(Handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (gameObject != null)
|
||||
{
|
||||
Object.Destroy(gameObject);
|
||||
|
@@ -66,6 +66,11 @@ namespace TEngine
|
||||
/// 是内部资源无需AB加载。
|
||||
/// </summary>
|
||||
public bool FromResources { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要缓存。
|
||||
/// </summary>
|
||||
public bool NeedCache { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义数据。
|
||||
@@ -221,13 +226,14 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources)
|
||||
public void Init(string name, int layer, bool fullScreen, string assetName, bool fromResources, bool needCache = false)
|
||||
{
|
||||
WindowName = name;
|
||||
WindowLayer = layer;
|
||||
FullScreen = fullScreen;
|
||||
AssetName = assetName;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
internal void TryInvoke(System.Action<UIWindow> prepareCallback, System.Object[] userDatas)
|
||||
@@ -245,17 +251,11 @@ namespace TEngine
|
||||
|
||||
internal void InternalLoad(string location, System.Action<UIWindow> prepareCallback, System.Object[] userDatas)
|
||||
{
|
||||
if (Handle != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_prepareCallback = prepareCallback;
|
||||
this.userDatas = userDatas;
|
||||
if (!FromResources)
|
||||
{
|
||||
Handle = YooAssets.LoadAssetAsync<GameObject>(location);
|
||||
Handle.Completed += Handle_Completed;
|
||||
GameModule.Resource.LoadAssetAsync<GameObject>(location, Handle_Completed, needCache: NeedCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -369,13 +369,6 @@ namespace TEngine
|
||||
// 注销回调函数
|
||||
_prepareCallback = null;
|
||||
|
||||
// 卸载面板资源
|
||||
if (Handle != null)
|
||||
{
|
||||
Handle.Release();
|
||||
Handle = null;
|
||||
}
|
||||
|
||||
OnDestroy();
|
||||
|
||||
// 销毁面板对象
|
||||
@@ -393,13 +386,22 @@ namespace TEngine
|
||||
/// <exception cref="Exception"></exception>
|
||||
private void Handle_Completed(AssetOperationHandle handle)
|
||||
{
|
||||
if (handle == null)
|
||||
{
|
||||
throw new GameFrameworkException("Load uiWindows failed because AssetOperationHandle is null");
|
||||
}
|
||||
if (handle.AssetObject == null)
|
||||
{
|
||||
return;
|
||||
throw new GameFrameworkException("Load uiWindows Failed because AssetObject is null");
|
||||
}
|
||||
|
||||
Handle = handle;
|
||||
|
||||
// 实例化对象
|
||||
var panel = handle.InstantiateSync(UIModule.UIRootStatic);
|
||||
if (!NeedCache)
|
||||
{
|
||||
AssetReference.BindAssetReference(panel, handle, AssetName);
|
||||
}
|
||||
Handle_Completed(panel);
|
||||
}
|
||||
|
||||
@@ -417,9 +419,6 @@ namespace TEngine
|
||||
_panel = panel;
|
||||
_panel.transform.localPosition = Vector3.zero;
|
||||
|
||||
// 绑定引用
|
||||
AssetReference = AssetReference.BindAssetReference(_panel);
|
||||
|
||||
// 获取组件
|
||||
_canvas = _panel.GetComponent<Canvas>();
|
||||
if (_canvas == null)
|
||||
|
@@ -37,31 +37,41 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public readonly bool FromResources;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false)
|
||||
/// <summary>
|
||||
/// 需要缓存。
|
||||
/// <remarks>关闭界面不立刻释放资源。</remarks>
|
||||
/// </summary>
|
||||
public readonly bool NeedCache;
|
||||
|
||||
public WindowAttribute(int windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, string location = "", bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
Location = location;
|
||||
FullScreen = fullScreen;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false)
|
||||
public WindowAttribute(UILayer windowLayer, bool fromResources, string location, bool fullScreen = false,bool needCache = false)
|
||||
{
|
||||
WindowLayer = (int)windowLayer;
|
||||
FromResources = fromResources;
|
||||
Location = location;
|
||||
NeedCache = needCache;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.ide.rider": "3.0.24",
|
||||
"com.unity.ide.visualstudio": "2.0.18",
|
||||
"com.unity.memoryprofiler": "0.7.1-preview.1",
|
||||
"com.unity.nuget.newtonsoft-json": "3.0.2",
|
||||
"com.unity.render-pipelines.universal": "12.1.10",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
|
@@ -5,7 +5,7 @@
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "b024a18ba16cccb7ac3c72cf3ce272ef025eb5e4"
|
||||
"hash": "216d09f7b65fadc5d8fcd0bba82e5ac50ca58f06"
|
||||
},
|
||||
"com.cysharp.unitask": {
|
||||
"version": "file:UniTask",
|
||||
@@ -45,6 +45,13 @@
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.editorcoroutines": {
|
||||
"version": "1.0.0",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ext.nunit": {
|
||||
"version": "1.0.6",
|
||||
"depth": 1,
|
||||
@@ -77,6 +84,15 @@
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.memoryprofiler": {
|
||||
"version": "0.7.1-preview.1",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.editorcoroutines": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.nuget.newtonsoft-json": {
|
||||
"version": "3.0.2",
|
||||
"depth": 0,
|
||||
|
@@ -206,7 +206,7 @@ QualitySettings:
|
||||
softVegetation: 1
|
||||
realtimeReflectionProbes: 1
|
||||
billboardsFaceCameraPosition: 1
|
||||
vSyncCount: 1
|
||||
vSyncCount: 0
|
||||
lodBias: 2
|
||||
maximumLODLevel: 0
|
||||
streamingMipmapsActive: 0
|
||||
|
Reference in New Issue
Block a user