Unity3D--游戏帧数【FPS】的显示和查看
2018-03-14 11:20
651 查看
在Unity3.5版本后是可以直接设置帧数FPS ,官方文档:http://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Awake() {
Application.targetFrameRate = 60;
}
}
下面是FPS 显示和查看
using UnityEngine;
public class ShowFPS : MonoBehaviour
{
//更新的时间间隔
public float UpdateInterval = 0.5F;
//最后的时间间隔
private float _lastInterval;
//帧[中间变量 辅助]
private int _frames = 0;
//当前的帧率
private float _fps;
void Start()
{
//Application.targetFrameRate=60;
UpdateInterval = Time.realtimeSinceStartup;
_frames = 0;
}
void OnGUI()
{
GUI.Label(new Rect(100, 100, 200, 200), "FPS:" + _fps.ToString("f2"));
}
void Update()
{
++_frames;
if (Time.realtimeSinceStartup > _lastInterval + UpdateInterval)
{
_fps = _frames / (Time.realtimeSinceStartup - _lastInterval);
_frames = 0;
_lastInterval = Time.realtimeSinceStartup;
}
}
}
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Awake() {
Application.targetFrameRate = 60;
}
}
下面是FPS 显示和查看
using UnityEngine;
public class ShowFPS : MonoBehaviour
{
//更新的时间间隔
public float UpdateInterval = 0.5F;
//最后的时间间隔
private float _lastInterval;
//帧[中间变量 辅助]
private int _frames = 0;
//当前的帧率
private float _fps;
void Start()
{
//Application.targetFrameRate=60;
UpdateInterval = Time.realtimeSinceStartup;
_frames = 0;
}
void OnGUI()
{
GUI.Label(new Rect(100, 100, 200, 200), "FPS:" + _fps.ToString("f2"));
}
void Update()
{
++_frames;
if (Time.realtimeSinceStartup > _lastInterval + UpdateInterval)
{
_fps = _frames / (Time.realtimeSinceStartup - _lastInterval);
_frames = 0;
_lastInterval = Time.realtimeSinceStartup;
}
}
}
相关文章推荐
- 【Unity】查看与显示游戏帧数FPS
- [Unity3D]查看与设置游戏帧数FPS
- [Unity3D]查看与设置游戏帧数FPS
- [Unity3D]查看与设置游戏帧数FPS
- [Unity3D]查看与设置游戏帧数FPS
- [Unity3D]查看与设置游戏帧数FPS
- Unity3D 大型游戏 最后一站 源码 部分重点 显示FPS
- Unity3D实时显示FPS(移动端测试神器)
- Unity3D手机斗地主游戏开发实战(03)_地主牌显示和出牌逻辑(不定期更新中~~~)
- Unity3D设置字体颜色大小,用于游戏分数显示设置等,
- [Unity3D]手机3D游戏开发:使用UnityRemote开发一个简单的FPS案例
- Unity3D手机斗地主游戏开发实战(03)_地主牌显示和出牌逻辑
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(一)----初始化显示的高分榜
- Unity3D FPS帧数修改
- Unity3D FPS帧数修改
- iOS查看屏幕帧数工具--YYFPSLabel
- Unity3d 帧率设置 及在游戏运行时显示帧率
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(九)----使用PreviewLabs插件提速与完整的项目源码
- Android游戏开发测量每秒帧数 Frames Per Second (FPS)
- [Unity3D]手机3D游戏开发:FPS射击游戏中瞄准镜CrossHair的制作