GUI.enabled without the transparency?

I need a way to disable input in the entire GUI. Using GUI.enabled without the transparency would allow me to do just that, however from what I hear it's a hard-coded behavior and cannot be changed.

I need to disable specific buttons (not all buttons), and I want to specify a GUIStyle for that button's "Disabled" state. I try managing this myself in game logic, but there are a few kinks.

Can GUI.enabled be configured to NOT make the controls turn transparent? If not, are there other ways I can intercept mouse move messages and prevent the controls from registering the cursor position?

I do not think there is a way to configure the style of GUI.enabled, and I don't think there is a good way to control cursor position (assuming you mean in a text box). I would do something like (C#):

private string inputString1 = "blah";
private string inputString2 = "blahblah";
private bool guiEnabled = false;

void OnGUI()
{
  guiEnabled = GUILayout.Toggle( guiEnabled );
  inputString1 = TextField( inputString1, guiEnabled );
  inputString2 = TextField( inputString2, guiEnabled );
}

private string TextField( string value, bool enable )
{
  if( enable )
  {
    return GUILayout.TextField( value );
  }
  else
  {
    // looks like a TextField but acts like a Label
    GUILayout.Label( value, "TextField" ); 
    return value;
  }
}

i.e. you have to do it manually, but you can just write one small function once to wrap it and use it for all the controls that need disabling.

Although I haven't tested this thoroughly, it might help out (posted in another thread about same issue).

Found a nice solution to this, looks like the behavior is not to hardcode alpha to .5, but to multiply it by .5. Therefore, setting the color to (1,1,1,2) results in the same color after this hardcoded math is done. So, for disabled controls, just do

GUI.color = new Color(1,1,1,2);

and set it back when done and your control's appearance will not change. Least it's working for me in the editor so far.

It took me a while and this thread helped - but instead of using the trick with the doubled alpha:

GUI,color = new Color(1,1,1,2);

… you can also set enabled to true only when the event type is Render. Then the event processing is disabled in all other passes

GUI.enabled = active || tp == EventType.repaint;

This way the rendering is unaffected and the events are swallowed. I use this to have overlapping windows without clicking through the topmost window…

A simple solution would be to simply catch all input events before calling the GUI:

`

if (disabled && Event.current.type != EventType.Repaint && Event.current.type != EventType.Layout)

Event.current.Use();

`

However, this will not get rid of mouse rollover GUI effects, I believe.

I wondered this too, especially with text fields and text areas. In some cases disabled controls can be "emulated" using other types of fields that aren't intended for input, and in some cases you can duplicate the control in an if-else condition. I submit a couple of alternate ideas that give a little more control.

In this example, you can create your own "disabled button" definition (typically with no "hover" or "active" states) that is called instead of the active one when `buttonDisabled` is true.

bool buttonDisabled;
GUIStyle enabledButton;
GUIStyle disabledButton;

void OnGUI() {
    if (!buttonDisabled) {
        GUILayout.Button("Button", enabledButton);
    } else {
        GUILayout.Button("Button", disabledButton);
    }
}

When you desire an area of text that cannot be selected or modified at runtime, if you can't use `GUIText` for the purpose, you should opt for a `Box` or `Label` instead. `Label`s are more limited, so generally stick with `Box`es unless you're sure you won't need to modify the element's appearance in any way.