UI Toolbox 徽标UI Toolbox
支持

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

CircleLayout

UIToolbox 中的 CircleLayout 是一个布局容器,把子元素放在圆或圆弧上:径向菜单、技能槽的环、由按钮组成的表盘。它用 C# 布局,所以在每个 Unity 6 版本中都能用,第一次布局之后不产生垃圾。

一个把六个按钮分布在整个圆上的 CircleLayout,和另一个把五个按钮放在圆弧上的 CircleLayout一个把六个按钮分布在整个圆上的 CircleLayout,和另一个把五个按钮放在圆弧上的 CircleLayout

<tb:CircleLayout radius="90" style="width: 260px; height: 260px;">
    <ui:Button text="1" />
    <ui:Button text="2" />
    <ui:Button text="3" />
    <ui:Button text="4" />
</tb:CircleLayout>

<tb:CircleLayout mode="Sequence" align="Center" spacing="32"
                 start-angle="-90" rotate-items="true" animate="true"
                 style="width: 260px; height: 260px;" />
var ring = new CircleLayout { Radius = 80, StartAngle = -90 };
ring.style.width = ring.style.height = 240;
ring.Add(new Button { text = "Attack" });
ring.Add(new Button { text = "Defend" });

// 子元素的位置,单位为度
if (ring.TryGetAngle(button, out var degrees))
    Debug.Log(degrees);

角度的单位是度。0 是顶部(12 点钟),角度按顺时针增加,所以 90 是右边。

成员 说明
Radius (radius) 圆的半径,单位为像素。0(默认)让圆适应布局的框,并减去最大子元素的一半。
StartAngle (start-angle) 第一个子元素的角度,单位为度。默认为 0。
Direction (direction) Clockwise(默认)或 CounterClockwise。
Mode (mode) Spread(默认)把子元素均匀分布在 Sweep 上。Sequence 把它们按 Spacing 度间隔放置。
Sweep (sweep) Spread 覆盖的角度,从 0 到 360。为 360(默认)时,子元素绕满一圈,最后一个不会落在第一个上。小于 360 时,第一个子元素在起始角度,最后一个在弧的末端。
Spacing (spacing) Sequence 模式下两个子元素之间的角度。默认为 30。
Align (align) Sequence 相对起始角度的位置:Start(第一个子元素在起始角度)、Center(中间的子元素在那里)或 End(最后一个子元素在那里)。
RotateItems (rotate-items) 把每个子元素按它的角度旋转,使它的顶部背向中心。
Animate (animate) 添加 USS 类 tb-circle-layout--animate,让子元素平滑移动到新位置。第一次布局不做动画。
VisibleCount、EffectiveRadius 有位置的子元素的数量,和正在使用的半径。
AngleOfSpot(index, count)、TryGetAngle(child, out degrees) 一个位置的角度,和一个子元素的角度。对于隐藏的或不在布局中的子元素,TryGetAngle 为 false。
PointOnCircle(radius, degrees) 静态方法:某个角度相对于中心的偏移。
Refresh() 立即布局。当布局的尺寸、设置或子元素改变时,布局会自己运行。

样式

类 元素
tb-circle-layout 布局。它本身没有外观。
tb-circle-layout--animate Animate 开启时的布局。它为子元素的 left、top 和 rotate 设置过渡,使用主题的动画时长和缓动令牌。