I created a custom editor window containing a scroll view. I made it so that the user can pan the view by moving the mouse while pressing the middle button (just like the scene view), it works great.
Now what I want is to change the mouse cursor into a hand (or whatever the pan cursor looks like on the current operating system) for the duration of the panning (again just like the scene view). But I didn’t find any function to do that.
I’m aware of EditorGUIUtility.AddCursorRect() but it doesn’t do what I want. AddCursorRect() defines a rectangle and changes the cursor when the mouse enters it. What I want is just to set the cursor no matter where it is.
I also found the Cursor.SetCursor() function, but that one takes a texture as parameter. I don’t want to set the cursor to a custom texture, I want to use the pan cursor provided by the operating system (as defined into the MouseCursor enumeration).
The scene view does it so I assume there must be a way for me to do it too.
I did some experimenting with the dimensions and found that using “SceneView.lastActiveSceneView.position” works perfectly since the expected rect uses pixel coordinates from the top left corner of the SceneView (which just derives from EditorWindow).
I thought something like using the AddCursorRect() dynamically. Something like this:
if(Condition to change the cursor)
{
EditorGUIUtility.AddCursorRect(new Rect(huge dimesions), MouseCursor.Pan);
}
With a very huge dimesions, that cover all the Editor window, it would be fine, because the mouse would be over the rect. But, my first approaches didn´t work… :S