FPS的Log代码

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 frame
	void 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值