I am using a mouse icon texture in the center of the screen to represent the mouse cursor in a first person point
of view application. I lock and unlock the mouse, swapping between a custom cursor texture and the hardware mouse.
I use two monitors with my game view on the secondary monitor and the scene view on the primary.
I would like to know if there is a way force the hardware mouse to focus on the game view. I use the escape key
for several things and when it is pressed, it takes focus from the game window and returns it to the desktop.
My code toggles the cursor lock with each press of escape and does that fine. But, it does not return focus
to the game window until I click on it with the mouse.
If I understood you right then you’re in Unity Editor and the problem is giving focus to Game view? If you can capture the event when the focus needs to be given to game view, then all you need to do is call this somewhere in editor code:
SceneView.GetWindow(System.Type.GetType("UnityEditor.GameView,UnityEditor.dll")).Focus();
Maybe there’s some easier way, but this works for me. GameView type is not directly available, so reflection is needed to get it.
Thank you for the help, but I may be incorrect with my explanation of what I want to accomplish.
My problem is that the mouse drops out of the game view and back to desktop (losing focus on the game window)
when I hit escape. I have the escape key set up to allow the player to back out of menus and when they do, the mouse
is free on the desktop and no longer locked. I’m not sure if I am unlocking it somewhere or if the escape key is cursed
to do this to me :-). I think what I need is to dig through my code further to see if I can somehow re-lock it to the center
of the game window after the player has escaped from an in game menu. If anyone knows that this is an issue and / or
knows how to dis-allow the escape key to back out of the game view, please let me know.