$运行时输出drawcall、顶点数量。 $
https://docs.unity3d.com/2020.2/Documentation/Manual/ProfilerRendering.html?continueFlag=a795970d585940c1b9ba34c4e7cb6a3e
using System.Text;
using Unity.Profiling;
using UnityEngine;
public class RenderStatsScript : MonoBehaviour
{
string statsText;
ProfilerRecorder setPassCallsRecorder;
ProfilerRecorder drawCallsRecorder;
ProfilerRecorder verticesRecorder;
void OnEnable()
{
setPassCallsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "SetPass Calls Count");
drawCallsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Draw Calls Count");
verticesRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Vertices Count");
}
void OnDisable()
{
setPassCallsRecorder.Dispose();
drawCallsRecorder.Dispose();
verticesRecorder.Dispose();
}
void Update()
{
var sb = new StringBuilder(500);
if (setPassCallsRecorder.Valid)
sb.AppendLine($"SetPass Calls: {setPassCallsRecorder.LastValue}");
if (drawCallsRecorder.Valid)
sb.AppendLine($"Draw Calls: {drawCallsRecorder.LastValue}");
if (verticesRecorder.Valid)
sb.AppendLine($"Vertices: {verticesRecorder.LastValue}");
statsText = sb.ToString();
}
void OnGUI()
{
GUI.TextArea(new Rect(10, 30, 250, 50), statsText);
}
}