GUILayout Window consume mouse events

Hey guys

I’m making a GUILayout Window in the scene view for my custom editor:

GUILayout.Window(s_WindowId, guiRect, DrawWindow, GetTitle(), windowStyle);

This is working great:

alt text

My problem is that it doesn’t quite behave like the window drawn by the Camera.

For example, the Camera Window never receives focus. Additionally, clicking the title in the Camera Window does not deselect the GameObject.

I suspect the solution to this problem is to somehow consume the mouse events, but I have little experience in this area.

Can anyone point me in the correct direction as to how I could implement this?

Thanks,
Ves

Alrighty, my friend .NET Reflector came to the rescue. I ended up stealing this from SceneViewOverlay:

private void EatMouseInput(Rect position)
{
	int controlID = GUIUtility.GetControlID(s_WindowId, FocusType.Native, position);

	switch (Event.current.GetTypeForControl(controlID))
	{
		case EventType.MouseDown:
			if (position.Contains(Event.current.mousePosition))
			{
				GUIUtility.hotControl = controlID;
				Event.current.Use();
			}
			break;
			
		case EventType.MouseUp:
			if (GUIUtility.hotControl == controlID)
			{
				GUIUtility.hotControl = 0;
				Event.current.Use();
			}
			break;
					
		case EventType.MouseDrag:
			if (GUIUtility.hotControl == controlID)
				Event.current.Use();
			break;
					
		case EventType.ScrollWheel:
			if (position.Contains(Event.current.mousePosition))
				Event.current.Use();
			break;
	}
}

Furthermore, to lose the “bevelled” style I needed to make my own GUIStyle:

s_WindowStyle = new GUIStyle(GUI.skin.window);
s_WindowStyle.onNormal = s_WindowStyle.normal;