/**************************************************** 文件:FPS.cs 作者:陶长春 邮箱:376248129@qq.com 日期:2025年3月12日 6:03:14 UnityVersion: 2021.3.13f1 功能:FPS工具类 *****************************************************/ using TFramework; using System.Collections.Generic; using UnityEngine; public class FPS { private float _lastTime = 0f; private int _fpsCount = 0; public TAction onUpdateFPS; /// /// 当前帧率 /// public float CurrentFPS { get; private set; } public FPS() { Main.Instance.onUpdate += Update; } private void Update() { float time = Time.realtimeSinceStartup - _lastTime; _fpsCount += 1; if (time > 1) { CurrentFPS = _fpsCount / time; _fpsCount = 0; _lastTime = Time.realtimeSinceStartup; onUpdateFPS?.Invoke(CurrentFPS); } } }