Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to draw EditorGUI on top of another EditorGUI and allow interact with it ?

Discussion in 'Editor & General Support' started by canis, Aug 12, 2017.

  1. canis


    Oct 25, 2013
    [How to move this thread to "Script" session?]

    here is the story, I tried to create the auto complete popup for my Editor tools kit. (following gif)
    as the images shown, when the "popup" that I make show on top of another EditorGUI.
    something wired happen,
    1. I can't really click on the "Top" button, click will focus the EditorGUI behind it.
      in this case:
      if any textfield are lay behind the button, mouse click will focus on the textfield "Behind",
      instead of the button on "Top" of it.
    2. Cursor (Mouse), it also display as a Cursor.Text instead of Cursor.Hand
    3. The popup working fine, if there is nothing allow to interact behind.


    some article are saying the GUI.Depth are used to solve the issue, however it didn't work on my cases.
    here is how I implement it.

    Code (CSharp):
    1. // Draw recommend keyward(s)
    2. if (m_CacheCheckList.Count > 0)
    3. {
    4.     int cnt = m_CacheCheckList.Count;
    5.     float height = cnt * EditorGUIUtility.singleLineHeight;
    6.     Rect area = position;
    7.     area = new Rect(area.x, area.y - height, area.width, height);
    8.     GUI.depth-=10;
    9.     // GUI.BeginGroup(area);
    10.     // area.position =;
    11.     GUI.BeginClip(area);
    12.     Rect line = new Rect(0, 0, area.width, EditorGUIUtility.singleLineHeight);
    14.     for (int i = 0; i < cnt; i++)
    15.     {
    16.         if (GUI.Button(line, m_CacheCheckList[i]))//, EditorStyles.toolbarDropDown))
    17.         {
    18.             rst = m_CacheCheckList[i];
    19.             GUI.changed = true;
    20.             GUI.FocusControl(""); // force update
    21.         }
    22.         line.y += line.height;
    23.     }
    24.     GUI.EndClip();
    25.     //GUI.EndGroup();
    26.     GUI.depth+=10;
    27. }
    so any idea how to workaround the problem ?

    for anyone who interested to review the full source code,
    there is the link in my blog.
    Last edited: Aug 12, 2017
  2. tcz8


    Aug 20, 2015
    Did you ever find a solution to that bug? I tried using your autocomplete code in a custom EditorWindow and stumbled on the same issue.
  3. canis


    Oct 25, 2013
    @tcz8 , yes I did, I post it on my blog (included source code)
    the concept is using the 'Event.current' to define which area are clicked.

    it look like this.

    added Feature :

    • [New] Up/Down Arrow to select the option
    • [New] Enter to confirm and replace current text to selected option.
    • [New] when string are perfect matching the option, the option will display as selected.
    • Giving recommend result based on giving string[] in editor
    • support Fuzzy matching – Levenshtein Distance (Wiki) (code ref: C#)