当前位置:网站首页>Unity 3D frame rate statistics script
Unity 3D frame rate statistics script
2022-07-24 06:14:00 【A small EZ】
Share a practical Unity3D Frame rate statistics script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FrameCounter : MonoBehaviour
{
// Attach this to a GUIText to make a frames/second indicator.
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
// It is also fairly accurate at very low FPS counts (<10).
// We do this not by simply counting frames per interval, but
// by accumulating FPS for each frame. This way we end up with
// correct overall FPS even if the interval renders something like
// 5.5f frames.
#region Field
float updateInterval = 1.0f;
private float accum = 0.0f; // FPS accumulated over the interval
private float frames = 0; // Frames drawn over the interval
private float timeleft; // Left time for current interval
private float fps = 15.0f; // Current FPS
private float lastSample;
private float gotIntervals = 0;
#endregion
#region attribute
private GUIStyle fontStyle = new GUIStyle();
#endregion
#region Unity Callback function
//private void Awake()
//{
// Application.targetFrameRate = -1;
//}
void Start()
{
fontStyle.normal.background = null; // Set background fill
fontStyle.normal.textColor = Color.white; // Set font color
fontStyle.fontSize = 40;
timeleft = updateInterval;
lastSample = Time.realtimeSinceStartup;
}//Start ()_end
// void Update()
void Update()
{
++frames;
float newSample = Time.realtimeSinceStartup;
float deltaTime = newSample - lastSample;
lastSample = newSample;
timeleft -= deltaTime;
accum += 1.0f / deltaTime;
// Interval ended - update GUI text and start new interval
if (timeleft <= 0.0f)
{
// display two fractional digits (f2 format)
fps = accum / frames;
// guiText.text = fps.ToString("f2");
timeleft = updateInterval;
accum = 0.0f;
frames = 0;
++gotIntervals;
}
//text.text = "FPS:" + fps.ToString("f2");
}//Update ()_end
#endregion
#region Self built method
void OnGUI()
{
GUI.Label(new Rect(0, 50, 200, 200), "FPS:" + fps.ToString("f2"));
}
#endregion
}
边栏推荐
- Thymeleaf quick start learning
- ue4 瞄准偏移
- JUC并发编程基础(4)--线程组和线程优先级
- data normalization
- Write the list to txt and directly remove the comma in the middle
- 什么是单调队列
- What is monotonic queue
- QT novice entry level calculator addition, subtraction, multiplication, division, application
- 不租服务器,自建个人商业网站(3)
- UE4 random generation of items
猜你喜欢

Jupyter notebook select CONDA environment

Use QT to connect to MySQL and create table numbers, write data, and delete data

Machine learning & deep learning introduction information sharing summary

UE4 replacement system 3. Final results

HoloLens 2 开发101:创建首个HoloLens 2应用程序

Xshell remote access tool

ue4 换装系统 2.换装系统的场景捕捉

The detailed process of connecting MySQL with QT and outputting data to QT window tablewidget.

Unicast, multicast, broadcast, tool development, introduction to QT UDP communication protocol development and source code of development tools

UE4: what is the gameplay framework
随机推荐
First knowledge of graphics
UE4: what is the gameplay framework
unity2D游戏之让人物动起来-上
What is monotone stack
Dameng database_ Supported table types, usage, characteristics
Jupyter notebook select CONDA environment
Accurate calculation of time delay detailed explanation of VxWorks timestamp
Hololens 2 development: development environment deployment
Headlong platform operation
Detailed explanation of KMP code distribution
Day3 jvm+ sorting summary
Kernel pwn 基础教程之 Heap Overflow
JUC并发编程基础(7)--多线程锁
unity最新版本的Text(TMP)UI文本怎么显示中文
data normalization
简单却好用:使用Keras 2实现基于LSTM的多维时间序列预测
day1-jvm+leetcode
How does the latest version of text (TMP) UI text of unity display in Chinese
Installation of tensorflow and pytorch frames and CUDA pit records
如何建立一个仪式感点满的网站,并发布到公网 2-2