-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfilerUI.cs
More file actions
116 lines (104 loc) · 4.91 KB
/
ProfilerUI.cs
File metadata and controls
116 lines (104 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using UnityEngine;
using TMPro;
using Sirenix.OdinInspector; // Import TextMeshPro namespace
using UnityEngine.UI;
namespace BytesOne.Profiler
{
public class ProfilerUI : MonoBehaviour
{
public Transform profilerCanvas;
public Button btnToggleProfiler;
[Title("System Profiler")]
public TextMeshProUGUI osText;
public TextMeshProUGUI deviceModelText;
public TextMeshProUGUI processorTypeText;
public TextMeshProUGUI processorCountText;
public TextMeshProUGUI graphicsDeviceNameText;
public TextMeshProUGUI graphicsDeviceVendorText;
public TextMeshProUGUI graphicsDeviceVersionText;
public TextMeshProUGUI fpsText;
public TextMeshProUGUI averageFpsText;
public TextMeshProUGUI renderTimeText;
[Title("Memory Profiler")]
public TextMeshProUGUI reservedMemoryText;
public TextMeshProUGUI allocatedMemoryText;
public TextMeshProUGUI managedHeapMemoryText;
public TextMeshProUGUI managedUsedMemoryText;
public TextMeshProUGUI graphicsDriverMemoryText;
[Title("Rendering Profiler")]
public TextMeshProUGUI setPassCallsText;
public TextMeshProUGUI drawCallsText;
public TextMeshProUGUI batchesText;
public TextMeshProUGUI trianglesText;
public TextMeshProUGUI verticesText;
private SystemProfiler systemProfiler;
private MemoryProfiler memoryProfiler;
private RenderingProfiler renderingProfiler;
void Start()
{
if (btnToggleProfiler)
{
btnToggleProfiler.onClick.AddListener(() =>
{
if (profilerCanvas)
{
profilerCanvas.gameObject.SetActive(!profilerCanvas.gameObject.activeSelf);
}
});
}
systemProfiler = FindObjectOfType<SystemProfiler>();
memoryProfiler = FindObjectOfType<MemoryProfiler>();
renderingProfiler = FindObjectOfType<RenderingProfiler>();
if (systemProfiler == null)
{
Debug.LogError("SystemProfiler component not found in the scene.");
//enabled = false;
}
if (memoryProfiler == null)
{
Debug.LogError("MemoryProfiler component not found in the scene.");
//enabled = false;
}
if (renderingProfiler == null)
{
Debug.LogError("RenderingProfiler component not found in the scene.");
//enabled = false;
}
if (systemProfiler != null)
{
osText.text = $"OS: {systemProfiler.OS}";
deviceModelText.text = $"Device: {systemProfiler.DeviceModel}";
processorTypeText.text = $"CPU: {systemProfiler.ProcessorType}";
processorCountText.text = $"Cores: {systemProfiler.ProcessorCount}";
graphicsDeviceNameText.text = $"GPU: {systemProfiler.GraphicsDeviceName}";
graphicsDeviceVendorText.text = $"GPU Vendor: {systemProfiler.GraphicsDeviceVendor}";
graphicsDeviceVersionText.text = $"GPU Version: {systemProfiler.GraphicsDeviceVersion}";
}
}
void Update()
{
if (systemProfiler != null)
{
fpsText.text = $"FPS: {Mathf.RoundToInt(systemProfiler.FPS)}";
averageFpsText.text = $"Avg FPS: {Mathf.RoundToInt(systemProfiler.AverageFPS)}";
renderTimeText.text = $"Render: {systemProfiler.RenderTime:F2} ms";
}
if (memoryProfiler != null)
{
reservedMemoryText.text = $"Reserved: {memoryProfiler.FormatMemorySize(memoryProfiler.ReservedMemory)}";
allocatedMemoryText.text = $"Allocated: {memoryProfiler.FormatMemorySize(memoryProfiler.AllocatedMemory)}";
managedHeapMemoryText.text = $"Heap Size: {memoryProfiler.FormatMemorySize(memoryProfiler.ManagedHeapMemory)}";
managedUsedMemoryText.text = $"Managed Used: {memoryProfiler.FormatMemorySize(memoryProfiler.ManagedUsedMemory)}";
graphicsDriverMemoryText.text = $"GPU: {memoryProfiler.FormatMemorySize(memoryProfiler.GraphicsDriverMemory)}";
}
if (renderingProfiler != null)
{
setPassCallsText.text = $"Set Pass: {renderingProfiler.SetPassCalls}";
drawCallsText.text = $"Draw Calls: {renderingProfiler.DrawCalls}";
batchesText.text = $"Batches: {renderingProfiler.Batches}";
trianglesText.text = $"Triangles: {renderingProfiler.Triangles}";
verticesText.text = $"Vertices: {renderingProfiler.Vertices}";
}
}
}
}