您的位置:首页 > 移动开发 > Unity3D

Unity3D 大型游戏 最后一站 源码 部分重点 显示FPS

2017-03-14 09:46 537 查看
本文固定链接:http://blog.csdn.net/u013108312/article/details/62037298

Unity3D 显示FPS脚本。

using UnityEngine;
using System.Collections;

public class ShowFPS : MonoBehaviour {

public static ShowFPS Instance
{
private set;
get;
}

void OnEnable()
{
Instance = this;
}

void OnDisable()
{
Instance = null;
}

public float f_UpdateInterval = 0.5F;

private float f_LastInterval;

private int i_Frames = 0;
private float f_Fps;

private GUIStyle style = new GUIStyle();

public float sSPing
{
set;
get;
}

public float cSPing
{
set;
get;
}

void Start()
{
Application.targetFrameRate = 300;
f_LastInterval = Time.realtimeSinceStartup;
i_Frames = 0;

style.fontSize = 10;
style.normal.textColor = new Color(0, 255, 0, 255);
}

void OnGUI()
{

GUI.Label(new Rect(0, 0, 200, 200), "FPS:" + f_Fps.ToString("f2"), style);
GUI.Label(new Rect(0, 10, 200, 200), "sSPing:" + sSPing.ToString("f2"), style);
GUI.Label(new Rect(0, 20, 200, 200), "cSPing:" + cSPing.ToString("f2"), style);
}

void Update()
{
++i_Frames;

if (Time.realtimeSinceStartup > f_LastInterval + f_UpdateInterval)
{
f_Fps = i_Frames / (Time.realtimeSinceStartup - f_LastInterval);

i_Frames = 0;

f_LastInterval = Time.realtimeSinceStartup;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