12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //======= Copyright (c) Valve Corporation, All rights reserved. ===============
- //
- // Purpose: Helper to display various hmd stats via GUIText
- //
- //=============================================================================
- using UnityEngine;
- #if UNITY_2017_2_OR_NEWER
- [ExecuteInEditMode]
- public class SteamVR_Stats : MonoBehaviour
- {
- void Awake()
- {
- Debug.Log("SteamVR_Stats is deprecated in Unity 2017.2 - REMOVING");
- DestroyImmediate(this);
- }
- }
- #else
- using Valve.VR;
- public class SteamVR_Stats : MonoBehaviour
- {
- public GUIText text;
- public Color fadeColor = Color.black;
- public float fadeDuration = 1.0f;
- void Awake()
- {
- if (text == null)
- {
- text = GetComponent<GUIText>();
- text.enabled = false;
- }
- if (fadeDuration > 0)
- {
- SteamVR_Fade.Start(fadeColor, 0);
- SteamVR_Fade.Start(Color.clear, fadeDuration);
- }
- }
- double lastUpdate = 0.0f;
- void Update()
- {
- if (text != null)
- {
- if (Input.GetKeyDown(KeyCode.I))
- {
- text.enabled = !text.enabled;
- }
- if (text.enabled)
- {
- var compositor = OpenVR.Compositor;
- if (compositor != null)
- {
- var timing = new Compositor_FrameTiming();
- timing.m_nSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Compositor_FrameTiming));
- compositor.GetFrameTiming(ref timing, 0);
- var update = timing.m_flSystemTimeInSeconds;
- if (update > lastUpdate)
- {
- var framerate = (lastUpdate > 0.0f) ? 1.0f / (update - lastUpdate) : 0.0f;
- lastUpdate = update;
- text.text = string.Format("framerate: {0:N0}\ndropped frames: {1}", framerate, (int)timing.m_nNumDroppedFrames);
- }
- else
- {
- lastUpdate = update;
- }
- }
- }
- }
- }
- }
- #endif
|