Skip to content

EUIButton

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)
    • EUINodeBase(34 属性 / 8 函数 / 4 事件)
      • [EUIButton](13 属性)

继承成员

2 个来源 / 38 属性 / 33 函数 / 10 事件

EUIButton 是 UI 按钮控件,用于在界面上创建可交互的按钮。它支持设置常态、按下和禁用三种状态的图片与颜色,并能显示文本。点击事件通过 OnClicked 订阅,可响应玩家操作。

适用场景

常用于制作游戏主菜单、设置面板或确认对话框中的按钮,例如开始游戏、确认购买等交互元素。

使用要点

通过 World:CreateUnit 创建实例,将 Parent 设为 PlayerGui.EuiManager:GetRootNode() 以显示在玩家界面上。设置 NormalImage、PressImage 等属性指定按钮外观,然后通过 OnClicked 事件连接处理函数响应点击。

注意事项

EUIButton 是按钮控件,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。按钮图片(PressImage/NormalImage/DisableImage)写入时使用 Asset 协议字符串(如 official://image/10066),不要把调试打印出的 official://image/xxx 字符串原样写回属性。点击事件通过 OnClicked 订阅。

代码示例

创建按钮并设置三态图片 ID

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 button = World:CreateUnit("EUIButton", {
    Parent = rootNode,
    Position = Vector2.New(0, 0),
    Size = Vector2.New(100, 40),
})
button.NormalImage = "official://image/10066"
button.PressImage = "official://image/10067"
button.DisableImage = "official://image/10068"

属性 (13)

Name类型默认值说明
NormalImageStringofficial://image/10000按钮常态图片写入时使用 Asset 协议字符串(如 official://image/10066);不要把调试打印出的 official://image/... 字符串原样写回属性。
PressImageStringofficial://image/10001按钮按下图片写入时使用 Asset 协议字符串(如 official://image/10067);不要把调试打印出的 official://image/... 字符串原样写回属性。
DisableImageStringofficial://image/10002按钮禁用图片写入时使用 Asset 协议字符串(如 official://image/10068);不要把调试打印出的 official://image/... 字符串原样写回属性。
DisabledBoolfalse控制按钮是否处于禁用状态。
ButtonTextString""按钮上显示的文本内容。
ButtonTextFontTextFontTypeEnums.TextFontType.HKXZYT_W9_GB按钮文本的字体。
ButtonTextFontSizeInt42按钮文本的字体大小。
ButtonTextColorColor[255, 255, 255, 255]按钮上文本的颜色。
ButtonNormalColorColor[255, 255, 255, 255]按钮处于正常状态时的背景颜色。
ButtonPressColorColor[255, 255, 255, 255]按钮被按下时的背景颜色。
ButtonDisableColorColor[255, 255, 255, 255]按钮处于禁用状态时的背景颜色。
StretchAreaVector4[0, 0, 0, 0]按钮图片的拉伸区域,用于九宫格拉伸。
StretchAreaPercentEnabledBooltrue控制拉伸区域是否按百分比计算。

关联类型