Need GUI + ability to keep cursor in window

I need to use both the GUI system, and I need to be able to keep the cursor inside the window at the same time. Ideally, I’d be able to modify/clamp Input.mousePosition, but the compiler tells me that’s readonly. The GUI system is also (as far as I can tell) not compatible with 1.x-style “GUITexture that moves based on mouse input” custom cursor, which is what I used to use for this sort of thing previously.

How can this be done? Or can it?

A “new GUI display that moves based on mouse input” custom cursor? You did it before, do it again with the new GUI tools so it layers nicely with your GUI elements.

Here’s how I’m drawing the cursor using the new GUI code:

var cursorImage : Texture;

function OnGUI () {
	if( !Screen.lockCursor ){
		GUI.depth = -16;
		GUI.Box(Rect(Input.mousePosition.x - 2, Screen.height - Input.mousePosition.y - 2, 32, 32), cursorImage, GUIStyle.none);
	}
}

This is only half the story (and the easy half). I don’t know if Unity allows us to set the mouse position (I know Unity itself can lock the cursor, but whether it gives us fine control is another story.)

You cannot set the mouse position.

Edit: and given what I just learned over here I can see how this isn’t likely to work in the end. Hmph, I’m off to get a suitable feature request logged…

It never occurred to me that Screen.lockcursor would play nicely with the GUI :wink: