TProfile
This commit is contained in:
ALEXTANG
2023-04-10 20:40:19 +08:00
parent 7d9c5eac69
commit 51b2eaf6b4
7 changed files with 93 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ namespace TEngine.Editor
public class ProfilerDefineSymbols
{
private const string EnableFirstProfiler = "FIRST_PROFILER";
private const string EnableDinProFiler = "DIN_PROFILER";
private const string EnableDinProFiler = "T_PROFILER";
private static readonly string[] AllProfilerDefineSymbols = new string[]
{
@@ -16,7 +16,7 @@ namespace TEngine.Editor
/// <summary>
/// 禁用所有日志脚本宏定义。
/// </summary>
[MenuItem("TEngine/Profiler Define Symbols/Disable All Logs", false, 30)]
[MenuItem("TEngine/Profiler Define Symbols/Disable All Profiler", false, 30)]
public static void DisableAllLogs()
{
foreach (string aboveLogScriptingDefineSymbol in AllProfilerDefineSymbols)
@@ -28,7 +28,7 @@ namespace TEngine.Editor
/// <summary>
/// 开启所有日志脚本宏定义。
/// </summary>
[MenuItem("TEngine/Profiler Define Symbols/Enable All Logs", false, 31)]
[MenuItem("TEngine/Profiler Define Symbols/Enable All Profiler", false, 31)]
public static void EnableAllLogs()
{
DisableAllLogs();

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b759e5ec06e84c9d983e71fec5364815
timeCreated: 1681129900

View File

@@ -0,0 +1,67 @@
using System.Diagnostics;
using UnityEngine.Profiling;
namespace TEngine
{
class TProfiler
{
private static int m_profileLevel = -1;
private static int m_currLevel = 0;
private static int m_sampleLevel = 0;
public static void SetProfileLevel(int level)
{
m_profileLevel = level;
}
[Conditional("FIRST_PROFILER")]
public static void BeginFirstSample(string name)
{
m_currLevel++;
if (m_profileLevel >= 0 && m_currLevel > m_profileLevel)
{
return;
}
m_sampleLevel++;
Profiler.BeginSample(name);
}
[Conditional("FIRST_PROFILER")]
public static void EndFirstSample()
{
if (m_currLevel <= m_sampleLevel)
{
Profiler.EndSample();
m_sampleLevel--;
}
m_currLevel--;
}
[Conditional("T_PROFILER")]
public static void BeginSample(string name)
{
m_currLevel++;
if (m_profileLevel >= 0 && m_currLevel > m_profileLevel)
{
return;
}
m_sampleLevel++;
Profiler.BeginSample(name);
}
[Conditional("T_PROFILER")]
public static void EndSample()
{
if (m_currLevel <= m_sampleLevel)
{
Profiler.EndSample();
m_sampleLevel--;
}
m_currLevel--;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f853bc680f948e5aa02d3e47e96a44b
timeCreated: 1681129934

View File

@@ -1,5 +1,8 @@
namespace TEngine
{
/// <summary>
/// UI行为接口。
/// </summary>
public interface IUIBehaviour
{
void ScriptGenerator();

View File

@@ -41,6 +41,11 @@ namespace TEngine
/// UI父节点。
/// </summary>
public UIBase Parent => parent;
/// <summary>
/// 自动逸数据集。
/// </summary>
protected System.Object[] userDatas;
/// <summary>
/// 窗口的实例资源对象。

View File

@@ -11,8 +11,6 @@ namespace TEngine
{
private System.Action<UIWindow> _prepareCallback;
private System.Object[] _userDatas;
private bool _isCreate = false;
private GameObject _panel;
@@ -64,9 +62,9 @@ namespace TEngine
{
get
{
if (_userDatas != null && _userDatas.Length >= 1)
if (userDatas != null && userDatas.Length >= 1)
{
return _userDatas[0];
return userDatas[0];
}
else
{
@@ -78,7 +76,7 @@ namespace TEngine
/// <summary>
/// 自定义数据集。
/// </summary>
public System.Object[] UserDatas => _userDatas;
public System.Object[] UserDatas => userDatas;
/// <summary>
/// 窗口深度值
@@ -219,7 +217,7 @@ namespace TEngine
internal void TryInvoke(System.Action<UIWindow> prepareCallback, System.Object[] userDatas)
{
_userDatas = userDatas;
base.userDatas = userDatas;
if (IsPrepare)
{
prepareCallback?.Invoke(this);
@@ -238,7 +236,7 @@ namespace TEngine
}
_prepareCallback = prepareCallback;
_userDatas = userDatas;
base.userDatas = userDatas;
Handle = YooAssets.LoadAssetAsync<GameObject>(location);
Handle.Completed += Handle_Completed;
}
@@ -296,9 +294,9 @@ namespace TEngine
{
var uiWidget = listChild[i];
UnityEngine.Profiling.Profiler.BeginSample(uiWidget.name);
TProfiler.BeginSample(uiWidget.name);
var needValid = uiWidget.InternalUpdate();
UnityEngine.Profiling.Profiler.EndSample();
TProfiler.EndSample();
if (!updateListValid && needValid)
{
@@ -312,7 +310,7 @@ namespace TEngine
}
}
UnityEngine.Profiling.Profiler.BeginSample("OnUpdate");
TProfiler.BeginSample("OnUpdate");
bool needUpdate = false;
if (listNextUpdateChild == null || listNextUpdateChild.Count <= 0)
@@ -326,7 +324,7 @@ namespace TEngine
OnUpdate();
needUpdate = true;
}
UnityEngine.Profiling.Profiler.EndSample();
TProfiler.EndSample();
return needUpdate;
}