主题
EUIInputField
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIInputField](16 属性 / 1 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
继承成员
2 个来源 / 38 属性 / 33 函数 / 10 事件
- 来自 EUINodeBase(34 属性 / 8 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release - 事件:
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、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUIInputField 是用于接收玩家文本输入的界面控件,公开属性可读取当前 Text,并描述字体、颜色、描边、阴影、对齐与占位提示等外观契约。当前运行包对 Text 与 PlaceHolderText 的直接写入仍有桥接 warning,因此可运行示例仅展示创建控件和读取 Text。
适用场景
常用于登录界面、聊天输入栏或搜索框等需要玩家输入文字的场景,通过将输入框挂载到玩家界面根节点来显示。
使用要点
通过 World:CreateUnit 创建实例,并将 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode() 返回的根节点。当前版本读取用户输入时使用 inputField.Text;不要调用不存在的 GetText,也不要在可运行示例中直接写 Text 或 PlaceHolderText,待运行时桥接修复后再恢复写入示例。
注意事项
EUIInputField 是文本输入框控件,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。读取用户输入请读取公开 Text 属性,不要调用不存在的 GetText。SetText/SetPlaceHolderText 在 Meta 中为 publish=false;2026-08-11 当前运行包直接写 Text/PlaceHolderText 还会产生 cannot convert argument warning,因此公开示例只读取 Text,不演示运行时写入。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] | 输入框文本的颜色。 |
FontSize | Int | 42 | 输入框文本的字号大小。 |
Font | TextFontType | Enums.TextFontType.HKXZYT_W9_GB | 输入框文本的字体。 |
OutlineEnabled | Bool | false | 是否启用文本描边。 |
OutlineColor | Color | [0, 0, 0, 0] | 输入框文本描边的颜色。 |
OutlineWidth | Int | 1 | 文本描边的宽度。 |
OutlineOpacity | Float | 1.0 | 文本描边的透明度。 |
ShadowEnabled | Bool | false | 是否启用文本阴影。 |
ShadowColor | Color | [0, 0, 0, 0] | 输入框文本阴影的颜色。 |
ShadowOffset | Vector2 | [1, 1] | 输入框文本阴影的偏移量。 |
ItalicEnabled | Bool | false | 是否启用斜体样式。 |
TextHorizontalAlignment | Int | 0 (Left) | 文本的水平对齐方式。 |
TextVerticalAlignment | Int | 0 (Top) | 文本的垂直对齐方式。 |
PlaceHolderText | String | "" | 输入框为空时显示的占位文本。 |
PlaceHolderTextColor | Color | [0, 0, 0, 0] | 输入框占位符文本的颜色。 |
关联类型
事件 (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)