VR fps 显示

VR FPS 帧率显示

  1. 找到你的VR Camera(或Center Eye Camera),创建 UI->Canvas
    设置Render Mode为 World Space;
    设置位置为(0,0,0.5)(push it out in front of the camera)
    设置Scale为(0.001,0.001,0.001)
  2. 点击Canvas,创建UI->Text
  3. Text加入下面的代码
    点击”F”键可以显示隐藏
    Note: It uses the new fancy Unity 5 Time.unscaledDeltaTime property !
    转载来自:http://talesfromtherift.com/vr-fps-counter/
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    using UnityEngine;
    using UnityEngine.UI;
    // Display FPS on a Unity UGUI Text Panel
    // To use: Drag onto a game object with Text component
    // Press 'F' key to toggle show/hide
    public class TextFPSCounter : MonoBehaviour
    {
    public Text text;
    public bool show = false;
    private const int targetFPS =
    #if UNITY_ANDROID // GEARVR
    60;
    #else
    75;
    #endif
    private const float updateInterval = 0.5f;
    private int framesCount;
    private float framesTime;
    void Start()
    {
    // no text object set? see if our gameobject has one to use
    if (text == null)
    {
    text = GetComponent<Text>();
    }
    }
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.F))
    {
    show = !show;
    }
    // monitoring frame counter and the total time
    framesCount++;
    framesTime += Time.unscaledDeltaTime;
    // measuring interval ended, so calculate FPS and display on Text
    if (framesTime > updateInterval)
    {
    if (text != null)
    {
    if (show)
    {
    float fps = framesCount / framesTime;
    text.text = System.String.Format("{0:F2} FPS", fps);
    text.color = (fps > (targetFPS - 5) ? Color.green :
    (fps > (targetFPS - 30) ? Color.yellow :
    Color.red));
    }
    else
    {
    text.text = "";
    }
    }
    // reset for the next interval to measure
    framesCount = 0;
    framesTime = 0;
    }
    }
    }
坚持原创技术分享,您的支持将鼓励我继续创作!