Interaction Components 交互组件 UI系列4

Interaction Components 交互组件

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.3版本
参考链接:https://docs.unity3d.com/Manual/UIInteractionComponents.html

This section covers components in the UI system that handles interaction, such as mouse or touch events and interaction using a keyboard or controller.
本节介绍UI系统中处理交互的组件,如鼠标或触摸事件以及使用键盘或控制器进行交互。

The interaction components are not visible on their own, and must be combined with one or more visual elements in order to work correctly.
交互组件本身是不可见的,必须与一个或多个可视化元素组合才能正确工作。

Common Functionality 常用功能

Most of the interaction components have some things in common. They are selectables, which means they have shared built-in functionality for visualising transitions between states (normal, highlighted, pressed, disabled), and for navigation to other selectables using keyboard or controller. This shared functionality is described on the Selectable page.
大多数交互组件都有一些共同点。它们的基类是selectables,这意味着它们具有共用的内置功能,用于可视化状态之间的转换(正常、突出显示、按下、禁用),以及使用键盘或控制器导航到其他selectables。此共用功能在Selectable页面上进行了描述。

The interaction components have at least one UnityEvent that is invoked when user interacts with the component in specific way. The UI system catches and logs any exceptions that propagate out of code attached to UnityEvent.
当用户以特定的方式与组件交互时,交互组件至少有一个UnityEvent被调用。UI系统捕获并记录从附加到UnityEvent的代码传播出去的任何异常。

Button

A Button has an OnClick UnityEvent to define what it will do when clicked.
一个按钮有一个OnClick UnityEvent来定义它在被点击时会做什么。
Interaction Components 交互组件 UI系列4
See the Button page for details on using the Button component.

Toggle

A Toggle has an Is On checkbox that determines whether the Toggle is currently on or off. This value is flipped when the user clicks the Toggle, and a visual checkmark can be turned on or off accordingly. It also has an OnValueCHanged UnityEvent to define what it will do when the value is changed.
Toggle 有一个Is On复选框,用于确定切换当前是打开还是关闭。当用户单击切换时,该值会被翻转,并相应地打开或关闭一个可视复选标记。它还有一个OnValueCHanged UnityEvent来定义当值发生更改时它将做什么。
Interaction Components 交互组件 UI系列4

Toggle Group

A Toggle Group can be used to group a set of Toggles that are mutually exclusive. Toggles that belong to the same group are constrained so that only one of them can be selected at a time - selecting one of them automatically deselects all the others.
切换组可用于对一组互斥的切换进行分组。属于同一组的切换受到限制,因此一次只能选择其中一个——选择其中一个将自动取消选择所有其他选项。
Interaction Components 交互组件 UI系列4

Slider

A Slider has a decimal number Value that the user can drag between a minimum and maximum value. It can be either horizontal or vertical. It also has a OnValueChanged UnityEvent to define what it will do when the value is changed.
滑动条有一个十进制数值,用户可以在最小值和最大值之间拖动该数值。它可以是水平的,也可以是垂直的。它还有一个OnValueChanged UnityEvent来定义当值发生更改时它将做什么。
Interaction Components 交互组件 UI系列4

Scrollbar

A Scrollbar has a decimal number Value between 0 and 1. When the user drags the scrollbar, the value changes accordingly.
滚动条的十进制数值在0和1之间。当用户拖动滚动条时,值会相应地改变。

Scrollbars are often used together with a Scroll Rect and a Mask to create a scroll view. The Scrollbar has a Size value between 0 and 1 that determines how big the handle is as a fraction of the entire scrollbar length. This is often controlled from another component to indicate how big a proportion of the content in a scroll view is visible. The Scroll Rect component can automatically do this.
滚动条通常与滚动矩形和蒙版一起使用来创建滚动视图。滚动条的大小值在0到1之间,它决定了句柄在整个滚动条长度中所占的比例。这通常由另一个组件控制,以指示滚动视图中有多大比例的内容是可见的。滚动矩形组件可以自动做到这一点。

The Scrollbar can be either horizontal or vertical. It also has a OnValueChanged UnityEvent to define what it will do when the value is changed.
滚动条可以是水平的,也可以是垂直的。它还有一个OnValueChanged UnityEvent来定义当值发生更改时它将做什么。
Interaction Components 交互组件 UI系列4

Dropdown

A Dropdown has a list of options to choose from. A text string and optionally an image can be specified for each option, and can be set either in the Inspector
or dynamically from code. It has a OnValueChanged UnityEvent to define what it will do when the currently chosen option is changed.
下拉菜单有一个可供选择的选项列表。可以为每个选项指定文本字符串和图像,也可以在检查器中设置
或者从代码中动态生成。它有一个OnValueChanged UnityEvent来定义当当前选择的选项发生更改时它将做什么。
Interaction Components 交互组件 UI系列4

Input Field

An Input Field is used to make the text of a Text Element editable by the user. It has a UnityEvent to define what it will do when the text content is changed, and an another to define what it will do when the user has finished editing it.
输入字段用于使用户可编辑文本元素的文本。它有一个UnityEvent来定义当文本内容改变时它会做什么,还有一个UnityEvent来定义当用户完成编辑时它会做什么。
Interaction Components 交互组件 UI系列4

Scroll Rect (Scroll View)

A Scroll Rect can be used when content that takes up a lot of space needs to be displayed in a small area. The Scroll Rect provides functionality to scroll over this content.
当需要在小区域中显示占用大量空间的内容时,可以使用滚动矩形。滚动矩形提供了在此内容上滚动的功能。

Usually a Scroll Rect is combined with a Mask in order to create a scroll view, where only the scrollable content inside the Scroll Rect is visible. It can also additionally be combined with one or two Scrollbars that can be dragged to scroll horizontally or vertically.
通常,为了创建滚动视图,滚动矩形与蒙版相结合,其中只有滚动矩形内的可滚动内容是可见的。它还可以与一个或两个滚动条组合使用,可以拖动滚动条进行水平或垂直滚动。
Interaction Components 交互组件 UI系列4