using System.Collections; using System.Collections.Generic; using UnityEngine; /******************************************************************************** *Create By CG *Function 屏幕显示帧数 *********************************************************************************/ namespace ZXK.UTility { public class FPSCheckShow : MonoBehaviour { public float updateInterval = 0.5F; private float accum = 0; private int frames = 0; private float timeleft; private string stringFps; void Start() { timeleft = updateInterval; } void Update() { timeleft -= Time.deltaTime; accum += Time.timeScale / Time.deltaTime; ++frames; if (timeleft <= 0.0) { float fps = accum / frames; string format = System.String.Format("FPS:{0:F3}", fps); stringFps = format; timeleft = updateInterval; accum = 0.0F; frames = 0; } } void OnGUI() { GUIStyle guiStyle = GUIStyle.none; guiStyle.fontSize = 40; guiStyle.normal.textColor = Color.red; guiStyle.alignment = TextAnchor.UpperLeft; Rect rt = new Rect(0, 0, 100, 100); GUI.Label(rt, stringFps, guiStyle); } } }