Search Unity

Need GUI + ability to keep cursor in window

Discussion in 'Immediate Mode GUI (IMGUI)' started by StarManta, Nov 16, 2007.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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?
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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.
     
  3. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    Here's how I'm drawing the cursor using the new GUI code:

    var cursorImage : Texture;

    Code (csharp):
    1. function OnGUI () {
    2.     if( !Screen.lockCursor ){
    3.         GUI.depth = -16;
    4.         GUI.Box(Rect(Input.mousePosition.x - 2, Screen.height - Input.mousePosition.y - 2, 32, 32), cursorImage, GUIStyle.none);
    5.     }
    6. }
    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.)
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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...
     
  5. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    It never occurred to me that Screen.lockcursor would play nicely with the GUI ;-)