找回密码
 立即注册
查看: 278|回复: 0

【Unity】帧率显示

[复制链接]
发表于 2022-7-6 16:50 | 显示全部楼层 |阅读模式
效果图


image.png

using UnityEngine;using System.Collections;public class FPSDisplay : MonoBehaviour{    private static FPSDisplay instance;    public static FPSDisplay Instance    {        get        {            if (instance == null)            {                GameObject go = new GameObject("[FPSDisplay]");                instance = go.AddComponent<FPSDisplay>();                GameObject.DontDestroyOnLoad(go);                go.hideFlags = HideFlags.HideAndDontSave;            }            return instance;        }    }    public void OnInit()    {    }    float deltaTime = 0.0f;    void Update()    {        deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;    }    void OnGUI()    {        int w = Screen.width, h = Screen.height;        GUIStyle style = new GUIStyle();        Rect rect = new Rect(0, 0, w, h * 2 / 100);        style.alignment = TextAnchor.UpperLeft;        style.fontSize = h * 2 / 100;        //new Color (0.0f, 0.0f, 0.5f, 1.0f);        style.normal.textColor = Color.white;        float msec = deltaTime * 1000.0f;        float fps = 1.0f / deltaTime;        //string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);        string text = string.Format("(fps:{0:0.})", fps);        GUI.Label(rect, text, style);    }}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-22 07:06 , Processed in 0.219786 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表