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

相关推荐
mxwin4 小时前
Unity URP 法线贴图色彩空间、编码与解码
unity·游戏引擎·贴图·shader
console.log('npc')5 小时前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
玖玥拾7 小时前
Cocos学习笔记:项目框架搭建与异步加载进度
游戏引擎·cocos2d
mxwin7 小时前
Unity Shader URP:将法线可视化,便于调试
unity·游戏引擎·shader
蓝黑墨水8 小时前
unity相关链接
unity·游戏引擎
mxwin8 小时前
Unity Shader 法线贴图的七种错误用法
unity·游戏引擎·贴图·shader
mxwin11 小时前
Unity URP 切线空间详解
unity·游戏引擎·shader
不如摸鱼去12 小时前
Wot UI 2.1.0 发布:ConfigProvider 全局配置能力升级
ui·小程序·uni-app
川石课堂软件测试14 小时前
UI自动化测试|元素操作&浏览器操作实践
功能测试·测试工具·mysql·ui·docker·容器·单元测试