How cool is that? ;-)

I may be the last to get it, but I guess UnityGUI is “kind of” cool :wink:

Where else could you do something like:

if (GUILayout.Toggle(selectedGameType == GameType.Multiplayer, "[M]ultiplayer")
    || Input.GetKeyDown("m")) {
  selectedGameType = GameType.Multiplayer;
  isValid = false;
}

This just rocks!!!

:slight_smile:

Jashan

PS … one must be careful, though… when doing this to dynamically change the GUI (i.e. you hit a key and some new areas pop up), it seems like the GUI system is having a problem with finding some references. I would assume this has to do with the multiple OnGUI calls during one frame (one for layout, one for “event-handling”… or maybe more).

My fix was to simply move those very specific cases back to the Update()-method (not very nice, but at least it works :wink: ).

… error is something like “Getting control 0’s position in a group with only 0 controls when doing keyDown”…

Jashan

When doing that kind of “non” gui checks it’s usually a good idea only to do them on the last call to the OnGUI i.e.

if (GUILayout.Toggle(selectedGameType == GameType.Multiplayer, "[M]ultiplayer")
    || (Input.GetKeyDown("m")  Event.current = EventType.repaint)) {
  selectedGameType = GameType.Multiplayer;
  isValid = false;
}

That looks like a cool idea, and interestingly, when I do add

 Event.current.type == EventType.keyDown

the original problem is fixed. When I check EventType.repaint, however, the key stroke is not recognized. I can fix that by changing Input.GetKeyDown to Input.GetKey - however, then, even when using EventType.repaint, I’m getting the original problem.

Now, what really confuses me: I have these buttons spread over a few functions because the GUI has various states, depending on the selections. Interestingly, while the problem occured only in one particular instance before, which can be fixed by adding a check to “EventType.keyDown”, that same code messes everything up where it worked before by only checking “Input.GetKeyDown(…)”.

Is there any “proper” way of doing this? I think keyboard shortcuts for buttons are a rather nice thing to add, but at the moment the way I’m doing this feels kind of hackish :wink:

Jashan

Try using something like this:

if (Event.current.Equals (Event.KeyboardEvent (“[esc]”))) {
Debug.Log (“ESC was pressed”);
}

Now, this method has some bugs in the 2.0.1 - but that’s the “proper” way to do these kind of things

This method is not as cool, but it works (plus it still works if CAPS lock is on) :slight_smile:

Testbln = GUILayout.Toggle(Testbln, "Im a toggle");
if (Event.current.character.ToString().ToLower() == "m"  Event.current.type == EventType.keyUp) Testbln = !Testbln;

Cheers
Shaun

Is capitals not working one of the bugs? i.e.

if(Event.current.Equals(Event.KeyboardEvent("M")) || Event.current.Equals(Event.KeyboardEvent("m"))) Testbln=!Testbln;

Using the above code, I never get the event if CAPS lock is on.

Hm… that…

if (GUI.Button("[C]onfigure")
    || Event.current.Equals(Event.KeyboardEvent("c"))) {
    isConfigurationScreen = true;
}

… doesn’t work for me, the same code works smoothly with Input.GetKeyDown and checking against Event.current.type == EventType.keyDown. It’s in an OnGUI() method.

@shaun: I would believe that this is “by design”. Capital letters are referred to by shift (#), so it should probably be Event.KeyboardEvent(“#m”)… I haven’t checked that, though, but the manual says it:

Scripting > Runtime Classes > Event > Event.KeyboardEvent

Jashan

Thanks Jashan… I was still in .ToString() mode, when it’s a Keyboard event. doh!

Just how buggy is it? I can’t get it to work anywhere. Is the bug in any way related with powerbook g4?

Regards,
Afonso