FPS

来源:互联网 发布:电脑软件全部打不开 编辑:程序博客网 时间:2024/04/26 10:34
using UnityEngine;
using System.Collections;

public class FPS : MonoBehaviour {
    
    private float m_timer;
    private int m_frameCounter;
    public float m_updateInterval = 0.5f;
    public float m_fps;

    public System.Action<float> m_fpsUpdateCallback;
    
    // Use this for initialization
    void Start () {
        m_timer = 0;
        m_frameCounter = 0;
    }
    
    // Update is called once per frame
    void Update () {
        m_timer += Time.deltaTime;
        m_frameCounter++;
        
        
        if(m_timer > m_updateInterval)
        {
            m_fps = m_frameCounter / m_timer;
            m_frameCounter = 0;
            m_timer = 0;

            if (m_fpsUpdateCallback != null)
            {
                m_fpsUpdateCallback(m_fps);
            }
        }
    }
}

0 0