主题
EUISizeConstraint
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- [EUISizeConstraint](2 属性)
继承成员
1 个来源 / 5 属性 / 28 函数 / 6 事件
- 来自 Unit(5 属性 / 28 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent、Tags - 函数:
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、HasTag、AddTag、RemoveTag - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUISizeConstraint 用于给具体的 EUI 控件节点附加尺寸约束,通过最小尺寸与最大尺寸两个属性限定控件在布局中的宽高范围。它本身不承载显示内容,而是作为约束组件影响所挂载控件的尺寸计算结果。
适用场景
当按钮、图片或文本等控件需要避免被布局压缩得过小、或防止尺寸无限放大时,可在该控件节点下挂载 EUISizeConstraint 并配置上下限。
使用要点
先在玩家 EUI 根节点下创建一个具体 EUI 控件(如 EUIImage 或 EUIButton),再调用 World:CreateUnit("EUISizeConstraint", { Parent = 目标控件, MinSize = Vector2.New(80, 40), MaxSize = Vector2.New(400, 240) }) 将尺寸上下限约束挂到该控件下。
注意事项
EUISizeConstraint 不能直接挂载在 EUIRootNode 或 EUISceneNode 下,必须挂载在继承自 EUINodeBase 的具体 EUI 控件节点下,否则会抛出异常。设置时须保证 MinSize 各分量非负且不超过 MaxSize。
代码示例
为 EUI 控件挂载尺寸范围约束
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 panel = World:CreateUnit("EUIImage", { Parent = rootNode, Position = Vector2.New(0, 0), Size = Vector2.New(200, 120) })
if panel == nil then return end
local constraint = World:CreateUnit("EUISizeConstraint", { Parent = panel, MinSize = Vector2.New(80, 40), MaxSize = Vector2.New(400, 240) })
if constraint == nil then return end
print("EUISizeConstraint 已创建:", constraint.Name, constraint.MinSize, constraint.MaxSize)属性 (2)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
MinSize | Vector2 | [0, 0] | 表示 EUISizeConstraint 约束的最小尺寸,类型为 Vector2,用于描述横向与纵向的尺寸下限。 |
MaxSize | Vector2 | [inf, inf] | 表示 EUISizeConstraint 约束的最大尺寸,类型为 Vector2,用于描述横向与纵向的尺寸上限。 |
