| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using UnityEngine;
- using System.Collections;
- using DG.Tweening;
-
- public class FPSTester : MonoBehaviour
- {
- private float m_LastUpdateShowTime=0f; //上一次更新帧率的时间;
-
- private float m_UpdateShowDeltaTime=1f;//更新帧率的时间间隔;
-
- private int m_FrameUpdate=0;//帧数;
-
- private float m_FPS=0;
-
- void Awake()
- {
- //Application.targetFrameRate=-1;
- }
-
- // Use this for initialization
- void Start ()
- {
- m_LastUpdateShowTime=Time.realtimeSinceStartup;
- }
-
- // Update is called once per frame
- void Update ()
- {
- m_FrameUpdate++;
- if(Time.realtimeSinceStartup-m_LastUpdateShowTime>=m_UpdateShowDeltaTime)
- {
- m_FPS=m_FrameUpdate/(Time.realtimeSinceStartup-m_LastUpdateShowTime);
- m_FrameUpdate=0;
- m_LastUpdateShowTime=Time.realtimeSinceStartup;
- }
- }
-
- void OnGUI()
- {
- GUIStyle labelFont = new GUIStyle();
- labelFont.normal.textColor = new Color(1, 0.6f, 0.6f);
- labelFont.fontSize = Mathf.CeilToInt(Screen.height * 0.05f);
- GUI.Label(new Rect(Screen.width/100,Screen.height/100,100,100),"FPS: "+m_FPS, labelFont);
- }
- }
|