unity UI特效遮罩

cs 复制代码
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

相关推荐
小雨下雨的雨10 小时前
鸿蒙PC应用:工程结构解析与配置文件详解
ui·华为·harmonyos·鸿蒙系统
速冻鱼Kiel10 小时前
GASP笔记01
笔记·ue5·游戏引擎·虚幻
世人万千丶10 小时前
鸿蒙跨端框架 Flutter 学习 Day 3:性能进阶——Iterable 延迟加载与计算流的智慧
学习·flutter·ui·华为·harmonyos·鸿蒙·鸿蒙系统
孟无岐11 小时前
【Laya】Animator2D 使用指南
typescript·游戏引擎·游戏程序·laya
航Hang*11 小时前
Photoshop 图形与图像处理技术——第9章:实践训练4——图层和蒙版
图像处理·笔记·ui·photoshop·期末·复习
世人万千丶11 小时前
鸿蒙跨端框架 Flutter 学习 Day 3:工程实践——数据模型化:从黑盒 Map 走向强类型 Class
学习·flutter·ui·华为·harmonyos·鸿蒙·鸿蒙系统
航Hang*12 小时前
Photoshop 图形与图像处理技术——第9章:实践训练3——图像修饰和色彩色调的调整
图像处理·笔记·学习·ui·photoshop·期末
速冻鱼Kiel12 小时前
GASP笔记02
笔记·ue5·游戏引擎·虚幻
__water13 小时前
RHK《Unity接入PicoSDK入门》
unity·游戏引擎·picosdk
低调小一13 小时前
Kotlin Multiplatform + 声明式 UI 三端实战:从工程结构到鸿蒙适配
ui·kotlin·harmonyos