Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// Created by JustPrototype
- /// Prototyping.bplaced.net
- /// </summary>
- public class FPSCounter : MonoBehaviour
- {
- public GameObject m_Panel_FPSCounter;// UI IMG for the output
- public float m_updateInterval = 0.5f;
- public bool m_ShowPFS;
- private float m_Accum;
- private int m_Frames;
- private float m_Timeleft;
- private float m_FPS;
- public void Start()
- {
- this.m_Timeleft = this.m_updateInterval;
- this.m_FPS = 30f;
- }
- public void Update()
- {
- this.m_Timeleft -= Time.deltaTime;
- this.m_Accum += Time.timeScale / Time.deltaTime;
- this.m_Frames++;
- if ((double)this.m_Timeleft <= 0.0)
- {
- this.m_FPS = this.m_Accum / (float)this.m_Frames;
- this.m_Timeleft = this.m_updateInterval;
- this.m_Accum = 0f;
- this.m_Frames = 0;
- }
- m_Panel_FPSCounter.GetComponent<Text>().text = "FPS: " + m_FPS.ToString("0");
- this.UpdateGUI();
- }
- private void UpdateGUI()
- {
- if (m_ShowPFS)
- m_Panel_FPSCounter.SetActive(true);
- else
- m_Panel_FPSCounter.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement