Traveller/scripts/FpsLabel.cs
Cold-Mint 39ca716e3d
Conduct code reviews.
进行代码审查。
2024-06-05 21:38:45 +08:00

58 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Godot;
namespace ColdMint.scripts;
/// <summary>
/// <para>FPSLabel</para>
/// <para>FPS标签</para>
/// </summary>
public partial class FpsLabel : Label
{
private bool _enable;
private LabelSettings? _labelSettings;
public override void _Ready()
{
Text = null;
//Enabled only in debug mode.
//仅在调试模式启用。
if (Config.IsDebug())
{
_labelSettings = new LabelSettings();
LabelSettings = _labelSettings;
_enable = true;
}
}
public override void _Process(double delta)
{
if (!_enable)
{
return;
}
var fps = Engine.GetFramesPerSecond();
Text = "FPS:" + fps;
if (_labelSettings != null)
{
//Green above 54 frames (smooth)
//在54帧以上为绿色流畅
if (fps > 54)
{
_labelSettings.FontColor = Colors.Green;
}
else if (fps > 48)
{
//Yellow between 48 and 54 frames (Karting)
//在48到54帧之间为黄色卡顿
_labelSettings.FontColor = Colors.Yellow;
}
else
{
//Red below 48 frames (lag)
//在48帧以下为红色
_labelSettings.FontColor = Colors.Red;
}
}
}
}