using UnityEngine; using UnityEditor; public class ZIMFPSWindow : EditorWindow { [MenuItem("Tools/Continuous FPS")] public static void Open() { EditorWindow.GetWindow(typeof(ZIMFPSWindow)); } public static float fpsMean; // 统计fps的均值 public static GUIStyle ZIMStyle; static int count; static string info; static float timeFlag; void OnEnable() { count = 0; timeFlag = Time.time; } void OnGUI() { if (ZIMStyle == null) { ZIMStyle = new GUIStyle(GUI.skin.label); ZIMStyle.fontSize = 18; ZIMStyle.alignment = TextAnchor.MiddleCenter; } GUILayout.Space(10); GUILayout.Label("Get mean FPS in continuous time", ZIMStyle); GUILayout.Space(10); if (GUILayout.Button("Reset")) { OnEnable(); } GUILayout.Space(10); info = "Mean FPS value is: " + fpsMean; EditorGUILayout.HelpBox(info, MessageType.None, true); } private void OnInspectorUpdate() { // 调用Repaint方法来强制窗口重绘 Repaint(); } private void Update() { count++; fpsMean = count / (Time.time - timeFlag); //Debug.Log($"{count}, {Time.time}, {fpsMean}"); } }