zoukankan      html  css  js  c++  java
  • u3d fpsCounter

    因为u3d自己的stats下面的fpscounter不是实际意义上的fps,所以看到demo的fpsCounter,把它改写为c#的

    using UnityEngine;
    using System.Collections;

    public class FpsCounterex : MonoBehaviour
    {
        private GUIText guitex;
        private double updateInterval = 1.0f;
        private double lastInterval;
        private int frames = 0;

        // Use this for initialization
        void Start ()
        {
            lastInterval = Time.realtimeSinceStartup;
            frames = 0;
        }

        void Exit()
        {
            if (guiText)
                DestroyImmediate(guiText.gameObject);
        
        
        }
        void OnDisable()
        {
            if (guiText)
                DestroyImmediate(guiText.gameObject);
        }
        // Update is called once per frame
        void Update ()
        {
            ++frames;
            float timeNow = Time.realtimeSinceStartup;
            if (timeNow > lastInterval + updateInterval)
            {
                if (!guitex)
                {
                   GameObject go= new GameObject("FPS Display");
                   go.AddComponent("GUIText");
                  // go.hideFlags = HideFlags.HideAndDontSave;
                   go.transform.position =new  Vector3(0,0,0);
                   guitex = go.guiText;
                   guitex.pixelOffset =new  Vector2(5,55);
                }
                float fps=(float) frames /(float) (timeNow - lastInterval);
                float ms  = 1000.0f / Mathf.Max((float)fps, 0.00001f);
                guitex.text = ms.ToString("f1") + "ms " + fps.ToString("f6") + "FPS";
               // guitex.text = "abasdfasdfadsf";
                frames = 0;
                lastInterval = timeNow;
            }

           // guitex.text = "asdfasdfadsfas";
        }
    }

    代码放到gameobject下面,界面会自己现实fps

  • 相关阅读:
    URAL 2067 Friends and Berries (推理,数学)
    URAL 2070 Interesting Numbers (找规律)
    URAL 2073 Log Files (模拟)
    URAL 2069 Hard Rock (最短路)
    URAL 2068 Game of Nuts (博弈)
    URAL 2066 Simple Expression (水题,暴力)
    URAL 2065 Different Sums (找规律)
    UVa 1640 The Counting Problem (数学,区间计数)
    UVa 1630 Folding (区间DP)
    UVa 1629 Cake slicing (记忆化搜索)
  • 原文地址:https://www.cnblogs.com/dragon2012/p/3891739.html
Copyright © 2011-2022 走看看