主题
EUIInputField
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUIInputField](16 属性 / 1 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
继承成员
2 个来源 / 39 属性 / 36 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 12 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、TouchDragEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 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、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUIInputField 是用于接收玩家文本输入的界面控件,公开属性可读取当前 Text,并描述字体、颜色、描边、阴影、对齐与占位提示等外观契约。当前运行包对 Text 与 PlaceHolderText 的直接写入仍有桥接 warning,因此可运行示例仅展示创建控件和读取 Text。
适用场景
在需要玩家输入名称、数值或聊天内容的 EUI 面板中,创建一个输入框并设置占位提示与文字样式,再通过读取 Text 属性获取玩家实际输入的内容;也可以连接 OnDetach,在输入结束时刷新界面或做状态复位。
使用要点
通过 World:CreateUnit 创建实例,并将 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode() 返回的根节点。当前版本读取用户输入时使用 inputField.Text;可运行示例只演示读取,不直接写入 Text 或 PlaceHolderText。
注意事项
EUIInputField 是文本输入框控件,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。读取用户输入请使用 Text 属性。当前运行包直接写 Text/PlaceHolderText 仍可能产生参数转换 warning,因此公开示例只读取、不演示运行时写入。Color 类型必须用 0-255 RGBA 四参数构造(如 Color.New(255, 0, 0, 255)),不能用 0-1 归一化值。
代码示例
创建输入框并读取文本属性
lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local inputField = World:CreateUnit("EUIInputField", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
inputField.OnDetach:Connect(function()
print("当前输入:", inputField.Text)
end)属性 (16)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Text | String | "" | 输入框当前显示的文本内容,类型为字符串。 |
TextColor | Color | [255, 255, 255, 255] | 输入框文本的颜色,类型为 Color。 |
FontSize | Int | 42 | 输入框文本的字号大小,类型为整数 Int。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | 输入框文本所使用的字体,类型为 Enums.TextFontType 枚举项,用于决定输入内容渲染时采用的字体样式。 |
OutlineEnabled | Bool | false | 是否开启输入框文本描边,类型为布尔值。 |
OutlineColor | Color | [0, 0, 0, 0] | 输入框文本描边的颜色,类型为 Color。 |
OutlineWidth | Int | 1 | 输入框文本描边的宽度,类型为整数。 |
OutlineOpacity | Float | 1.0 | 输入框文本描边的透明度,类型为浮点数。 |
ShadowEnabled | Bool | false | 是否开启输入框文本阴影,类型为布尔值。 |
ShadowColor | Color | [0, 0, 0, 0] | 输入框文本阴影的颜色,类型为 Color。 |
ShadowOffset | Vector2 | [1, 1] | EUIInputField 的文本阴影偏移属性,类型为 Vector2,用于表示输入框文本阴影的偏移量。 |
ItalicEnabled | Bool | false | 是否开启输入框文本的斜体效果,类型为布尔值。 |
TextHorizontalAlignment | EUITextHorizontalAlignment | Enums.EUITextHorizontalAlignment.Left | 输入框文本的水平对齐方式,取值为 Enums.EUITextHorizontalAlignment 枚举项。 |
TextVerticalAlignment | EUITextVerticalAlignment | Enums.EUITextVerticalAlignment.Top | 输入框文本的垂直对齐方式,取值为 Enums.EUITextVerticalAlignment 枚举项。 |
PlaceHolderText | String | "" | 输入框的占位文本,类型为字符串,用于在未输入内容时给出提示信息。 |
PlaceHolderTextColor | Color | [0, 0, 0, 0] | 输入框占位文本的颜色,类型为 Color。 |
关联类型
事件 (1)
OnDetach
签名:OnDetach() 触发:local
输入框脱离(结束编辑)时触发的本地事件,事件不携带任何参数。
示例代码
监听 EUIInputField.OnDetach 事件的示例。
lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiInputField = World:CreateUnit("EUIInputField", { Parent = rootNode })
euiInputField.OnDetach:Once(function()
print("OnDetach event")
end)