using UnityEngine;
using System.Collections;
namespace Engine.Component
{
/// 统计帧频
public class FPSComponent : BaseComponent
{
/// 当前帧数
private int nFrameCt = 60;
/// 统计时间
private int nStartTime = 0;
/// 统计中的值
private int nFrameIng = 0;
/// 渲染帧函数
void Update()
{
if (CStaticMethod.SystemAfterTime () - nStartTime >= 1000)
{
nFrameCt = nFrameIng;
nStartTime = CStaticMethod.SystemAfterTime ();
nFrameIng = 0;
}
else
{
nFrameIng++;
}
}
void OnGUI()
{
GUIStyle testStyle = new GUIStyle();
testStyle.normal.background = null;
if (nFrameCt >= 40)
{
testStyle.normal.textColor = Color.white;
}
else if (nFrameCt >= 30)
{
testStyle.normal.textColor = Color.green;
}
else {
testStyle.normal.textColor = Color.red;
}
testStyle.fontSize = 30;
GUI.Label(new Rect(10, 10, 200, 60), "frame:" + nFrameCt, testStyle);
}
}
}