using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**
UI特效遮罩
1.需要将ScrollRect 的遮罩Mask 换为 2D Mask
2.将特效的Render里面的 Masking 设置为
*/
public class UIParticleMaskControll : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
public void SetParticeMasking(GameObject go)
{
var pers = go.GetComponentsInChildren<ParticleSystemRenderer>();
foreach (ParticleSystemRenderer item in pers)
{
item.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
}
}
/// <summary>
/// 设置遮罩范围
/// </summary>
public void SetMaskRect(float width,float height)
{
var xScale = width / 4 * 100;//像素转换 4指的是sprite的width
var yScale = height / 4 * 100;//像素转换 4指的是sprite的height
transform.localScale = new Vector3(xScale, yScale, 1);
}
// Update is called once per frame
void Update()
{
}
}
ParticleSystemRenderer-maskInteraction - Unity 脚本 API文章来源:https://www.toymoban.com/news/detail-804569.html
文章来源地址https://www.toymoban.com/news/detail-804569.html
到了这里,关于unity UI特效遮罩的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!