Last week I was done with the restructuring. And I added some new graphics to the layout. We discovered that the graphics we had caused a problem with the professional version of Unity and because of that we needed to fix the graphics. So I made the graphics for it, even if it isn’t the final graphics.
This week I decided to start with a task I have been putting on hold for the longest time. Tabbing between fields. I did the task earlier, but did not find a good way to go about this. The reason being that Unity if you are using [ExecuteInEditMode] or want input while in edit mode you cannot use the standard Unity input methods. So for instance Input.GetKeyDown() won’t work. Instead what you need to do is to use the Event.current.keyCode. The problem is that it doesn’t check if the key is down for the first time or not. Instead what you need to do is to check Event.current.type and check if the event is EventType.KeyDown. However when I tried this the first time I did not know about the Event.current.type.
So the first attempt of doing this a while back, I tried to implement my own KeyDown, but it reacted to all events so the previous event and current event would always update on mousemove etc. Basically what I did in the first attempt was to check if the previous event was tab or if it wasn’t. But the thing was that in Unity an event is even mouse move and OnGUI updates on focus and with the events, so when tabbing 2 events would be created and it always skipped a field.
The new version I found the keydown and that made it much simpler. I didn’t need to check for the previous event and thus I could just do:
if (Event.current.keyCode == KeyCode.Tab && Event.current.type == EventType.KeyDown)
This does basically the same as Input.GetKeyDown(KeyCode.Tab).
Another problem was getting the Shift modifier to go backwards, so I needed to add if (Event.current.shift) and put the previous element method in there and add else and put the next into that. And it was done.
Another philosophy I adopted was to make the class be as flexible as possible, so that I could reuse the class at some point without having to do too much modification. Ideally I should try to make it so that I can use it without modification at all, but I found out that I couldn’t do that unless I wanted to complicate the class even more.
I wanted to share the code here, but after having written all of this I don’t think that’s productive. If anyone requests it though I will put the code up here.
Next update will probably be sometime next year.