使用屏幕大小缩放 GUI.TextArea [英] Scaling GUI.TextArea with Screen Size

查看:20
本文介绍了使用屏幕大小缩放 GUI.TextArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缩放 GUI.TextArea.

代码块在 OnGui 函数中工作.但是当我改变屏幕尺寸时,textArea 不会在正确的位置和尺寸上.

(2017 - 请注意他们最近将措辞从空间"改为大小"...)

Unity 不小心在该菜单上设置了错误的默认选项.

在他们解决问题之前,务必记住选择按屏幕大小缩放".

其他选项无关紧要,几乎从未使用过.

2) 单击添加按钮",或添加您想要的任何元素:面板.滚动视图、滑块等

大功告成.

就这么简单.

对于给定的项目:要实现您所说的 POSITION,只需执行此操作...

选择与您相关的选项,可能是中间选项.

在你的脚本中有

 public 文本 hello

这将在您的检查器面板中为该脚本创建一个插槽(标记为hello").

一定要拖动物理.Text 单元(即,在画布"下面)到检查器中的那个槽.在代码中设置文本很简单:

 hello.text = "这里有一些文字";

就是这么简单.您可以在编辑器中设置字体的大小、形状、位置等,所见即所得.

请务必设置以下项目...

...因为你需要它们.干杯.

i'm trying to scale a GUI.TextArea.

the code block works in OnGui function. But when i change screen size , the textArea won't be on correct position and size.

first screen size

second screen size

is there any solution like Canvas.ScaleMode.ScaleToFit or should i recreate the GUI.TextArea?

Edit: I use button,some image and text in canvas and easily scale them with canvasScaler script. But the text object doesn't contain multiple line text so i create textarea with gui for display multiple line text.

解决方案

The UI system in unity is very easy to use...

1) click add canvas .. select "scale with screen size"

Important!!!!!!!!!!!!!

It is critical to select "scale with screen size".

(Note that this is in the "Canvas Scaler" section - it is NOT in the "Canvas" section.)

(2017 - note they recently changed the wording from "space" to "size"...)

Unity accidentally set the WRONG DEFAULT OPTION on that menu.

Until they fix the problem, it is essential to remember to select "scale with screen size".

The other options are irrelevant and almost never used.

2) click "Add Button", or add any element you want: panel. scroll view, slider, etc.

You're completely done.

It's that easy.

For a given item: to achieve what you say about POSITION, just do this ...

select the option relevant to you, probably middle one.

In your script have

  public Text hello

That will create a slot (labelled "hello") in your Inspector panel for that script.

be sure to drag the physical .Text unit (ie, underneath "Canvas") to that slot in the Inspector. To set the text, in code, is trivial:

    hello.text = "some text here"; 

it's that simple. You can set the size, shape, position, etc of the type in the editor, what you see is what you get.

Be sure to set the following items ...

... as you need them. Cheers.

这篇关于使用屏幕大小缩放 GUI.TextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