Sweep over 48 files (Editor/ excluded): remove comments that restate the code, condense class summaries, fix three stale doc statements (HsvColorPicker alpha bar, PaintHud layoutPrefab, MasterVolume FallbackDefault). Inline two single-use wrappers (IsPointerOverUi, BuildModes), drop an unused using, replace a magic literal with the existing ParallaxBase constant, and convert ~10 UnityEngine.Object null checks to the implicit-bool convention. No serialized fields, signatures, RPC/NetworkVariable names, defaults, or #if blocks touched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Caps the frame rate via <see cref="Application.targetFrameRate"/>. VSync is
|
|
/// disabled automatically while limiting, because it would otherwise override
|
|
/// targetFrameRate. Changes apply live (also in Play mode) via OnValidate.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
public class FrameRateLimiter : MonoBehaviour
|
|
{
|
|
[Header("Limit")]
|
|
[Tooltip("Cap the frame rate to 'Target FPS' (off = unlimited).")]
|
|
public bool limitFrameRate = true;
|
|
|
|
[Tooltip("Target frame rate when the limit is active.")]
|
|
[Range(1, 360)]
|
|
public int targetFps = 60;
|
|
|
|
[Header("VSync")]
|
|
[Tooltip("Disable VSync while limiting (VSync would otherwise override the FPS limit). Normally ON.")]
|
|
public bool disableVSyncWhenLimiting = true;
|
|
|
|
[Tooltip("VSync count when no limit is active (0 = off, 1 = every refresh, 2 = every second refresh).")]
|
|
[Range(0, 2)]
|
|
public int vSyncCountWhenUnlimited = 0;
|
|
|
|
void OnEnable() => Apply();
|
|
|
|
void OnValidate()
|
|
{
|
|
if (Application.isPlaying)
|
|
Apply();
|
|
}
|
|
|
|
public void Apply()
|
|
{
|
|
if (limitFrameRate)
|
|
{
|
|
if (disableVSyncWhenLimiting)
|
|
QualitySettings.vSyncCount = 0;
|
|
|
|
Application.targetFrameRate = Mathf.Max(1, targetFps);
|
|
}
|
|
else
|
|
{
|
|
QualitySettings.vSyncCount = vSyncCountWhenUnlimited;
|
|
Application.targetFrameRate = -1;
|
|
}
|
|
}
|
|
|
|
/// <summary>Enable/disable the limit (e.g. for UI buttons).</summary>
|
|
public void SetLimitEnabled(bool enabled)
|
|
{
|
|
limitFrameRate = enabled;
|
|
Apply();
|
|
}
|
|
|
|
/// <summary>Set the target FPS and enable the limit (e.g. for UI sliders).</summary>
|
|
public void SetTargetFps(int fps)
|
|
{
|
|
targetFps = Mathf.Max(1, fps);
|
|
limitFrameRate = true;
|
|
Apply();
|
|
}
|
|
}
|