mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
对象池支持ShutDown
对象池支持ShutDown
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#region Class Documentation
|
#region Class Documentation
|
||||||
|
|
||||||
/************************************************************************************************************
|
/************************************************************************************************************
|
||||||
Class Name: ResourcePool对象池。
|
Class Name: ResourcePool对象池。
|
||||||
Type: Util, Singleton
|
Type: Util, Singleton
|
||||||
@@ -6,16 +7,17 @@ Type: Util, Singleton
|
|||||||
Example:
|
Example:
|
||||||
//注册 - 添加对象池路径,满足这个路径开头的GameObject开启对象池:
|
//注册 - 添加对象池路径,满足这个路径开头的GameObject开启对象池:
|
||||||
ResourceCacheMgr.Instance.RegCacheResPath("Assets/AssetRaw/Effects");
|
ResourceCacheMgr.Instance.RegCacheResPath("Assets/AssetRaw/Effects");
|
||||||
|
|
||||||
//正常引用资源。
|
//正常引用资源。
|
||||||
var obj = await GameModule.Resource.LoadAssetAsync<GameObject>("Sprite",parent:transform);
|
var obj = await GameModule.Resource.LoadAssetAsync<GameObject>("Sprite",parent:transform);
|
||||||
|
|
||||||
//回收资源
|
//回收资源。
|
||||||
GameModule.Resource.FreeGameObject(obj);
|
GameModule.Resource.FreeGameObject(obj);
|
||||||
|
|
||||||
//删除资源 放心资源不存在泄露。
|
//删除资源 放心资源不存在泄露。
|
||||||
Unity Engine.Object。Destroy(obj);
|
Unity Engine.Object。Destroy(obj);
|
||||||
************************************************************************************************************/
|
************************************************************************************************************/
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -85,7 +87,7 @@ namespace TEngine
|
|||||||
|
|
||||||
public void OnDestroy()
|
public void OnDestroy()
|
||||||
{
|
{
|
||||||
FreeAllCacheAndGo();
|
FreeAllCacheAndGo(needDestroy: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCacheGo(string resPath, GameObject go)
|
public void AddCacheGo(string resPath, GameObject go)
|
||||||
@@ -105,6 +107,7 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
return new DelayDestroyGo();
|
return new DelayDestroyGo();
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = _freeDelayNode.Count - 1;
|
int index = _freeDelayNode.Count - 1;
|
||||||
DelayDestroyGo delayDestroyGo = _freeDelayNode[index];
|
DelayDestroyGo delayDestroyGo = _freeDelayNode[index];
|
||||||
_freeDelayNode.RemoveAt(index);
|
_freeDelayNode.RemoveAt(index);
|
||||||
@@ -275,9 +278,9 @@ namespace TEngine
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FreeAllCacheAndGo()
|
public static void FreeAllCacheAndGo(bool needDestroy = true)
|
||||||
{
|
{
|
||||||
ResourcePool.Instance.FreeAllCacheGo();
|
ResourcePool.Instance.FreeAllCacheGo(needDestroy);
|
||||||
ResourceCacheMgr.Instance.RemoveAllCache();
|
ResourceCacheMgr.Instance.RemoveAllCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +289,7 @@ namespace TEngine
|
|||||||
Instance.FreeAllCacheGo();
|
Instance.FreeAllCacheGo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FreeAllCacheGo()
|
public void FreeAllCacheGo(bool needDestroy = true)
|
||||||
{
|
{
|
||||||
using Dictionary<string, GoPoolNode>.Enumerator enumerator = _cacheGo.GetEnumerator();
|
using Dictionary<string, GoPoolNode>.Enumerator enumerator = _cacheGo.GetEnumerator();
|
||||||
while (enumerator.MoveNext())
|
while (enumerator.MoveNext())
|
||||||
@@ -297,8 +300,11 @@ namespace TEngine
|
|||||||
GameObject go = listGo[index];
|
GameObject go = listGo[index];
|
||||||
if (go != null)
|
if (go != null)
|
||||||
{
|
{
|
||||||
go.transform.SetParent(null, false);
|
if (needDestroy)
|
||||||
DoDestroy(go);
|
{
|
||||||
|
go.transform.SetParent(null, false);
|
||||||
|
DoDestroy(go, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,10 +347,13 @@ namespace TEngine
|
|||||||
_goProperty.Remove(hashCode);
|
_goProperty.Remove(hashCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoDestroy(GameObject go)
|
private void DoDestroy(GameObject go, bool needDestroy = true)
|
||||||
{
|
{
|
||||||
RemoveGoProperty(go.GetHashCode());
|
RemoveGoProperty(go.GetHashCode());
|
||||||
Object.Destroy(go);
|
if (needDestroy)
|
||||||
|
{
|
||||||
|
Object.Destroy(go);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsNeedAutoFree(string resPath)
|
public bool IsNeedAutoFree(string resPath)
|
||||||
@@ -499,7 +508,7 @@ namespace TEngine
|
|||||||
CheckPoolCacheFree();
|
CheckPoolCacheFree();
|
||||||
|
|
||||||
LateUpdate();
|
LateUpdate();
|
||||||
|
|
||||||
ResourceCacheMgr.Instance.OnUpdate();
|
ResourceCacheMgr.Instance.OnUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user