标题: [Unity 组件参考手册]组件:资源组件之字体 [打印本页] 作者: . 时间: 2013-1-24 20:31 标题: [Unity 组件参考手册]组件:资源组件之字体 Fonts can be created or imported for use in either the GUI Text or the Text Mesh Components.字体可以在GUI文本(GUI Text)或文本网格(Text Mesh)组件创建或导入来使用。
[Importing ***e Type Font files (.ttf) 导入***e Type字体文件(.ttf)]To add a font to your project you need to place the .ttf file in your Assets folder. Unity will then automatically import it. You have to make sure that the font has a .ttf extension otherwise Unity will not recognize it.要添加一种字体到您的项目中,你需要将.ttf文件放到你的资源文件夹。然后Unity将自动导入。你必须确保字体的扩展名是.ttf,否则Unity不能识别。To change the Size of the font, highlight it in the Project View and you have a number of options in the Import Settings in the Inspector.要改变字体的大小(Size ),在项目视图中选中这个字体,然后在检视面板的导入设置会有很多选项。(改变Font Size的数值即可改变字体的大小)
Import Settings for a font 字体的导入设置------------------------------------------------------------------------ Font Size 字体大小
The size of the font, based on the sizes set in any word processor
字体的大小,基于任何文字处理器中设置的大小
Character 字符
The text encoding of the font. You can force the font to display only upper- or lower-case characters here Setting this mode to Dynamic causes Unity to use the underlying OS font rendering routines (see below).
字体的文本编码。您可以强制字体只有大写或小写字符在这里显示,设置此模式为动态(Dynamic),Unity会使用底层操作系统的字体渲染例行程序(见下文)。
2.x font placing
2.x字体铺设
Unity 3.x uses a more typographically correct vertical font placement compared to 2.x. We now use the font ascent stored in the ***etype font data rather than computing it when we render the font texture. Ticking this Property causes the 2.x vertical positioning to be used.
Unity 3.x相比起2.x,使用在排字上更准确的垂直字体布置,我们现在可以使用存储在***eType字体数据的字体上升,而不是在渲染字体纹理时计算它。选中此属性将会使用2.x的垂直定位。------------------------------------------------------------------------ Import Settings specific to non-dynamic fonts
非动态(non-dynamic)特有的导入设置(Import Settings)------------------------------------------------------------------------ Font Rendering 字体渲染
The amount of anti-aliasing applied to the font.
应用的字体,消除锯齿的的数量------------------------------------------------------------------------ Import Settings specific to dynamic fonts
动态(dynamic)字体特有的导入设置(Import Settings) Style 样式
The styling applied to the font, one of Normal, Bold, Italic or BoldAndItalic.
应用到的字体的式样,正常(Normal),粗体(Bold),斜体(Italic)或斜粗体(BoldAndItalic)。
Include Font Data 包含字体数据
This setting controls the packaging of the font when used with Dynamic font property. When selected the TTF is included in the output of the build. When not selected it is assumed that the end user will have the font already installed on their machine. Note that fonts are subject to copyright and you should only include fonts that you have licensed or created for yourself.
此设置控制使用动态字体属性时的字体的包装。当选上,TTF是包含在编译输出。未选中时,它是假设最终用户在他们的机器上已经安装字体。请注意,字体存在着版权相关约束,你应该只包括您已获得许可或为自己创造的字体
Font Names 字体名
Only available when Include Font Data is not selected. Enter a comma-separated list of font names. These fonts will be tried in turn from left to right and the first one found on the gamers machine will be used.
当没有选中包含字体数据(Include Font Data)时。输入的字体名称用逗号分隔的列表。这些字体将尝试从左至右依次在玩家机器上查找,使用最先找到的那个字体。------------------------------------------------------------------------ After you import the font, you can expand the font in Project View to see that it has auto-generated some assets. Two assets are created during import: "font material" and "font texture".在导入的字体后,你可以在项目视图中展开字体,看到它自动生成的部分资源。两个资源在导入过程中创建:"字体材质(font material)"和"字体纹理(font texture)"。
[Dynamic fonts 动态字体]Unity 3.0 adds support for dynamic font rendering. When you set the Characters drop-down in the Import Settings to Dynamic, Unity will not pre-generate a texture with all font characters. Instead, it will use the OS built-in font rendering to create the texture on the fly. This has the advantage that it can save in download size and texture memory, especially when you are using a font which is commonly included in user systems, so you don't have to include the font data, or when you need to support asian languages or large font sizes (which would make the font textures very large using normal font textures). It has the disadvantage that font rendering may not look exactly the same on all user machines (especially between mac and windows machines, or when a font is not installed and a fallback font is used), and that it can occasionally cause slowdowns as the font textures are generated for the characters needed on screen.Unity 3.0增加了支持动态字体渲染。当你在导入设置的字符(Characters )下拉菜单设置为动态(Dynamic),Unity将不会预先生成一个与所有字体的字符纹理。相反,它会使用操作系统内置的字体渲染实时来创建的纹理。这样做的好处,它可以保存下载的大小和纹理内存,尤其是当你使用通常在用户系统中的字体,所以你不必包括字体的数据,或当你需要支持亚洲语言或较大的字体大小(使用正常字体纹理,使字体的纹理非常大)。它的缺点,字体渲染未必所有的用户机器上看起来完全是相同的(尤其是Mac和Windows计算机之间,或当一个字体未安装和使用一个备用的字体),并且,在生成屏幕上所需要的字符字体纹理,有时可能会导致速度变慢。Dynamic fonts are currently only supported on Desktop platforms (Mac and Windows).动态字体是目前只支持台式机平台(Mac和Windows)。
[Unicode support]Unity has full unicode support. Unicode text allows you to display German, French, Danish or Japanese characters that are usually not supported in an ASCII character set. You can also enter a lot of different special purpose characters like arrow signs or the option key sign, if your font supports it.Unity有完整的Unicode支持。 Unicode文本允许您显示德国,法国,丹麦或日本等通常不支持ASCII字符集的字符。您还可以输入很多不同的特殊用途字符,像箭头标志或选项的关键标志,如果你的字体支持。To use unicode characters, choose either Unicode or Dynamic from the Characters drop-down in the Import Settings. You can now display unicode characters with this font. If you are using a GUIText or Text Mesh, you can enter unicode characters into the Component's Text field in the Inspector. Note that the Inspector on Mac may not show the unicode characters correctly.要使用Unicode字符,选择导入设置字符下拉菜单为Unicode 或动态(Dynamic )。现在,您可以用这种字体显示Unicode字符。如果您使用的是GUI文本(GUIText) 或文本网格( Text Mesh),您可以在检视面板输入Unicode字符到组件的文本字段( Text field)。请注意,在Mac上检视面板可能不能正确显示Unicode字符。You can also use unicode characters if you want to set the displayed text from scripting. The Javascript and C# compilers fully support Unicode based scripts. You simply have to save your scripts with UTF-16 encoding. In Unitron, this can be done by opening the script and choosing Text->Text Encoding->Unicode (UTF 16). Now you can add unicode characters to a string in your script and they will display as expected in UnityGUI, a GUIText, or a Text Mesh. On the PC where UniSciTE is used for script editing save scripts using the UCS-2 Little Endian encoding.如果你想在脚本设置显示的文本,您也可以使用Unicode字符。 JavaScript和C#编译器完全支持基于Unicode的脚本。您只需将您的脚本保存为UTF - 16编码。在Unitron中,可以通过打开脚本,并选择文字 - >文字编码 - > Unicode(UTF16)(Text->Text Encoding->Unicode (UTF 16))完成。现在您可以在你的脚本添加Unicode字符到字符串,他们会如预期在UnityGUI,GUI文本(GUIText)或文本网格(Text Mesh)显示。在PC机上, UniSciTE 是用于编辑脚本保存脚本,使用UCS- 2 Little Endian编码。
[Changing Font Color 改变字体颜色]There are different ways to change the color of your displayed font, depending on how the font is used.有不同的方式来改变字体显示颜色,这取决于如何使用字体。
[GUIText & Text Mesh 图形用户界面文本 和 文本网格]If you are using a GUIText or a Text Mesh, you can change its color by using a custom Material for the font. In the Project View, click on Create->Material, and select and set up the newly created Material in the Inspector. Make sure you assign the texture from the font asset to the material. If you use the built-in GUI/Text Shader shader for the font material, you can choose the color in the Text Color property of the material.如果您使用的是图形用户界面文本(GUIText)或文本网格(Text Mesh),您可以通过使用一个自定义字体材质改变其颜色。在项目视图中点击创建- >材质(Create->Material,),并在检视面板选择和设置新创建的材质。确保你从字体资源为材质指派了的纹理。如果您使用内置的GUI /文本着色器(Text Shader)为字体材质着色,你可以在材质的文本颜色(Text Color)属性选择颜色。
[UnityGUI 图形用户界面]If you are using UnityGUI scripting to display your font, you have much more control over the font's color under different circumstances. To change the font's color, you create a GUISkin from Assets->Create->GUI Skin, and define the color for the specific control state, e.g. Label->Normal->Text Color. For more details, please read the GUI Skin page.如果您使用的是Unity图形用户界面(UnityGUI)脚本来显示您的字体,你可以控制更多不同的情况下字体的颜色。要更改字体的颜色,从资源 - >创建 - >图形用户界面皮肤(GUISkin)(Assets->Create->GUI Skin)创建一个GUISkin ,并定义为特定的控制状态,例如标签 - >一般 - >文字颜色(Label->Normal->Text Color)。有关详细信息,请阅读GUI皮肤页面(GUI Skin page)。
[Hints 提示] To display an imported font select the font and choose GameObject->Create Other->3D Text.
要显示导入的字体,选中字体和选择游戏对象 - >创建其他 - >3D文本(GameObject->Create Other->3D Text.)。
Using only lower or upper case characters reduces generated texture size.
使用仅小写或大写字符能降低生成纹理大小。
The default font that Unity supplies is Arial. This font is always available and does not appear in the Project window. On the editor this font is treated as a Dynamic font so all characters it contains can be used. When used on a mobile device, however, this default font is treated as an ASCII Default Set font. This means that only ASCII characters can be displayed using this font on the mobile devices. To display, for example, CJK characters on the mobile devices please use your own font and mark it as Unicode.
默认的字体,Unity提供的是Arial。这种字体是始终可用并没有出现在项目窗口。在编辑器中,字体被视为动态(Dynamic )字体,所以它包含的所有字符可以使用。然而在移动设备上使用时,默认的字体是被视为ASCII默认设置(ASCII Default Set)字体。这意味着,只有ASCII字符可以在移动设备上显示,使用此字体。例如,在移动设备上显示CJK字符,请使用自己的字体和标记为Unicode。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/