Delete Unused Ref

Delete Unused Ref
This commit is contained in:
ALEXTANG
2022-05-25 19:59:23 +08:00
parent 9f5af4249a
commit d478617453
4 changed files with 10 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ namespace TEngine
{ {
List<MemPoolBase> m_listPool = new List<MemPoolBase>(); List<MemPoolBase> m_listPool = new List<MemPoolBase>();
[Conditional("TEngine_DEBUG")] [Conditional("UNITY_EDITOR")]
public void ShowCount() public void ShowCount()
{ {
int totalCnt = 0; int totalCnt = 0;

View File

@@ -117,7 +117,6 @@ namespace TEngine
UnloadFalse(); UnloadFalse();
Load(); Load();
} }
} }
/// <summary> /// <summary>

View File

@@ -5,9 +5,6 @@ using UnityEngine.U2D;
namespace TEngine namespace TEngine
{ {
/// <summary>
/// 封装的AssetBundle
/// </summary>
public class AssetData public class AssetData
{ {
private AssetBundleData _refBundle; private AssetBundleData _refBundle;
@@ -56,14 +53,8 @@ namespace TEngine
public string FullPath => _fPath; public string FullPath => _fPath;
/// <summary>
/// Asset名
/// </summary>
public string Name => _name; public string Name => _name;
/// <summary>
/// 异步操作对象
/// </summary>
public AsyncOperation AsyncOp public AsyncOperation AsyncOp
{ {
get get
@@ -111,14 +102,11 @@ namespace TEngine
_fPath = path; _fPath = path;
} }
/// <summary>
/// 增引用计数
/// </summary>
public void AddRef() public void AddRef()
{ {
++_refCount; ++_refCount;
#if UNITY_EDITOR #if UNITY_EDITOR
//TLogger.LogInfo($"Add AssetData {_fPath} _refCount = {_refCount}"); TLogger.LogInfoSuccessd($"Add AssetData {_fPath} _refCount = {_refCount}");
#endif #endif
} }
@@ -129,7 +117,7 @@ namespace TEngine
{ {
--_refCount; --_refCount;
#if UNITY_EDITOR #if UNITY_EDITOR
//TLogger.LogInfo($"Dec AssetData {_fPath} _refCount = {_refCount}"); TLogger.LogInfoSuccessd($"Dec AssetData {_fPath} _refCount = {_refCount}");
#endif #endif
if (_refCount <= 0) if (_refCount <= 0)
{ {
@@ -328,11 +316,15 @@ namespace TEngine
public void LoadScene(LoadSceneMode mode) public void LoadScene(LoadSceneMode mode)
{ {
if (_refBundle != null && _refBundle.Bundle == null) if (_refBundle != null && _refBundle.Bundle == null)
{
_refBundle.Load(); _refBundle.Load();
}
_asyncLoadRequest = SceneManager.LoadSceneAsync(_name, mode); _asyncLoadRequest = SceneManager.LoadSceneAsync(_name, mode);
if (_asyncLoadRequest != null) if (_asyncLoadRequest != null)
{
_asyncLoadRequest.allowSceneActivation = false; _asyncLoadRequest.allowSceneActivation = false;
}
} }
/// <summary> /// <summary>

View File

@@ -2,36 +2,23 @@
namespace TEngine namespace TEngine
{ {
/// <summary>
/// GameObject与AssetData的绑定对象用于管理对AssetData的引用计数
/// </summary>
[DisallowMultipleComponent, AddComponentMenu("")] [DisallowMultipleComponent, AddComponentMenu("")]
public sealed class AssetTag : MonoBehaviour public sealed class AssetTag : MonoBehaviour
{ {
AssetData _assetData; AssetData _assetData;
[SerializeField, HideInInspector] private string _path; [SerializeField, HideInInspector] private string _path;
/// <summary>
/// 对应的资源路径
/// </summary>
public string Path => _path; public string Path => _path;
/// <summary>
/// 缓存池中的归还时间戳
/// </summary>
public float PoolReturnTimestamp { get; set; }
private int _instanceID = 0; private int _instanceID = 0;
private void Awake() private void Awake()
{ {
// 处理Cloned GameObject上引用计数不正确的问题
if (_path != null && (_instanceID == -1 || _instanceID != gameObject.GetInstanceID())) if (_path != null && (_instanceID == -1 || _instanceID != gameObject.GetInstanceID()))
{
Bind(ResMgr.Instance.GetAsset(_path, false)); Bind(ResMgr.Instance.GetAsset(_path, false));
}
} }
/// <summary>
/// GameObject绑定AssetData
/// </summary>
/// <param name="assetData">Asset数据</param>
public void Bind(AssetData assetData) public void Bind(AssetData assetData)
{ {
_assetData = assetData; _assetData = assetData;
@@ -45,5 +32,4 @@ namespace TEngine
_assetData.DecRef(); _assetData.DecRef();
} }
} }
} }