UI Toolbox 徽标UI Toolbox
支持

本页为译文。技术支持和视频教程主要使用英语,内容以英文页面为准。 英文版

Alert

Alert 是留在布局中的消息,例如表单上方的警告。它有严重程度、图标、可选的标题、消息、可选的关闭按钮和操作按钮。对于会浮动并在一段时间后消失的消息,请改用通知。

Load game 界面,三个存档位上方有一条信息提示 Your progress saves at each campfireLoad game 界面,三个存档位上方有一条信息提示 Your progress saves at each campfire

<tb:Alert name="diskAlert" severity="Warning" title="Low disk space"
          description="The save folder has 120 MB left." closable="true">
    <ui:Button text="Free space" name="freeSpace" />
</tb:Alert>
var alert = root.Q<Alert>("diskAlert");
alert.Closed += () => Debug.Log("The user closed the alert");
if (disk.FreeMegabytes > 500) alert.Close(); else alert.Open();
成员 说明
Severity(severity) Info(默认)、Success、Warning 或 Error:Severity 的值。它设置图标和类 tb-alert--info、--success、--warning 或 --error。
Title(title) 消息上方的粗体一行。标题为空则不显示这一行。
Description(description) 消息。富文本标签有效。
Closable(closable) 显示 "×" 按钮。默认关闭。
Close()、Open()、IsOpen 隐藏警告、再次显示它,以及状态。关闭的警告仍留在层级中。在 UXML 中带 style="display: none;" 或由 USS 规则隐藏而开始的警告,在 Open() 之前处于关闭状态。
Closed Close 或关闭按钮隐藏警告时触发。

提示:

样式

类 元素
tb-alert 带图标、主体和关闭按钮的行,位于 --tb-color-surface-alt 上,左侧有 4 px 的边框。
tb-alert--info、--success、--warning、--error 严重程度。它设置左边框和图标的颜色:强调色、成功色、警告色或危险色。
tb-alert__icon 圆形图标标签,20 px。
tb-alert__body 带标题、消息和操作的列。
tb-alert__title、tb-alert__message 粗体标题和消息。两者都会换行。
tb-alert__actions 子元素所在的行,会换行。每个子元素有上边距。
tb-alert__close "×" 按钮(20 px)。它与通知的关闭按钮共用规则。

要用危险色填充错误警告:

.tb-alert--error { background-color: var(--tb-color-danger); }
.tb-alert--error .tb-alert__title,
.tb-alert--error .tb-alert__message {
    color: var(--tb-color-danger-text);
}

AlertDemo 场景展示了游戏界面中的警告:菜单的存档位、设置界面的检查、商店的购买、大厅的连接,以及任务日志的外观。