主题
EUIClippingNode
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIClippingNode](4 属性)
- 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
- 属性:
EUIClippingNode 是一个 UI 裁切节点,用于根据蒙版图片的 Alpha 通道对子节点进行裁切显示。通过设置 ClippingImage 指定蒙版资源,并利用 AlphaThreshold 控制裁切阈值,可实现圆形头像、不规则形状遮罩等效果。支持反转裁切区域,灵活控制子节点的可见范围。
适用场景
常用于制作圆形头像、技能图标遮罩或任意不规则形状的 UI 容器,通过蒙版图片限制子元素的显示区域。
使用要点
通过 World:CreateUnit("EUIClippingNode", { Parent = parentNode }) 创建实例,设置 ClippingImage 为蒙版图片资源 URI,调整 AlphaThreshold 控制裁切精度,将需要裁切的子节点挂载到该节点下即可生效。
注意事项
EUIClippingNode 的 ClippingImage 使用调用方提供的有效 String 资源 URI,AlphaThreshold 通常取 0~1;这些公开属性可在 CreateUnit config 中初始化或通过属性赋值更新。不要调用 publish=false 的 SetClippingImage/SetAlphaThreshold/SetInverted/SetClippingEnabled。
代码示例
创建裁切节点并设置蒙版
lua
-- @runtime client
local function createClippingNode(imageUri)
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()
return World:CreateUnit("EUIClippingNode", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
ClippingImage = imageUri,
AlphaThreshold = 0.05,
Inverted = false,
ClippingEnabled = true,
})
end属性 (4)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Inverted | Bool | false | 控制裁剪区域是否反转。设为 true 时,原本被裁剪的区域将变为可见,原本可见的区域将被裁剪。 |
AlphaThreshold | Float | 0.05 | 设置裁剪蒙版的 Alpha 阈值,用于控制像素的可见性。当蒙版图片的 Alpha 值低于该阈值时,对应区域的子节点内容将被裁剪隐藏。 |
ClippingImage | String | official://image/10000 | 指定用于裁剪的蒙版图片资源。图片的 Alpha 通道将作为裁剪依据,结合 AlphaThreshold 决定子节点的可见区域。 |
ClippingEnabled | Bool | true | 控制裁剪功能是否启用。设为 true 时,子节点将根据蒙版图片和 Alpha 阈值进行裁剪;设为 false 时,裁剪功能关闭,子节点正常显示。 |
