unity3d 2d教程 uiroot2d 和uiroot3d有什么区别

Pages: [1]
Topic: UIRoot &(Read 48047 times)
on: November 20, :01 PM »
OverviewUIRoot always lies at the bottom of the NGUI UI hierarchy (or top, depending on how you look at it!)It's responsible for keeping the scale of the UI somewhat more manageable. Since widget coordinates are generally specified in pixels, a 800 by 400 widget will be 800 by 400 units, which is... quite large. UIRoot shrinks itself by the inverse of the screen's height, thus keeping the widgets small and easier to work with.& &UIRoot has several scaling styles for you to play with. Flexible style lets your UI always be in pixels, and a 300x200 widget will always take 300 by 200 pixels on the screen. This also means that viewing your UI on a low-res device will make your widgets appear rather large in size, and viewing your UI on a high-res device will make your widgets appear small. On the plus side, with this setting your UI will always remain as crisp as possible.Constrained is the exact opposite of that. When the UIRoot is set to this setting, your screen will always remain the same size as far as NGUI is concerned, regardless of the actual screen size. This means that if a 300x200 widget takes 25% of your screen with the resolution of , it will still take 25% of the screen when you drop your resolution to . If you don't want to worry about how your UI will look at different screen sizes and you don't care much about making it as crisp as possible, choose this setting. Don't forget to set the Content dimensions setting when choosing this option.You can further refine the constrain by choosing whether the content will Fit on the screen or whether it will Fill the screen (when 'fit' is off). Think of it as your Desktop wallpaper. When you choose the Fit method, the wallpaper will always be fully visible on the screen, where if you go with a Fill method, it will always completely fill the screen while maintaining its aspect ratio. Same idea here. See the
for more information.ConstrainedOnMobiles setting is a combination of the two. It will behave as if the setting was &Flexible& on desktop builds, and it will act as if the size was &Constrained& when targeting mobile platforms.If you go with the Flexible option, don't forget to set the Minimum and Maximum Height values. These values are used to keep your virtual screen size within &sane& values. So for example if your UI is set to Pixel Perfect mode, and the Minimum Height is set to 720, then some player tries to run your application with the resolution of 800 by 600, the UI will behave as if the setting was &Constrained& with the Content Height set to 720.Shrink Portrait UI option is designed to adjust your UI's size when the screen is in Portrait mode. It's similar to a height-based adjustment, but it will take the width into consideration as well.Pro-TipThe UIRoot always scales itself by 2 / ScreenHeight, where ScreenHeight is either the actual screen height (in pixel perfect mode), or the manual height that you've specified (in fixed size mode). In doing so, the camera that draws the UI can remain at Orthographic Size of 1.If you don't need the auto-scaling functionality of the UIRoot, you can get rid of this component altogether.Class DocumentationIf you have a question regarding this component or would like me to clarify something, just post a reply here.
« Last Edit: August 22, :24 AM by ArenMook »
« Reply #1 on: December 18, :06 AM »
I suggest to have a scale factor which is used to scale up the gameobject that UIRoot is attached to and to set NGUI camera's size property. For example I am using NGUI anchoring with rage tool, I choose the screen height to be 640, scaling style is FixedSize, and the whole NGUI system is too small compared to unity unit. The transform's scale of UIRoot attached-gameobject is set to 0. which is very small and Rage tool is messed up with that tiny scale. Thus I modified the code a little bit: in UIRoot.cs:public float scale = 1000;protected virtual void Start ()&&&{&&&&&&UIOrthoCamera oc = GetComponentInChildren&UIOrthoCamera&();&&&&&&if (oc != null)&&&&&&{&&&&&&&&&Debug.LogWarning(&UIRoot should not be active at the same time as UIOrthoCamera. Disabling UIOrthoCamera.&, oc);&&&&&&&&&Camera cam = oc.gameObject.GetComponent&Camera&();&&&&&&&&&oc.enabled =&&&&&&&&&if (cam != null) cam.orthographicSize = 1f *&&&&&&}&&&&&&else Update();&&&}void Update ()&&&{#if UNITY_EDITOR&&&&&&if (!Application.isPlaying && gameObject.layer != 0)&&&&&&&&&UnityEditor.EditorPrefs.SetInt(&NGUI Layer&, gameObject.layer);#endif&&&&&&if (mTrans != null)&&&&&&{&&&&&&&&&float calcActiveHeight = activeH&&&&&&&&&if (calcActiveHeight & 0f )&&&&&&&&&{&&&&&&&&&&&&float size = 2f / calcActiveH&&&&&&&&&&&&&&&&&&&&&&&&Vector3 ls = mTrans.localS&&&&&&&&&&&&&&&if (!(Mathf.Abs(ls.x - size) &= float.Epsilon) ||&&&&&&&&&&&&&&&!(Mathf.Abs(ls.y - size) &= float.Epsilon) ||&&&&&&&&&&&&&&&!(Mathf.Abs(ls.z - size) &= float.Epsilon))&&&&&&&&&&&&{&&&&&&&&&&&&&&&mTrans.localScale = new Vector3(size * scale, size * scale, size * scale);&&&&&&&&&&&&}&&&&&&&&&}&&&&&&}&&&}I am not sure if it break the other code as now It work just fine to me. Hope to have this scale factor variable in the next version.
« Reply #2 on: December 20, :23 PM »
Don't use UIRoot in your case. You don't need it. Remove it, and set the ortho camera's size yourself.
« Reply #3 on: January 07, :52 AM »
I think UIRoot should not scale the whole thing down by default, It's very weird to have a root GameObject at some 0.0000xx scale. I belive most of other people would like it better to see UIRoot at scale (1,1,1) - It's what we expect for the first time using a GUI library (and 2D Toolkit is using that). Scaling everything down 0.000xxx will make people confuse as they don't understand what is that value about (and they can't change it). Keeping Orthorgraphic size at 1 is not needed, just set it to Screen.height / 2 ... thanks god I found this post after several years using NGUI, I thought that scale can not be change and I even wrote a script / modify UIRoot's script to prevent the changes. I didn't know that NGUI can live without UIRoot as I belive UIRoot should be the root of all UI, and no UI could survive without UIRoot.thanks, I got to remove all the UIRoot component now&
« Reply #4 on: January 14, :49 PM »
Is there a reason there isn't a width property for Pixel Perfect or FixedSize? The setup works well for keeping everything in line vertically, but completely ignores the horizontal. As a result, shrinking a screen's resolution leaves a big blank part off to the side, or a larger resolution leaves content hanging off the right side of the screen.A width setting that controls sizingin the same fashion would be very useful.
« Reply #5 on: January 14, :25 PM »
That's what anchors are for.If you just have it be based on width AND height, then you will end up with skewed UIs. Think of how poor the UI will look like if you designed it with a 4:3 aspect ratio, then tried to display it stretched on a 25:9? All your squares and circles will be horribly stretched rectangles and ovals.You need to use anchors instead. Check the very first example that comes with NGUI, then watch the video on the 3.0.7 anchoring system.
« Reply #6 on: February 11, :28 PM »
I'm experiencing a significant problem where I can't work with NGUI widgets unless they're under a UIRoot. In previous versions, I could just have a UILabel in the world somewhere (on the ground, or attached to some object). Now, as soon as I add one to some prefab, it immediately creates a UIRoot hierarchy with a UICamera, then parents my prefab to the UI structure. I'm unable to remove the UIRoot in any way -- if I try to move my prefab back out of the hierarchy, I get a bunch of exceptions in the editor.I tracked this down to the CreatePanel call, which eventually forces a CreateUI if there isn't one. As a test, I tried disabling this functionality, but then the widget doesn't render at all. Is there some new way of having free-floating UIWidgets in the scene? Or should I have dozens of mini UIRoots all over my scene if I want to have NGUI elements sprinkled around?
« Reply #7 on: February 11, :16 PM »
It doesn't need to be under a UIRoot.As long as a widget finds a UIPanel on a parent, it's fine. So make sure you have a panel above your widgets.
« Reply #8 on: April 09, :27 AM »
About setting width - I think I understand completely why there is no such thing, but shouldn't be there also a way to setup minimal width? My problem is that what if I change screen so it's width is small while height is big (screen will look like a pillar or something). The screen size would be configured according height, but because there wouldn't be much horizontal space, everything would break even when using anchors. I'm pretty much aware that in that case the enforcing minimal width could make height greater then maximal height (if we would still keep correct aspect ratio - which is IMHO priority number one) - but I think it's better solution then none at all...
« Reply #9 on: April 09, :39 AM »
Set &Shrink Portrait UI& on the UIRoot, Aithoneku.
« Reply #10 on: June 24, :22 AM »
I have a hierarchy like the following,A (UIRoot)&- BC (UIRoot)&- DWhen I destroy A, the D is resized (UIWidget size) automatically.Why does this happen?I checked anchor target of D, but it suggests that the target is C.The only way I found to avoid this is separating the two UIRoot placingon different layers.
« Last Edit: June 24, :56 AM by t_n »
« Reply #11 on: June 24, :05 AM »
You should be using different layers if you have different UIRoots. Otherwise organize your UI like this:UIRoot- B- D
« Reply #12 on: June 24, :17 AM »
Ok, thank you Aren.
« Reply #13 on: August 28, :15 PM »
Hi!This question is more like clarification.I'm using Constraint option to preserve rations on different resolutions. So 1st screenshot is from 22'' desktop, second one - from laptop. As we can see latter one is blurry. So if I want my UI to be as crisp as possible I should forgo Constraint mode and use Flexible mode?Thanks, Artem.
« Reply #14 on: August 30, :37 AM »
Yes. Flexible mode is the only way to always have crisp looking UIs on all devices.
Pages: [1]NGUI的UIROOT怎么调整?_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:61,090贴子:
NGUI的UIROOT怎么调整?收藏
在GAME视图为480*854,高宽比为1.78但在scene视图中,却只有473*480,比例差距也太大了,怎么调整?
unity3d,学习专业的游戏引擎-unity3d.达内游戏主程培训,一般要4-16周,就可掌握.变高端游戏达人-薪资翻番.unity3d费用根据培训课时定,上海官方咨询-unity3d.
难倒一定要我
吗?安安,帮帮我!
新版NGUI中,GAME视图和SCENE视图中,是有所差别,以GAME视图为准。SCENE视图里你动一下一些NGUI元素,就能和GAME同步了。因为你选用的是PixelPerfect模式,所以是按照当前视图的尺寸来调整UIRoot的比例的。所以有差距。
PlayerSetting里面设置一下你要的分辨率就行了呀~~~
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或NGUI中的UIRoot要不要做成DontDestroyOnLoad()?_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:61,090贴子:
NGUI中的UIRoot要不要做成DontDestroyOnLoad()?收藏
正在学习Unity3D,选用NGUI做界面。做了两个关卡,先是负责登录选择关卡和英雄等的,然后是战斗关卡。这两个关卡的UI是不一样的,在关卡切换时UI也需要切换。我的战斗关卡可能包含多个场景,对应Unity中的Scene。我现在是把UIRoot做成DontDestroyOnLoad(...);这样在战斗关卡中切换场景时UI可以一直保留,但问题是当我由战斗关卡切换到初始登录关卡时得自己手动负责场景切换时UI的加载和卸载。貌似有点麻烦,想问问大家有没有更好的解决方案?
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或

我要回帖

更多关于 unity uiroot 的文章

 

随机推荐