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

相关推荐
ZC跨境爬虫7 小时前
跟着 MDN 学CSS day_16:(深入掌握背景与边框的艺术)
前端·css·ui·html·tensorflow
万岳科技系统开发8 小时前
外卖系统小程序开发趋势:即时零售与同城配送的融合升级
unity·游戏引擎·零售
十贺12 小时前
【Unity开发字典】分包、黏包基本概念和处理逻辑实现
unity·游戏引擎
淡海水16 小时前
01-认知篇-总览-HybridCLR是什么
unity·c#·aot·热更新·clr·hybrid
lazy熊16 小时前
AI编程实战9:用 Codex 把一段重复 UI 抽成组件
ui·ai编程
c++之路17 小时前
状态模式(State Pattern)
ui·状态模式
小许同学记录成长20 小时前
频谱分析仪 UI 自定义绘制
ui·架构
霸王•吕布20 小时前
游戏引擎中的BoundingBox
游戏引擎·aabb包围盒·obb包围盒
nnsix21 小时前
Unity AssetBundle(AB包) 笔记
笔记·unity·游戏引擎
mxwin21 小时前
Unity Shader Shiny SSRR
unity·游戏引擎·shader