Writing a script for the scene view itself, not an editorwindow or custom inspector?

Is there a way to write an editor script that doesn’t require an EditorWindow and doesn’t require a GameObject (such as a custom inspector)?

I’m trying to write a grid manager tool for the editor. As I mouse over each tile on the grids, I would like to change the color of the gizmo/place a marker object at the tile location on the grid. From there I’ll implement tile selection. Each grid is a single mesh upon which I’m using raycasting to determine tile location.

I don’t want this functionality to be a part of each grid because there can be multiple grids. I want to avoid doing the same work twice for each grid.

At first I turned to EditorWindows but those only work as long as the EditorWindow has focus. The second you close it or click off, it doesn’t update.

Secondly, I tried just using an object in my scene view but A) that clutters things up and B) I have the same problem… the object needs to be selected. The second you deselect, the script stops running.

What are my options here?

TL;DR I’m trying to enhance how the mouse works in the editor but editor windows and custom inspector scripts aren’t cutting it.

    [InitializeOnLoad]
    public class MySceneClass
    {
        static MySceneClass()
        {
            SceneView.onSceneGUIDelegate += Update;
        }

        public static void Update(SceneView view)
        {
            // stuff
        }
    }
1 Like