Hey there -- I'm trying to figure out the best way to approach UI implementation using 2DToolkitUI and could use some guidance.
Let's start by saying that I'm building a 3D game (the standard camera is perspective) that targets mobile + PC -- variable screen size, aspect ratio, and pixel density all need to be accounted for, though for now I'll be happy to just use hi-res/hi-DPI assets for all targets.
I am looking to implement my always-on-screen UI using 2DToolkitUI. I figure the best way to do this is have a separate, ortho camera that only shows UI elements in screen space, and that it draws after the game camera draws the 3D world.
I dropped a tk2dcamera into my scene, set its Clear Flags to "don't clear", and am using the Culling Mask to draw only things in a new layer called "2DToolkitUI". Set the camera depth to 1 so that it draws after my standard perspective camera.
I then drop a BasicButton prefab into the scene, put it in my "2DToolkitUI" layer. Takes me some time to figure out where to position the button but I finally figure out how to get it on screen. This is where I start to get confused.
1. The button doesn't respond to clicks in game. It renders on top of the 3D world as intended but clicks are not received. Note that if I do this same work in a new, empty project, clicks are received just fine, so it must have something to do with my project's settings. Any idea where to look?
2. What's the best way to resize UI elements when placing them in the editor? I can resize the button graphic's "dimensions" in "pixel units" but these numbers don't seem to have any correlation with what I see on screen. I currently set this field 128x128 with a transform.scale on the BasicButton of 1x1 ... and the button is completely invisible. If I set the transform.scale up to 128x128, the button now appears to occupy 48x48 pixels in my 1024x768 window. Huh? I feel like I'm just randomly trying things here, what's the correct method?
3. I'm going to start with our HUD -- on-screen indicators for score, resource count, and a menu button. All of these elements want to be laid out relative to the corners of the screen. Is there a way to properly author this in-editor? Or do I need to perform the layout tasks in code?
Thanks in advance for your time and guidance!
Cheers,
David