UI Toolbox 徽标UI Toolbox
支持

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

AlertStrip

AlertStrip 是一排警报图标,如同大战略游戏中那样。每个图标是一种警报,例如闲置的工厂或补给不足。图标有表示严重程度的颜色、计数徽章,以及带详情的工具提示。点击图标会前往原因所在。右键点击会忽略这条警报。

城市警报的横向和纵向条带,每条都带严重程度颜色和数量城市警报的横向和纵向条带,每条都带严重程度颜色和数量

如何添加一个条:

<tb:AlertStrip name="alerts" />
<tb:AlertStrip
    name="cityAlerts"
    vertical="true"
    tooltip-placement="Right" />
var alerts = root.Q<AlertStrip>("alerts");

// Add an alert, or change it. The same id changes the same icon.
alerts.Set("supply", crateIcon, Severity.Warning, count: 2,
    title: "Low supply", details: "2 armies have low supply.",
        priority: 4);

// The count grows, and the alert becomes an error: the icon flashes and
// the notification sound plays
alerts.Set("supply", crateIcon, Severity.Error, 4, "Low supply",
    "4 armies have low supply.", 4);

// The cause is gone: the icon slides out
alerts.Remove("supply");

alerts.Clicked += id => ShowRegion(id);
alerts.Dismissed += id => snoozedUntil[id] = day + 5;

警报来自代码,所以条在 UI Builder 中是空的。在那里它显示虚线轮廓,内有 "AlertStrip: code sets the alerts"。

成员 说明
Set(id, icon, severity, count, title, details, priority) 添加警报 id,条中已有它时则更改它。返回 AlertStripItem。新图标滑入,其后的图标滑到新位置。
Remove(id) 移除警报。图标滑出,其后的图标滑入空位。条中没有该警报时返回 false。
Dismiss(id) 移除警报并触发 Dismissed,和右键点击一样。
Clear() 移除每条警报。
Get(id)、Contains(id) 某条警报的图标,或 null。条中有该警报时为 true。
Items、Count 按条的顺序排列的警报。正在滑出的图标不在列表中。
Clicked 用户点击图标,或在获得焦点的图标上按 Enter 或提交键时,以 id 触发。
Dismissed 用户右键点击图标,或在获得焦点的图标上按 Delete 或 Backspace 时,以 id 触发。
Vertical(vertical) 把图标排成一列,用于屏幕侧边的条。
TooltipPlacement(tooltip-placement) 工具提示显示的位置。默认是 Below,适合顶部的条。位于左侧的垂直条请用 Right。
FlashErrors(flash-errors) 让 Error 图标用 AttentionFlash 闪烁(默认 true)。
ErrorSound(error-sound) 警报变为 Error 时播放通知音(默认 true)。
Dismissible(dismissible) 允许用户忽略警报(默认 true)。
AlertStrip.Compare(a, b) 条的顺序。

AlertStripItem 是一个图标:

成员 说明
Id、Severity、Count、Title、Details、Priority、Icon 上一次 Set 的值。你也可以在该项上更改它们。
CountBadge 角上的 Badge。计数为 0 时隐藏它。计数超过 99 时显示 "99+"。
Tip ToolTip。Title 是它的页眉,Details 是它的文字。详情中的富文本标签有效。
Sequence 第一次 Set 的顺序。
IsRemoved 图标滑出期间为 true。

Severity 是 Info、Success、Warning 或 Error。Alert、NotificationBubble 和 Callout 使用同一个枚举。

严重程度 图标 徽章色调 工具提示
Info 强调色 Accent ToolTip.ACCENT_CLASS
Success 成功色 Success ToolTip.SUCCESS_CLASS
Warning 警告色 Warning ToolTip.WARNING_CLASS
Error 危险色,闪烁 Error ToolTip.ERROR_CLASS

提示:

样式

类 元素
tb-alert-strip 条:会换行的一行。
tb-alert-strip--vertical Vertical 开启的条:一列。
tb-alert-strip__item 一个图标:36 px 见方,带边框和圆角。指针下会稍微变大。
tb-alert-strip__item--info、--success、--warning、--error 严重程度。它设置边框颜色和图标的着色。
tb-alert-strip__item--error.tb-attention--on Error 图标的闪烁:危险色背景。
tb-alert-strip__icon 图片,22 px,用 -unity-background-image-tint-color 着色。
tb-alert-strip__count 计数徽章,一个角上的 Badge。
tb-alert-strip__item--hidden 滑入开始和滑出结束的位置:透明并向上偏移 12 px(垂直条中向左偏移 12 px)。
tb-alert-strip__item--anim-in、--anim-out 滑入和滑出的过渡。
tb-alert-strip__item--shift 图标滑到新位置期间的过渡,当它前面的图标出现或消失时。

要让图标更大:

.tb-alert-strip__item { width: 48px; height: 48px; }
.tb-alert-strip__icon { width: 32px; height: 32px; }

AlertStripDemo 场景展示了:带日期时钟的大战略条,以及城市建造游戏的垂直条。

SVG:Icon 是 Background。作为 VectorImage 导入的 SVG 与纹理一样可用。见图片:PNG 或 SVG。