zoukankan      html  css  js  c++  java
  • Unity3D 计算FPS

    using UnityEngine;
    using System.Collections;
    
    public class FPS : MonoBehaviour {
    
        private const string DISPLAY_TEXT_FORMAT = "{0} msf
    ({1} FPS)";
        private const string MSF_FORMAT = "#.#";
        private const float MS_PER_SEC = 1000f;
    
        private string textField;
        private float fps = 60;
    
        void Awake()
        {
        }
    
        void Start()
        {
    
        }
    
        void LateUpdate()
        {
            float interp = Time.deltaTime / (0.5f + Time.deltaTime);
            float currentFPS = 1.0f / Time.deltaTime;
            fps = Mathf.Lerp(fps, currentFPS, interp);
            float msf = MS_PER_SEC / fps;
            textField = string.Format(DISPLAY_TEXT_FORMAT,
                msf.ToString(MSF_FORMAT), Mathf.RoundToInt(fps));
        }
        GUIStyle style = new GUIStyle();
        void OnGUI()
        {
            style.fontSize = 30;
            style.normal.textColor = Color.white;
            GUI.Label(new Rect(0, 0, 200, 100), textField, style);
        }
    }
  • 相关阅读:
    代理
    博客园主题
    JS_1
    脚本语言
    Hadoop生态体系
    Hadoop序列化程序报错
    46. 全排列
    1038 Recover the Smallest Number (30分)
    1064 Complete Binary Search Tree (30分)
    1034 Head of a Gang (30分)
  • 原文地址:https://www.cnblogs.com/mrblue/p/5957980.html
Copyright © 2011-2022 走看看