Skip to content

Commit d3e6d31

Browse files
committed
Fix domain reload warnings and improve editor initialization.
- Fix UDR0001 warnings and stabilize editor event subscriptions.
1 parent ba39169 commit d3e6d31

3 files changed

Lines changed: 87 additions & 31 deletions

File tree

Editor/EditorFPSDisplay.cs

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// **************************************************************** //
1010

1111
#if UNITY_EDITOR
12-
using UnityEngine;
1312
using UnityEditor;
13+
using UnityEngine;
1414

1515
namespace RimuruDev
1616
{
@@ -19,41 +19,82 @@ public sealed class EditorFPSDisplay
1919
{
2020
private static float fps;
2121
private static int frameCount;
22-
private const float OneSecond = 1;
2322
private static double lastUpdateTime;
23+
private static bool subscribed;
24+
25+
private const float oneSecond = 1f;
2426
private static readonly Rect rect = new(10, 10, 100, 50);
2527

2628
static EditorFPSDisplay()
2729
{
30+
Subscribe();
31+
32+
AssemblyReloadEvents.beforeAssemblyReload -= Unsubscribe;
33+
AssemblyReloadEvents.beforeAssemblyReload += Unsubscribe;
34+
35+
EditorApplication.quitting -= Unsubscribe;
36+
EditorApplication.quitting += Unsubscribe;
37+
}
38+
39+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
40+
private static void Initialize()
41+
{
42+
Unsubscribe();
43+
44+
fps = 0f;
45+
frameCount = 0;
46+
lastUpdateTime = EditorApplication.timeSinceStartup;
47+
48+
Subscribe();
49+
}
50+
51+
private static void Subscribe()
52+
{
53+
if (subscribed)
54+
return;
55+
56+
subscribed = true;
57+
2858
EditorApplication.update += Update;
29-
SceneView.duringSceneGui += OnSceneGUI;
59+
SceneView.duringSceneGui += OnSceneGui;
3060
}
3161

32-
~EditorFPSDisplay()
62+
private static void Unsubscribe()
3363
{
64+
if (!subscribed)
65+
return;
66+
67+
subscribed = false;
68+
3469
EditorApplication.update -= Update;
35-
SceneView.duringSceneGui -= OnSceneGUI;
70+
SceneView.duringSceneGui -= OnSceneGui;
3671
}
3772

3873
private static void Update()
3974
{
4075
frameCount++;
76+
4177
var timeNow = EditorApplication.timeSinceStartup;
78+
var delta = timeNow - lastUpdateTime;
4279

43-
if (timeNow - lastUpdateTime >= OneSecond)
44-
{
45-
fps = frameCount / (float)(timeNow - lastUpdateTime);
46-
frameCount = 0;
47-
lastUpdateTime = timeNow;
48-
}
80+
if (!(delta >= oneSecond))
81+
return;
82+
83+
fps = frameCount / (float)delta;
84+
frameCount = 0;
85+
lastUpdateTime = timeNow;
4986
}
5087

51-
private static void OnSceneGUI(SceneView sceneView)
88+
private static void OnSceneGui(SceneView sceneView)
5289
{
5390
Handles.BeginGUI();
54-
GUILayout.BeginArea(rect);
55-
GUILayout.Label($"FPS: {fps:F1}", EditorStyles.whiteLabel);
56-
GUILayout.EndArea();
91+
{
92+
GUILayout.BeginArea(rect);
93+
{
94+
GUILayout.Label($"FPS: {fps:F1}", EditorStyles.whiteLabel);
95+
}
96+
GUILayout.EndArea();
97+
}
5798
Handles.EndGUI();
5899
}
59100
}

README.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
# Unity Editor FPS Display
22

3-
A Unity Editor extension to display the FPS in the Scene view. This can help developers optimize their editor scripts and monitor the performance of their Unity Editor.
3+
A lightweight Unity Editor extension that displays real-time FPS directly in the Scene view.
4+
Useful for monitoring editor performance, custom tools, and editor-time rendering overhead.
45

56
## Features
67

7-
- Displays FPS in the top-right corner of the Scene view.
8-
- Helps in monitoring and optimizing editor scripts.
8+
- Displays FPS in the Scene view overlay
9+
- Zero configuration, works out of the box
10+
- Safe for Enter Play Mode with Domain Reload disabled
11+
- Supports modern Unity editor lifecycle (assembly reloads, subsystem registration)
12+
13+
## Supported Unity Versions
14+
15+
- Unity **2020.3 LTS**
16+
- Unity **2021+**
17+
- Unity **6.x (6000.x)**
918

1019
## Installation
1120

12-
To install this package, follow these steps:
21+
### Via Git URL (recommended)
1322

14-
1. Open your Unity project.
15-
2. Go to `Window -> Package Manager`.
16-
3. Click the `+` button in the top-left corner of the Package Manager window.
17-
4. Select `Add package from git URL...`.
18-
5. Enter the following URL: `https://github.com/RimuruDev/Unity-EditorFPSDisplay.git`
19-
6. Click `Add`.
23+
1. Open **Window → Package Manager**
24+
2. Click **+**
25+
3. Select **Add package from git URL**
26+
4. Paste: ```https://github.com/RimuruDev/Unity-EditorFPSDisplay.git```
27+
5. Click **Add**
2028

2129
## Usage
2230

23-
Once installed, the FPS counter will automatically appear in the top-right corner of the Scene view in the Unity Editor. There is no additional setup required.
31+
Once installed, the FPS counter will automatically appear in the Scene view.
32+
No setup or configuration is required.
33+
34+
## Notes
35+
36+
- Designed to be safe with **Enter Play Mode Options**
37+
- Properly handles editor domain reloads and assembly reloads
38+
- Does not allocate per frame
2439

2540
## License
2641

27-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
42+
MIT License — see [LICENSE](LICENSE)
2843

2944
## Author
3045

31-
RimuruDev
46+
**RimuruDev**
3247

33-
[GitHub Profile](https://github.com/RimuruDev)
48+
GitHub: https://github.com/RimuruDev

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "com.rimurudev.editorfpsdisplay",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"displayName": "Editor FPS Display",
5-
"description": "A Unity Editor extension to display the FPS in the Scene view.",
5+
"description": "A Unity Editor extension to display FPS in the Scene view. Supports Unity 2020.3 LTS and newer (including Unity 6.x).",
66
"unity": "2020.3",
77
"author": {
88
"name": "RimuruDev",

0 commit comments

Comments
 (0)