富文本 Rich Text

Date:2013-08-02 04:32
The text for GUI elements and text meshes can incorporate multiple font styles and sizes. The GUIStyle, GUIText and TextMesh classes have a Rich Text setting which instructs Unity to look for markup tags within the text. The Debug.Log function can also use these markup tags to enhance error reports from code. The tags are not displayed but indicate style changes to be applied to the text.

这种文本用于GUI元素和文本网格可以结合多种字体类型和大小。 GUIStyle, GUIText 和 TextMesh类都有富文本设置,能指示unity寻找文本内含有的标记标签。Dubug.Log也可以用这些标记标签来增强代码报告错误的能力。这些标签不显示,而是显示应用到文本的风格变化。

Markup format 标记格式

The markup system is inspired by HTML but isn’t intended to be strictly compatible with standard HTML. The basic idea is that a section of text can be enclosed inside a pair of matching tags:-

该标记系统的灵感来源于HTML但不打算要严格兼容标准的HTML。其基本思路是,一对匹配的标签里面可以包含一部分文字:

We are <b>not</b> amused

As the example shows, the tags are just pieces of text inside the “angle bracket” characters, < and >. The text inside the tag denotes its name (which in this case is just b). Note that the tag at the end of the section has the same name as the one at the start but with the slash / character added. The tags are not displayed to the user directly but are interpreted as instructions for styling the text they enclose. The b tag used in the example above applies boldface to the word “not”, so the text will appear onscreen as:-

示例所示,标签只是“尖括号”和文本,< 和 >。标签内的文本表示的名字(在这个示例中就是b)注意:这个结尾部分的标签和开头那个名字一样但带有/符号。该标签不直接显示给用户但是诠释为它们扩起来的文字风格,即把not用b括起来,在例子中的b标签在单词“not”上应用粗体字,所以这个文本将会以如下形式出现:

We are not amused

A marked up section of text (including the tags that enclose it) is referred to as an element.

已标记的文本块(包括标签括入的)被作为一个元素 如not

Nested elements 嵌套元素

It is possible to apply more than one style to a section of text by “nesting” one element inside another

通过嵌套一个元素到另一个元素里面来应用多种样式到一个文本块这个是可以的。

We are <b><i>definitely not</i></b> amused

The i tag applies italic style, so this would be presented onscreen as

i标签应用斜体风格,所以将会以如下形式出现在屏幕上:

We are definitely not amused

Note the ordering of the ending tags, which is in reverse to that of the starting tags. The reason for this is perhaps clearer when you consider that the inner tags need not span the whole text of the outermost element

注意结束标签的顺序,与起始标签顺序相反。这样做的原因是帮助你更清晰的考虑内部标签不必跨越整个文本的最外层元素。(标签不能交叉包含,只能一对标签包含另一对;而一对标签不能只包含另一对标签的一部分。)

We are <b>absolutely <i>definitely</i> not</b> amused

which gives 显示为:

We are absolutely definitely not amused

Tag parameters 标签参数

Some tags have a simple all-or-nothing effect on the text but others might allow for variations. For example, the color tag needs to know which color to apply. Information like this is added to tags by the use of parameters:-

某些标签有一些简单的效果,开始标签可以有一些参数,例如,color标记需要知道应用哪个颜色。像这个在开始标签应用参数:

We are <color=green>green</color> with envy

Note that the ending tag doesn’t include the parameter value. Optionally, the value can be surrounded by quotation marks but this isn’t required.

注意结尾标签不包括参数素值。参数值可以由双引号包起来,但是这不是必需的。。

Supported tags 支持的标签

The following list describes all the styling tags supported by Unity.

下面的列表描述所有unity支持的标签样式。

b

Renders the text in boldface.

呈现粗体文本。

We are <b>not</b> amused

i

Renders the text in italics.

呈现斜体文本。

We are <i>usually</i> not amused

size 大小

Sets the size of the text according to the parameter value, given in pixels.

根据给定的参数值,以像素为单位设定的文字大小。

