unity中FPS计算

来源:互联网 发布:windows mobile win10 编辑:程序博客网 时间:2024/04/27 23:01
直接代码
using UnityEngine;using System.Collections;using System.Collections.Generic;public class FramesPerSecond : MonoBehaviour {//GUIpublic GUISkin guiStyle;public float updateInterval = 0.5f;private float accum = 0.0f;private int frames = 0;private float timeleft;public string fps;// Use this for initializationvoid Start () {timeleft = updateInterval;}// Update is called once per framevoid Update () {timeleft -= Time.deltaTime;accum += Time.timeScale/Time.deltaTime;++frames;// Interval ended - update GUI text and start new intervalif( timeleft <= 0.0 ) {// display two fractional digits (f2 format)fps = "" + (accum/frames).ToString("f2");timeleft = updateInterval;accum = 0.0f;frames = 0;}}void OnGUI () {GUI.skin = guiStyle;GUI.Label(new Rect (Screen.width-75, 5, 70, 20), "FPS :" + fps);//GUI.Label(new Rect (Screen.width-70, 35, 60, 30), fps);}}

0 0
原创粉丝点击