I have a main script that is attached to the “world” (root) object on the scene and is responsible for global things such as global key events, displaying debug GUI, etc…
void OnGUI()
{
GUI.color = Color.red;
GUI.depth = 220;
windowRect0 = GUI.ModalWindow(0, windowRect0, DoMyWindow, "Red Window");
}
void DoMyWindow(int windowID)
{
if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
{
print("Got a click in window with color " + GUI.color);
Event.current.Use();
}else
{
Event.current.Use();
}
GUI.DragWindow(new Rect(0, 0, 10000, 10000));
}
I also have multiple objects dynamically generated on the screen (chess squares), each has a script that highlights itself when mouse hovers over and each pops detailed info (a prefab) when mouse clicks over it:
public class ChessTileHandler : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler{
...
public void OnPointerEnter(PointerEventData eventData)
{
.. highlight object...
}
public void OnPointerExit(PointerEventData eventData)
{
... return to normal
}
public void OnPointerClick(PointerEventData eventData)
{
... pop details...
}
}
The idea is the root object would pop the little debugging modal window on a particular key combination. It does pop the window, but it is not modal, when I click on the button from the GUI debug window or try to move it around, the chess square behind it reacts properly with a click event, it also reacts with a hover event when i hover over the GUI elements while dragging the modal window.
My question is, how do I create a truly modal window that would “eat” any mouse click on it (and preferably any mouse click outside it too) until I disable the GUI element?
EDIT:
the only solution I came up with so far is to have a static/global variable that enables/disables EventSystem. Is there a more elegant solution to the issue?