We are <size=50>largely</size> unaffected

Although this tag is available for Debug.Log, you will find that the line spacing in the window bar and Console looks strange if the size is set too large.

虽然这个标签是Debug.Log看得到的,如果设置过大,你将会发现窗口栏和控制台的大小看起来很奇怪。

color 颜色

Sets the color of the text according to the parameter value. The color can be specified in the traditional HTML format

根据参数值设置文本颜色,颜色值可以用传统的HTML格式指定

#rrggbbaa

…where the letters correspond to pairs of hexadecimal digits denoting the red, green, blue and alpha (transparency) values for the color. For example, cyan at full opacity would be specified by

字母对应于对十六进位数字,表示红色,绿色,蓝色和alpha(透明度)值的颜色。例如,青色完全不透明:

<color=#00ffffff>...

Another option is to use the name of the color. This is easier to understand but naturally, the range of colors is limited and full opacity is always assumed.

另一种选择是使用的颜色名称。这是比较容易理解且自然,颜色的范围是有限的,总是假定完全不透明。

<color=cyan>...

The available color names are given in the table below.

material 材质

This is only useful for text meshes and renders a section of text with a material specified by the parameter. The value is an index into the text mesh’s array of materials as shown by the inspector.

这仅用于文本网格并渲染具有材料参数所指定的一段文字。该值是文本网格显示在检视面板材质数组的索引。

We are <material=2>texturally</material> amused

quad 嵌入

This is only useful for text meshes and renders an image inline with the text. It takes parameters that specify the material to use for the image, the image height in pixels, and a further four that denote a rectangular area of the image to display. Unlike the other tags, quad does not surround a piece of text and so there is no ending tag - the slash character is placed at the end of the initial tag to indicate that it is “self-closing”.

这仅用于文本网格和在文本内嵌图像。它的参数,material是用于图片,图片的高度以像素为单位,另外四个标参数表示一个用于显示图像的矩形区域。不像其他标签,quad不用环绕文字所以没有结束标签-斜杠符号放置在开始标签的结尾表明它是“自封闭的”。

<quad material=1 size=20 x=0.1 y=0.1 width=0.5 height=0.5 />

This selects the material at position in the renderer’s material array and sets the height of the image to 20 pixels. The rectangular area of image starts at given by the x, y, width and height values, which are all given as a fraction of the unscaled width and height of the texture.

该行代码意思是材质的位置在渲染器的材质数组,同时设置图像高度为20像素。用于显示图像的矩形区域初始位置由X、Y、width和height的值提供,这些参数很适用于那些宽和高不成比例的图片。

