赞
踩
MaskableGraphic是Unity UGUI中的一个组件,用于实现图形的遮罩效果。通过该组件,我们可以将一个图形对象的显示范围限制在一个指定的区域内,从而实现遮罩效果。
MaskableGraphic组件的工作原理是通过将图形对象与遮罩对象进行相交运算,将图形对象的显示范围限制在遮罩对象的范围内。具体的工作流程如下:
using UnityEngine;
using UnityEngine.UI;
public class Example1 : MonoBehaviour
{
public GameObject maskObject;
public GameObject graphicObject;
private void Start()
{
graphicObject.transform.SetParent(maskObject.transform);
graphicObject.GetComponent<MaskableGraphic>().maskable = true;
}
}
操作步骤:
using UnityEngine; using UnityEngine.UI; public class Example2 : MonoBehaviour { public GameObject maskObject; public GameObject graphicObject; public Material maskMaterial; private void Start() { graphicObject.transform.SetParent(maskObject.transform); MaskableGraphic maskableGraphic = graphicObject.GetComponent<MaskableGraphic>(); maskableGraphic.maskable = true; maskableGraphic.maskMaterial = maskMaterial; } }
操作步骤:
using UnityEngine; using UnityEngine.UI; public class Example3 : MonoBehaviour { public GameObject maskObject; public GameObject graphicObject; private void Start() { graphicObject.transform.SetParent(maskObject.transform); MaskableGraphic maskableGraphic = graphicObject.GetComponent<MaskableGraphic>(); maskableGraphic.maskable = true; maskableGraphic.maskInteraction = MaskableGraphic.MaskInteraction.VisibleInsideMask; } }
操作步骤:
using UnityEngine;
using UnityEngine.UI;
public class Example4 : MonoBehaviour
{
public GameObject graphicObject;
private void Update()
{
graphicObject.GetComponent<MaskableGraphic>().SetMaterialDirty();
}
}
操作步骤:
using UnityEngine;
using UnityEngine.UI;
public class Example5 : MonoBehaviour
{
public GameObject graphicObject;
private void Update()
{
graphicObject.GetComponent<MaskableGraphic>().SetVerticesDirty();
}
}
操作步骤:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。