You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
750 B

  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System.Collections;
  4. public class FPSDisplay : MonoBehaviour {
  5. float deltaTime = 0.0f;
  6. void Update() {
  7. deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
  8. }
  9. void OnGUI() {
  10. int w = Screen.width, h = Screen.height;
  11. GUIStyle style = new GUIStyle();
  12. Rect rect = new Rect(0, 0, w, h * 2 / 100);
  13. style.alignment = TextAnchor.UpperLeft;
  14. style.fontSize = h * 2 / 100;
  15. style.normal.textColor = new Color(0.0f, 0.0f, 0.5f, 1.0f);
  16. float msec = deltaTime * 1000.0f;
  17. float fps = 1.0f / deltaTime;
  18. string text = string.Format("{0:0.0} ms ({1:0.} fps)", msec, fps);
  19. GUI.Label(rect, text, style);
  20. }
  21. }
  22. #endif