- Home /
Modify editor GUI content using mouse click
I'm trying to make a custom editor window that has a window area and an inspector-like area to the right, as follows:
It behaves as expected, but I have an issue: I need to know which window is current selected, so I'm holding the current window ID in a property, as follows:
void windowFunc(int id){
if ((Event.current.button == 0) && (Event.current.type == EventType.MouseDown)) {
selectedWindow = id;
}
// More window stuff...
}
and, on OnGUI function, I reset the selected window so whenever I click outside an window but inside window area, i de-select any selected window:
void OnGUI () {
// Some GUI stuff...
if ((Event.current.type == EventType.MouseDown) && (Event.current.button == 0) && bounds.Contains(Event.current.mousePosition)) {
// reset selected window
selectedWindow = -1;
}
BeginWindows();
// More GUI stuff, and a catch later...
}
So far, so good. The problem lies when I need to modify the side view to show/hide content based on selected window:
void OnGUI() {
// The same OnGUI as before...
if (selectedWindow != -1){
EditorGUI.indentLevel++;
// draw some controls over here...
EditorGUI.indentLevel--;
}
// if statement is false, don't draw extra items
}
This code works flawless if the amount of controls is higher than before (in the image example, if a window has more outputs than the window selected before). Otherwise, the error pops up on console:
ArgumentException: Getting control 5's position in a group with only 5 controls when doing mouseDown
I know why the error occurs (I shouldn't change window content between a layout and a repaint event), but how can I work-around this issue? Does removing "Layout" functions should get rid of these errors (yes, I'm using Layout functions to draw the controls)?
Answer by astorga · Sep 23, 2015 at 01:46 PM
Just in case anyone need to know, here's what I did to handle this situation: On windowFunc
, I added a call: Event.current.Use();
. After that, no more console errors, and I'm happy :D
Your answer
Follow this Question
Related Questions
Editor GUI Foldout header style customization 0 Answers
DragAndDrop EditorGUILayout.Box ? 1 Answer
EditorGUI elements require minimum size of 24px? 0 Answers
How do I make a progress bar in the editor lock the background? 0 Answers
Drawing Editor Inspector GUI based on selected/current prefab (CustomPropertyDrawer) 2 Answers