Search Unity

Assigning focus to a control?

Discussion in 'Immediate Mode GUI (IMGUI)' started by SWGraham, Jul 24, 2008.

  1. SWGraham

    SWGraham

    Joined:
    Mar 10, 2008
    Posts:
    49
    I want the Enter key to assign focus to a text entry field for chat. I know about how GUIUtility.keyboardControl is the widget that has the text cursor. GUIUtility.GetControlID sounds like it should be what to use to find the ID I want to stick there, but the documentation page looks like a copypaste mistake and doesn't show how to use it.

    Anyone use these successfully?
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    GetControlID is used to generate a unique ID for a GUI control, not for looking up a control's id.

    Try using GUI.SetNextControlName with GUI.FocusControl.
     
  3. SWGraham

    SWGraham

    Joined:
    Mar 10, 2008
    Posts:
    49
    Rawk! That makes sense when I remember that GUI is stream-of-consciousness. "Next" means the next control that I mention. So...

    Code (csharp):
    1. GUI.SetNextControlName( "ChatEntry" );
    2. myText = GUI.TextField(sendRect, myText, 64);
    3.  
    and

    Code (csharp):
    1.  
    2. if( Input.GetButtonDown( "Shaun Rocks" ) )
    3.    GUI.FocusControl( "ChatEntry" );
    4.