Search Unity

Detect events outside of OnSceneGUI ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dark-Protocol, Nov 8, 2015.

  1. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    I have a custom editor which requires the player to click and drag the mouse inside the scene view in order to draw things. The drawing is finalized whenever the user releases the left mouse button. The problem is that if I hover out of the scene view while drawing and release the left mouse button, the event is not detected and I have to drag the mouse back over the scene view, click it again and release it in order for the editor to detect the MouseUp event. Is there a way I can detect the MouseUp event even if I'm not hovering over the scene view ?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    What sort of editor is it? Is it derived from Editor (e.g: an inspector?)
     
  3. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Hi litoral, yes, my editor derives from the editor class and it both draws in the inspector and the scene view. I check the mouse events in both the scene drawing and the inspector drawing but still the above mentioned problem persists. Even if I click in the scene view and then move the mouse over the inspector and release the mouse, it won't detect the release unless I click on the inspector and then release the mouse.
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    What is the expected behaviour you'd like to see? You say that you're "drawing" things in the scene view by clicking and dragging the mouse.

    What should happen in the case where you leave the scene view window ? should it keep drawing? should it stop ? what do you expect for it to do ?
     
  5. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    I expect the editor to detect the mouse up event and stop drawing. I'm actually implementing a custom drag-select system for selecting non-game objects visualized on the screen by the custom editor. I need the editor to detect the mouse up event even if the mouse is outside the scene view and finalize the selection/stop drawing the selection rectangle. I need to mimic the behavior of the standard drag-selection.
     
  6. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Okay, so it seems that this thing is not possible. I couldn't find any information about it anywhere and since I couldn't get an answer here, I guess that it's not really possible using Unity's API. I wonder if I could make a low-level mouse hook and detect the mouse input like that. Too bad Unity doesn't have a built-in way to do that.