FPS的Log代码

来源:互联网 发布:眼皮抽脂的危害知乎 编辑:程序博客网 时间:2024/05/17 02:39
FPS是图像领域中的定义,是指画面每秒传输帧数,通俗来讲就是指动画或视频的画面数。FPS是测量用于保存、显示动态视频的信息数量。每秒钟帧数愈多,所显示的动作就会愈流畅。通常,要避免动作不流畅的最低是30。某些计算机视频格式,每秒只能提供15帧。
FPS”也可以理解为我们常说的“刷新率(单位为Hz)”,例如我们常在CS游戏里说的“FPS值”。我们在装机选购显卡和显示器的时候,都会注意到“刷新率”。一般我们设置缺省刷新率都在75Hz(即75帧/秒)以上。例如:75Hz的刷新率刷也就是指屏幕一秒内只扫描75次,即75帧/秒。而当刷新率太低时我们肉眼都能感觉到屏幕的闪烁,不连贯,对图像显示效果和视觉感观产生不好的影响。
FPS.cs
using UnityEngine;using System.Collections;public class FPS : MonoBehaviour {public float f_updatInterval = 0.3f;private float f_LastInterval;private int i_Frames =0;private float f_Fps;void Start () {f_LastInterval = Time.realtimeSinceStartup;i_Frames = 0;}// Update is called once per framevoid Update () {++i_Frames;if (Time.realtimeSinceStartup > f_LastInterval + f_updatInterval) {f_Fps = i_Frames / (Time.realtimeSinceStartup - f_LastInterval);i_Frames = 0;f_LastInterval = Time.realtimeSinceStartup;}}void OnGUI(){GUI.Label (new Rect(0,100,200,200),"FPS"+ f_Fps.ToString("f2"));}}

ShowFPS.cs
using UnityEngine;using System.Collections;public class ShowFPS : MonoBehaviour{float deltaTime = 0.0f;void Update(){    deltaTime += (Time.deltaTime - deltaTime) * 0.1f;}void OnGUI(){int w = Screen.width;int h = Screen.height;GUIStyle style = new GUIStyle ();Rect rect = new Rect (0, 0, 100, 50);style.alignment = TextAnchor.UpperLeft;style.normal.textColor = new Color (0.0f, 0.0f, 0.5f,1.0f);float msec = deltaTime * 1000.0f;float fps = 1.0f / deltaTime;string text = string.Format ("{0:0.0}ms({1:0})fps",msec,fps);GUI.Label (rect,text,style);}}

每秒刷新60帧,手机帧频可以到理想状态。

0 0
原创粉丝点击