mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
ObjectPool
ObjectPool
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using TEngine.Runtime.ObjectPool;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime
|
||||
{
|
||||
public sealed partial class DebuggerComponent
|
||||
{
|
||||
private sealed class ObjectPoolInformationWindow : ScrollableDebuggerWindowBase
|
||||
{
|
||||
private ObjectPoolComponent m_ObjectPoolComponent = null;
|
||||
|
||||
public override void Initialize(params object[] args)
|
||||
{
|
||||
m_ObjectPoolComponent = ObjectPoolComponent.Instance;
|
||||
if (m_ObjectPoolComponent == null)
|
||||
{
|
||||
Log.Fatal("Object pool component is invalid.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDrawScrollableWindow()
|
||||
{
|
||||
GUILayout.Label("<b>Object Pool Information</b>");
|
||||
GUILayout.BeginVertical("box");
|
||||
{
|
||||
DrawItem("Object Pool Count", m_ObjectPoolComponent.Count.ToString());
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
ObjectPoolBase[] objectPools = m_ObjectPoolComponent.GetAllObjectPools(true);
|
||||
for (int i = 0; i < objectPools.Length; i++)
|
||||
{
|
||||
DrawObjectPool(objectPools[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjectPool(ObjectPoolBase objectPool)
|
||||
{
|
||||
GUILayout.Label(Utility.Text.Format("<b>Object Pool: {0}</b>", objectPool.FullName));
|
||||
GUILayout.BeginVertical("box");
|
||||
{
|
||||
DrawItem("Name", objectPool.Name);
|
||||
DrawItem("Type", objectPool.ObjectType.FullName);
|
||||
DrawItem("Auto Release Interval", objectPool.AutoReleaseInterval.ToString());
|
||||
DrawItem("Capacity", objectPool.Capacity.ToString());
|
||||
DrawItem("Used Count", objectPool.Count.ToString());
|
||||
DrawItem("Can Release Count", objectPool.CanReleaseCount.ToString());
|
||||
DrawItem("Expire Time", objectPool.ExpireTime.ToString());
|
||||
DrawItem("Priority", objectPool.Priority.ToString());
|
||||
ObjectInfo[] objectInfos = objectPool.GetAllObjectInfos();
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Label("<b>Name</b>");
|
||||
GUILayout.Label("<b>Locked</b>", GUILayout.Width(60f));
|
||||
GUILayout.Label(objectPool.AllowMultiSpawn ? "<b>Count</b>" : "<b>In Use</b>", GUILayout.Width(60f));
|
||||
GUILayout.Label("<b>Flag</b>", GUILayout.Width(60f));
|
||||
GUILayout.Label("<b>Priority</b>", GUILayout.Width(60f));
|
||||
GUILayout.Label("<b>Last Use Time</b>", GUILayout.Width(120f));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (objectInfos.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < objectInfos.Length; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
GUILayout.Label(string.IsNullOrEmpty(objectInfos[i].Name) ? "<None>" : objectInfos[i].Name);
|
||||
GUILayout.Label(objectInfos[i].Locked.ToString(), GUILayout.Width(60f));
|
||||
GUILayout.Label(objectPool.AllowMultiSpawn ? objectInfos[i].SpawnCount.ToString() : objectInfos[i].IsInUse.ToString(), GUILayout.Width(60f));
|
||||
GUILayout.Label(objectInfos[i].CustomCanReleaseFlag.ToString(), GUILayout.Width(60f));
|
||||
GUILayout.Label(objectInfos[i].Priority.ToString(), GUILayout.Width(60f));
|
||||
GUILayout.Label(objectInfos[i].LastUseTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), GUILayout.Width(120f));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GUILayout.Label("<i>Object Pool is Empty ...</i>");
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84a0c315609844058d56cd62d6ee5d0b
|
||||
timeCreated: 1662467627
|
@@ -34,7 +34,7 @@ namespace TEngine.Runtime
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("TEngine/Debugger")]
|
||||
partial class DebuggerComponent : MonoBehaviour
|
||||
partial class DebuggerComponent : UnitySingleton<DebuggerComponent>
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认调试器漂浮框大小。
|
||||
@@ -147,8 +147,9 @@ namespace TEngine.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
Object.DontDestroyOnLoad(gameObject.transform.parent);
|
||||
m_DebuggerManager = DebuggerManager.Instance;
|
||||
if (m_DebuggerManager == null)
|
||||
@@ -159,7 +160,6 @@ namespace TEngine.Runtime
|
||||
m_FpsCounter = new FpsCounter(0.5f);
|
||||
}
|
||||
|
||||
|
||||
#region Debug系统
|
||||
private SystemInformationWindow m_SystemInformationWindow = new SystemInformationWindow();
|
||||
private EnvironmentInformationWindow m_EnvironmentInformationWindow = new EnvironmentInformationWindow();
|
||||
@@ -187,7 +187,7 @@ namespace TEngine.Runtime
|
||||
private RuntimeMemoryInformationWindow<Font> m_RuntimeMemoryFontInformationWindow = new RuntimeMemoryInformationWindow<Font>();
|
||||
private RuntimeMemoryInformationWindow<TextAsset> m_RuntimeMemoryTextAssetInformationWindow = new RuntimeMemoryInformationWindow<TextAsset>();
|
||||
private RuntimeMemoryInformationWindow<ScriptableObject> m_RuntimeMemoryScriptableObjectInformationWindow = new RuntimeMemoryInformationWindow<ScriptableObject>();
|
||||
|
||||
private ObjectPoolInformationWindow m_ObjectPoolInformationWindow = new ObjectPoolInformationWindow();
|
||||
private MemoryPoolInformationWindow m_MemoryPoolInformationWindow = new MemoryPoolInformationWindow();
|
||||
private NetworkInformationWindow m_NetworkInformationWindow = new NetworkInformationWindow();
|
||||
|
||||
@@ -228,6 +228,7 @@ namespace TEngine.Runtime
|
||||
RegisterDebuggerWindow("Profiler/Memory/TextAsset", m_RuntimeMemoryTextAssetInformationWindow);
|
||||
RegisterDebuggerWindow("Profiler/Memory/ScriptableObject", m_RuntimeMemoryScriptableObjectInformationWindow);
|
||||
|
||||
RegisterDebuggerWindow("Profiler/Object Pool", m_ObjectPoolInformationWindow);
|
||||
RegisterDebuggerWindow("Profiler/Memory Pool", m_MemoryPoolInformationWindow);
|
||||
RegisterDebuggerWindow("Profiler/Network", m_NetworkInformationWindow);
|
||||
|
||||
@@ -264,9 +265,9 @@ namespace TEngine.Runtime
|
||||
m_DebuggerManager.RegisterDebuggerWindow(path, debuggerWindow, args);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
m_FpsCounter.Update(Time.deltaTime, Time.unscaledDeltaTime);
|
||||
m_FpsCounter.Update(elapseSeconds,realElapseSeconds);
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
|
Reference in New Issue
Block a user