Unity3d学习笔记 RichText相关推荐

  1. Unity3D 学习笔记3——了解U3D引擎的操作面板和各种工具

    Unity3D 学习笔记3--了解U3D引擎的操作面板和各种工具 在完成了Unity的安装破解之后,我们接下来要做的当前是启动这个引擎,然后学会如何去使用它为我们提供的各种工具,这也是上手任何一个软件 ...

  2. Unity3D 学习笔记4 —— UGUI+uLua游戏框架

    Unity3D 学习笔记4 -- UGUI+uLua游戏框架 使用到的资料下载地址以及基础知识 框架讲解 拓展热更过程 在这里我们使用的是uLua/cstolua技术空间所以提供的UGUI+uLua的 ...

  3. Unity3D学习笔记6——GPU实例化(1)

    文章目录 1. 概述 2. 详论 3. 参考 1. 概述 在之前的文章中说到,一种材质对应一次绘制调用的指令.即使是这种情况,两个三维物体使用同一种材质,但它们使用的材质参数不一样,那么最终仍然会造成 ...

  4. Unity3D学习笔记8——GPU实例化(3)

    文章目录 1. 概述 2. 详论 2.1. 自动实例化 2.2. MaterialPropertyBlock 3. 参考 1. 概述 在前两篇文章<Unity3D学习笔记6--GPU实例化(1) ...

  5. unity3d 学习笔记四 skybox(天空盒) light(光源) halo(光晕)

    Unity3D学习笔记(四)天空.光晕和迷雾 六年前第一次接触<魔兽世界>的时候,被其绚丽的画面所折服,一个叫做贫瘠之地的地方,深深印在我的脑海里.当时在艾泽拉斯大陆还不能使用飞行坐骑,试 ...

  6. Unity3D学习笔记:粒子特效参数

    Unity3D学习笔记:粒子特效参数含义 转载 https://blog.csdn.net/asd237241291/article/details/8433534 粒子特效 粒子系统检视面板 初始化 ...

  7. Unity3D学习笔记12——渲染纹理

    文章目录 1. 概述 2. 详论 3. 问题 1. 概述 在文章<Unity3D学习笔记11--后处理>中论述了后处理是帧缓存(Framebuffer)技术实现之一:而另外一个帧缓存技术实 ...

  8. Unity3D学习笔记(二、小球滚动吃金币)

    源码:键盘方向键操作小球滚动吃金币Unity3D源码 下篇:Unity3D学习笔记(三.小球跑酷) 一.颜色材质球创建  二.Plane平板创建 三.围墙 同理二,新建Cube,并调整属性,设立围墙 ...

  9. Unity3D学习笔记3——Unity Shader的初步使用

    文章目录 1. 概述 2. 详论 2.1. 创建材质 2.2. 着色器 2.2.1. 名称 2.2.2. 属性 2.2.3. SubShader 2.2.3.1. 标签(Tags) 2.2.3.2. ...

最新文章

  1. jquery如何判断div是否隐藏
  2. devc 无法编译循环语句_鸡生蛋还是蛋生鸡?详解第一个编译器是怎么来的~
  3. boost::safe_numerics模块实现检测到错误表达式评估的测试程序
  4. new Random().Next(1, 100); 多线程同时执行结果很高概率相同,
  5. Flutter入门:dart基础
  6. C语言之从内存角度理解不同类型的变量
  7. Java福尔摩斯的约会大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧 3485djDkxh4hhGE 2984akDfkkkkggEdsb shgsfdk dHyscvnm”。大侦探很快就明白了
  8. /deep/使用方式方式;/deep/无效; ::v-deep和>>>使用;
  9. 编译pjsip2.1.0 vidgui程序时,xlib保错问题
  10. sklearn——AdaBoost应用
  11. APScheduler Scheduler
  12. 小程序秒杀活动服务器,一套实用的小程序秒杀活动方案,亲这边建议你收藏哦...
  13. PAT甲级 1017 Queueing at Bank
  14. scara工业机器人外观_SCARA工业机器人研究现状
  15. Cortex-M3/M4内核处理器一次中断事件可能产生两次中断问题
  16. 如何成为一名优秀的测试/开发程序员?专注谋定而后动......
  17. android 拨打电话 发送短信 权限,Android中发送短信和拨打电话
  18. 避免选中页面文字或者内容时出现蓝色背景
  19. JavaScript系列之高级篇(2)
  20. 基于Springboot和Idea的医院管理系统(挂号、缴费、取药、住院) 毕业论文+项目源码及数据库文件+包远程安装配置+代码讲解

热门文章

  1. 基于Java实现的汽车租赁管理系统、SSM/SpringBoot两个版本都有+mysql汽车出租系统实现
  2. java读取json文件_Java 读取Json文件内容
  3. THREE.JS镜头随鼠标晃动效果
  4. Tomcat闪退问题解决
  5. 基于多时间尺度的灵活性资源优化配置 电力系统的调度优化,通过对电负荷和热负荷的优化分配,实现电力系统的经济运行和能源的高效利用
  6. repo 切换manifest
  7. 【cuda安装教程】GTX1050Ti+win10+cuda9.0+cudnn7.4.1安装过程记录
  8. 业内指路共享软件:更多机会在移动和海外市场(二)
  9. 小程序 rich-text 不支持 section 标签的情况
  10. 【luogu 11.8 队内赛 】【暴力】T1 Lyrith -迷宮リリス-