显示帧数脚本

 1 //
 2 // Author:
 3 //   Andreas Suter (andy@edelweissinteractive.com)
 4 //
 5 // Copyright (C) 2011-2012 Edelweiss Interactive (http://www.edelweissinteractive.com)
 6 //
 7 
 8 using UnityEngine;
 9 using System.Collections;
10 
11 public class ShowFPS : MonoBehaviour {
12 
13     public float fpsMeasuringDelta = 2.0f;
14 
15     private float timePassed;
16     private int m_FrameCount = 0;
17     private float m_FPS = 0.0f;
18     
19     private void Start () {
20         timePassed = 0.0f;
21     }
22     
23     private void Update () {
24         m_FrameCount = m_FrameCount + 1;
25         timePassed = timePassed + Time.deltaTime;
26         
27         if (timePassed > fpsMeasuringDelta) {
28             m_FPS = m_FrameCount / timePassed;
29             
30             timePassed = 0.0f;
31             m_FrameCount = 0;
32         }
33     }
34     
35     private void OnGUI () {
36         GUI.color = new Color (1.0f, 0.5f, 0.0f);
37         GUILayout.Label ("FPS: " + m_FPS);
38     }
39 }

 

posted @ 2017-08-01 11:43  露夕逝  阅读(288)  评论(0编辑  收藏  举报