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

相关推荐
工业HMI实战笔记2 小时前
包装机械HMI:快速换型与配方管理的界面解决方案
ui·性能优化·自动化·汽车·交互
在路上看风景5 小时前
32. 代码优化
unity
在路上看风景6 小时前
01. 编辑器外观
unity
熊猫钓鱼>_>6 小时前
【开源鸿蒙跨平台开发先锋训练营】Day 12:全场景适配与异常防护——构建高可靠的鸿蒙跨端体验
react native·ui·华为·开源·app·harmonyos·鸿蒙
CreasyChan6 小时前
unity C# 实现屏蔽敏感词
unity·c#·游戏引擎
m5655bj7 小时前
通过 Python 删除 Excel 中的空白行列
python·ui·excel
玉梅小洋8 小时前
Unity 2D游戏开发 Ruby‘s Adventure 2:主角和第一脚本
游戏·unity·游戏引擎·游戏程序·ruby·游戏开发
左手厨刀右手茼蒿8 小时前
Flutter for OpenHarmony 实战:DartX — 极致简练的开发超能力集
android·flutter·ui·华为·harmonyos
CG_MAGIC8 小时前
3D 烘焙资产导出:多引擎(Unity/Unreal)适配技巧
3d·unity·游戏引擎·效果图·建模教程·渲云
云上空1 天前
腾讯云使用对象存储托管并分享WebGL小游戏(unity3d)(需要域名)
unity·腾讯云·webgl·游戏开发·对象存储·网页托管