using System.Collections;
using System.Collections.Generic;
using UnityEngine;/**UI特效遮罩
1.需要将ScrollRect 的遮罩Mask 换为 2D Mask2.将特效的Render里面的 Masking 设置为*/
public class UIParticleMaskControll : MonoBehaviour
{// Start is called before the first frame updatevoid 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的widthvar yScale = height / 4 * 100;//像素转换 4指的是sprite的heighttransform.localScale = new Vector3(xScale, yScale, 1);}// Update is called once per framevoid Update(){}
}
ParticleSystemRenderer-maskInteraction - Unity 脚本 API