主题
TextUnit
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- [TextUnit](26 属性)
继承成员
1 个来源 / 4 属性 / 25 函数 / 6 事件
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
三维文字组件,用于在场景中显示可配置的立体文字。支持调整位置、旋转、缩放、字体、颜色、对齐方式以及超框滚动等丰富属性,可灵活定制文字外观与布局。
适用场景
在场景中创建并配置三维文字,例如显示玩家名称、提示信息或装饰性文本,通过设置内容、字体、颜色和布局属性实现多样化的视觉效果。
使用要点
通过 game:CreateUnit("TextUnit", config) 或 World:CreateUnit("TextUnit", config) 创建实例,然后直接读写属性如 Content、FontSize、TextColor 等来定制文字。可使用 Enums.HorizontalAlignmentType 和 Enums.VerticalAlignmentType 设置对齐,用 Enums.TextOverflowStrategy 控制超框行为。
注意事项
实例必须通过 CreateUnit 创建,不能使用 New 方法。属性修改会立即生效,无需额外刷新。超框滚动策略需配合 OverflowScrollSpeed 和 OverflowScrollSpacing 使用。
代码示例
创建 3D 文字并设置样式
lua
-- @runtime client
local world = game:GetService("World")
local textUnit = world:CreateUnit("TextUnit", {
Content = "欢迎来到关卡",
Width = 6.0,
Height = 2.0,
FontName = Enums.TextFontType.HKXZYT_W9_GB,
FontSize = 80,
TextColor = Color.New(255, 230, 120, 255),
OutlineColor = Color.New(0, 0, 0, 255),
OutlineWidth = 2.0,
})
textUnit.GradientColorEnable = true
textUnit.GradientColors = {
Color.New(255, 230, 120, 255),
Color.New(255, 120, 80, 255),
}
print("文字内容:", textUnit.Content)属性 (26)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Position | Vector3 | [0.0, 0.0, 0.0] | TextUnit 在世界空间中的位置,使用 Vector3 表示三维坐标。 |
Rotation | Quaternion | [0.0, 0.0, 0.0, 1.0] | TextUnit 在世界空间中的旋转,使用 Quaternion 表示四元数旋转。 |
Width | Float | 5.0 | TextUnit 文字框的宽度。 |
Height | Float | 5.0 | TextUnit 文字框的高度。 |
Scale | Vector3 | [1.0, 1.0, 1.0] | 文本单元的整体缩放比例,使用 Vector3 分别控制 X、Y、Z 三个轴向的缩放。 |
Content | String | "" | TextUnit 显示的文本内容。 |
FontName | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | TextUnit 使用的字体名称。 |
FontSize | Int | 100 | TextUnit 的字体大小。 |
Visible | Bool | true | TextUnit 是否可见。 |
HoriAlign | HorizontalAlignmentType | Enums.HorizontalAlignmentType.ALIGN_LEFT | TextUnit 的水平对齐方式。 |
VertAlign | VerticalAlignmentType | Enums.VerticalAlignmentType.ALIGN_TOP | TextUnit 的垂直对齐方式。 |
LineWrap | Bool | true | TextUnit 是否自动换行。 |
OverflowStrategy | TextOverflowStrategy | Enums.TextOverflowStrategy.OVERFLOW_NONE | 文本超出文字框时的处理策略。 |
OverflowScrollSpeed | Float | 2.0 | 跑马灯滚动的速度。 |
OverflowScrollSpacing | Float | 0 | 跑马灯滚动时的间距。 |
VerticalDirection | Bool | false | TextUnit 是否纵向显示文字。 |
ReverseDirection | Bool | false | 纵向显示时是否从右到左排列文字。 |
LineSpacing | Float | 0.0 | TextUnit 的行间距。 |
TextSkew | Float | 0.0 | TextUnit 的文本倾斜角度。 |
GradientColorEnable | Bool | false | 是否启用文本颜色渐变。 |
TextColor | Color | Color.New(255, 255, 255, 255) | 文本的填充颜色。 |
GradientColors | Array<Color> | - | 用于定义文本渐变颜色的颜色列表,配合 GradientColorEnable 属性使用。 |
GradientAngle | Float | 0.0 | 文本颜色渐变的角度。 |
OutlineColor | Color | Color.New(0, 0, 0, 255) | 文本描边的颜色。 |
OutlineWidth | Float | 0.0 | TextUnit 的描边宽度。 |
BindSocket | String | "" | TextUnit 绑定的挂点名称。 |
