I want to be able to draw a circle around the mouse position when doing things on the Scene View.
I’m having trouble finding a solution to that because from what i’ve been searching, to draw gizmos or handles i need them to derive from a Monobehavior, but i don’t want to have to have an object on the scene to do this.
Is there a different way to go about this?
Not sure why SceneView is not documented. But you should be able to subscribe to the draw event like this:
static class SceneDrawer {
[InitializeOnLoadMethod]
static Init() {
SceneView.onSceneGUIDelegate -= DrawHandles;
SceneView.onSceneGUIDelegate += DrawHandles;
}
static void DrawHandles(SceneView sceneView) {
}
}
Getting the mouse position here might be as simple as Event.current.mousePosition. Not sure though
To complete previous post, I have something like that for my tools:
public static class SceneDrawer
{
[InitializeOnLoadMethod]
static Init()
{
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
private static void OnSceneGUI(SceneView sceneView)
{
Handles.BeginGUI();
{
if (EditorWindow.mouseOverWindow is SceneView)
{
if (Event.current.type == EventType.Repaint)
{
DrawCircleBrush(Color.white, 10f);
}
}
}
Handles.EndGUI();
}
private static void DrawCircleBrush(Color _color, float _size)
{
Handles.color = _color;
// Circle
Handles.CircleHandleCap(0, Event.current.mousePosition, Quaternion.identity, _size, EventType.Repaint);
// Cross Center
Handles.DrawLine(Event.current.mousePosition + Vector2.left, Event.current.mousePosition + Vector2.right);
Handles.DrawLine(Event.current.mousePosition + Vector2.up, Event.current.mousePosition + Vector2.down);
}
}
3 Likes