Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    [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.

    EditorGUI_issue.gif

    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 = Vector2.zero;
    11.     GUI.BeginClip(area);
    12.     Rect line = new Rect(0, 0, area.width, EditorGUIUtility.singleLineHeight);
    13.  
    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.
    http://www.clonefactor.com/wordpress/public/1769/
     
    Last edited: Aug 12, 2017
  2. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    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

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    @tcz8 , yes I did, I post it on my blog (included source code)
    https://www.clonefactor.com/wordpress/program/c/1809/
    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#)

     
  4. inkletom

    inkletom

    Joined:
    Oct 13, 2016
    Posts:
    63
    Hey! I was trying to do the same thing, and found your code still had the same issue - anything drawn before the popup eats the input. Don't suppose you forgot to update the source or something? It looks slightly different to your example video in my project too.
    (Also, big thanks for this, it's a really good tool!)