ZIMFPSWindow.cs.bak 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using UnityEditor;
  3. public class ZIMFPSWindow : EditorWindow
  4. {
  5. [MenuItem("Tools/Continuous FPS")]
  6. public static void Open()
  7. {
  8. EditorWindow.GetWindow(typeof(ZIMFPSWindow));
  9. }
  10. public static float fpsMean; // 统计fps的均值
  11. public static GUIStyle ZIMStyle;
  12. static int count;
  13. static string info;
  14. static float timeFlag;
  15. void OnEnable()
  16. {
  17. count = 0;
  18. timeFlag = Time.time;
  19. }
  20. void OnGUI()
  21. {
  22. if (ZIMStyle == null)
  23. {
  24. ZIMStyle = new GUIStyle(GUI.skin.label);
  25. ZIMStyle.fontSize = 18;
  26. ZIMStyle.alignment = TextAnchor.MiddleCenter;
  27. }
  28. GUILayout.Space(10);
  29. GUILayout.Label("Get mean FPS in continuous time", ZIMStyle);
  30. GUILayout.Space(10);
  31. if (GUILayout.Button("Reset"))
  32. {
  33. OnEnable();
  34. }
  35. GUILayout.Space(10);
  36. info = "Mean FPS value is: " + fpsMean;
  37. EditorGUILayout.HelpBox(info, MessageType.None, true);
  38. }
  39. private void OnInspectorUpdate()
  40. {
  41. // 调用Repaint方法来强制窗口重绘
  42. Repaint();
  43. }
  44. private void Update()
  45. {
  46. count++;
  47. fpsMean = count / (Time.time - timeFlag);
  48. //Debug.Log($"{count}, {Time.time}, {fpsMean}");
  49. }
  50. }