Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Smiley on April 09, 2014, 08:49:42 AM
-
Hey people,
I have to build a GUI which supports screen rotation. Not only that, the screen can be split between two players, each with there own (identical, but separate) GUI.
During this split, the users can pick which side of the screen they wish to be oriented at. However, when i take my entire GUI and flip it on it's side, and sometime even when upside down. Things go weird. Anchors show strange behavior and scaling goes wrong. Objects disappear due to that as well.
I have the idea that i am working at this problem a completely wrong way. Flipping the camera obviously doesn't do anything. And building the entire GUI like 6 times just to have 1 instance of each for every possible rotation angle and configuration, would just be weird.
Any advice on how to get at this problem would be greatly appreciated and thanks in advance,
Smiley
-
Anchoring to the camera should work fine but I would say don't rotate the camera. Adjust the camera's view rect instead. I can imagine all kind of weird stuff will happen if you want to rotate the camera independently of the UI, or rotate the entire UI independently from the camera that draws it if you happen to have stuff anchored inside. Not much I can advise about that other than the obvious "don't do it".
-
Hey, thanks for the reply.
Obviously rotating the camera doesn't work. and seperating camera from the ngui tree would break just about everything. I just want to create a GUI, which i can rotate per panel on the Z axis, without anything weird happening.
A lot of things like anchor and scales go all messed up when i try to accomplish this. (especially the progress bar)
Any advice on that?
Thanks in advance,
Smiley
-
I think your best bet is to render your UI to texture, then draw this texture. When you want to change the aspect ratio, do that by adjusting the camera's ortho size and/or view rect and rotating the final render texture into place.
This way your anchors will not be getting rotated. Only the final rendered texture will be rotated, so you won't run into any of these issues.
-
So if i get this right, i would create my GUI. Then use the camera to create a "render texture" (a texture that shows this camera) and put that in front of my 3D world camera, or another ngui camera?
This would work for rotation. Sadly, if i would scale the rendered texture, i think a lot of stuff would get malformed (if scaled on ratio's for screen ratio differences).
Any ideas on how to deal with both?
At any rate, this is already a great idea, since i can at least use this to solve my rotation issue, be it compromising ratio scaling to do so!
Thanks a lot,
Smiley
-
There is not much else I can suggest here as what you're trying to do is highly unusual and it's not something I've ever had to do.
-
Correct, this situation would only appear if you would want to make a unity game for touch table devices or big tablets. In which you would want to allow the player to pick on which side of they screen they take place.
It does not happen very often.
Thanks for your advice, and i will just see how far i can take this. Otherwise i would have to compromise somehow.
-
Starlink is playable on a tablet with more than one player. I've actually had many fun tabletop matches with a friend that way. But it didn't involve flipping any UIs, so I was lucky there.
-
True, if you have a omnidirectional GUI (images or icons that look the same no matter where you stand looking at the screen) or a GUI with fixed player positions at all times. This doesn't form a problem. It is when you try to do both, it just becomes a mess. I have thought up of a way to use your camera trick. If i can make NGUI still somehow "scale" with the resolution of the screen, which i think i can (make the camera used as normal, but hide the actual rendering of it, to then use the rendered texture, which is properly scaled.) The menu should then still be ''normally formed" instead of being stretched or squished.
So i will just try that out when i get there. Thanks again for the advice!
-
After trying around getting this to work. I made a render texture, and tried to make it show up properly (without rotating just yet).
The results were not amazing: (http://puu.sh/8iJ1S.png)
I am quickly running out of options, and i think this means that the GUI has to be redone in general, just to eliminate rotation as a whole.
NGUI is just not ment to have there GUI or camera rotated. Nor have it being rendered to a texture. Both just do not end well.
Anyone who has any new ideas is welcome, but i am close to giving this up.
Maybe the Unity GUI will support it in 2020 though? :P
Sincerely,
Smiley
-
Rendering to texture works just fine, same as drawing anything to a texture in Unity.
Based on your pic, you don't actually have any camera clearing color. Only depth. When you don't clear color, you get ghosting like that.
-
Ok, i found that out, next up. The GUI no longer scales with the camera ( i can see the camera, and even panel size change in the editor when i drag the width of the game view, however it doesn't actually scale the GUI anymore.) Any good reason for this, or a way to change that around? (By code if need be)
(http://puu.sh/8iLOA.png)
Thanks in advance,
Smiley
-
When you are rendering to texture, the texture has width and height. This effectively replaces the game window's width and height. The texture is square by default, and you are squishing it so that it's a rectangle.
-
Yes, That is correct. However it doesn't really give me the option with rendered texture. It is always square. Resulting in non square screens always looking stretched. Which doesn't help.
-
You can create a render texture with any size. You just have to do it through code rather than inspector.