Thursday, November 20, 2014

User Interfaces Pt.3 - Well that was Embarrassing...

Today again, I spent the vast majority of my time stuck to the computer investigating solutions to the UI and found tons of different leads. Too many in fact. I'd say today served well as a period for me to learn more about the finer points of how Unity works rather than the editor aspects I've been stuck in so far. Certainly has also helped my understanding of C# improve. It's been both frustrating and exciting, though I think some progress was made, if only a little towards the end goal, though I'm probably getting ahead of myself here.

In terms of what I spent some time learning, I looked into EventSystems and InputModules within Unity. These are elements that control and manage the data from hardware/OS inputs for use within unity. Upon the creation of a Canvas, an event system is made that contains the Standalone Input Module and the Touch Input Module. The Standalone Input Module gets data from the mouse, keyboard, and or gamepad for use in the game while the touch input module does likewise for touch controls. One can create their own modified input modules and triggers, though the documentation seems to be lacking in this (something noted by Ralph Barbagallo on his blog).

Further inquiry and I began to learn more about event triggers, the way the GUI interacts with inputs, how gameobjects are handled by the systems, the different types of Unity behaviors, though it mostly wasn't too helpful in resolving the issue. What actually did end up helping is somewhat shameful though.

Yes everyone, to my surprise, the big issue with my GUI elements no being detected was a poor use of the box colliders attached to them. It turns out, that the box colliders I'd attached were VERY small and were hard to hit at all with the "false finger" I've created for the testing purposes. I found this out when I was moving the finger around in a playful manner and detected a debug log for "Trigger was detected" that I'd setup within my touchdetection script. I investigated more closely and found that the box collider was INCREDIBLY small as their scale seems to have been a 1,1,1 box but in relation to the GUI element. The GUI itself is 160 wide by 30 tall so a 1,1,1 ratio would basically require clicking a single pixel out in an area to properly hit. After enlarging the collider, triggers were easily detected and my head firmly planted itself across my desk. I imagine I must have been blushing out of the embarrassment but I think the pain of a good forehead knock was a sufficient distraction.

Anyhow, what's done is done and it's time to figure out my next course of actions. I'll probably end up creating a script for managing the size of the box colliders so they can resize along with the GUI elements for development convenience, but the main question at hand still remains of how I can get the collision data to not only interact with the menus, but interact with spacial awareness. I'm thinking of trying to place the GUI item's location from the screenspace or viewport to the worldspace, then subsequently using contact points from the colliders to determine which part of the GUI is being interacted with to make things work properly. I may have to create a custom module still to have the collisions and their locations serve as valid submit commands for things like the button and scroll wheel, but I'll know for sure tomorrow when I try it out.

I've learned a lot today. Hopefully it'll serve me well in the future. After all, the humiliation of today can be the fuel for tomorrow's triumph.

No comments:

Post a Comment