将RectMask2D组件拖拽到Example脚本的rectMask变量上。 运行游戏,子对象将只在遮罩范围内显示。 例子2:动态调整遮罩范围 usingUnityEngine;usingUnityEngine.UI;publicclassExample:MonoBehaviour{publicRectMask2D rectMask;publicRectTransform maskRect;privatevoidUpdate(){ rectMask.rectTransform.sizeDelta = maskRect.sizeD...
RectMask2D组件通过裁剪子对象的渲染区域来实现遮罩效果。它使用一个矩形区域作为遮罩范围,只有在该范围内的子对象才会被显示出来。 3. RectMask2D的常用属性 Show Mask Graphic: 是否显示遮罩的图形,可以用于调试遮罩范围。 Softness: 遮罩边缘的柔化程度,值越大边缘越柔化。 Padding: 遮罩范围与子对象之间的边距。
}// if we have a enabled Mask component then it will// generate the mask material. This is an optimisation// it adds some coupling between components though :(// 如果我们用了Mask,它会生成一个mask材质,Mask maskComponent = GetComponent<Mask>();if(m_StencilValue >0&& (maskComponent ==null...
A RectMask2D: *Only works in the 2D plane *Requires elements on the mask to be coplanar. *Does not require stencil buffer / extra draw calls *Requres fewer draw calls *Culls elements that are outside the mask area. 変数 canvasRectキャンバス空間にあるマスクの Rect を取得します。
将RectMask2D组件拖拽到Example脚本的rectMask变量上。 将遮罩范围的RectTransform组件拖拽到Example脚本的maskRect变量上。 运行游戏,遮罩范围将根据参考元素的大小动态调整。 例子3:遮罩范围内的交互 usingUnityEngine;usingUnityEngine.UI;publicclassExample:MonoBehaviour{publicRectMask2DrectMask;publicButtonbutton;private...
RectMask2D 是一个类似于__遮罩 (Mask)__ 控件的遮罩控件。遮罩将子元素限制为父元素的矩形。与标准的遮罩控件不同,这种控件有一些限制,但也有许多性能优势。
Mask 组件调用了模板材质球构建了一个自己的材质球,因此它使用了实时渲染中的模板方法来裁切不需要显示的部分,所有在 Mask 组件的子节点都会进行裁切。 我们可以说 Mask 是在 GPU 中做的裁切,使用的方法是着色器中的模板方法。 二、RectMask2D原理分析
(1)、Mask组件可以实现遮罩的效果,将一个图像设为拥有mask组件图像的子物体,最后就会隐藏掉子图像和mask图像不重合的部分,如下图分别对比Mask和子物体的区域 在“Mask”物体上添加Mask组件后的效果就是右图效果 (2)、RectMask2D的用法和mask大致相同,不过RectMask2D只能裁剪一个矩形区域,同时RectMask2D可以选择边缘...
usingUnityEngine;usingUnityEngine.UI;publicclassExample:MonoBehaviour{publicRectMask2DrectMask;privatevoidStart(){rectMask.enabled=true;}} 操作步骤: 创建一个空物体,并添加RectMask2D组件。 将需要被遮罩的子对象作为该物体的子对象。 将RectMask2D组件拖拽到Example脚本的rectMask变量上。
将该脚本挂在顶部Content上,子对象中的MaskableGraphic物体都会被统一管理,但子物体如果所属另一个RectMask2D,那还是不行 usingSystem.Collections.Generic;usingUnityEngine.UI;usingUnityEngine;publicclassRectMaskAgent:MaskableGraphic{privateList<MaskableGraphic>_maskableList=newList<MaskableGraphic>();protectedRectMask...