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

相关推荐
尤老师FPGA25 分钟前
使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第四十七讲)
ui
UI设计兰亭妙微2 小时前
UI 设计组件的价值与实践+常用 UI 设计组件核心规范清单
人工智能·ui
灰灰勇闯IT5 小时前
Flutter for OpenHarmony:深色模式下的 UI 优化技巧 —— 构建舒适、可读、无障碍的夜间体验
flutter·ui
测试人社区—03925 小时前
UI测试在DevOps流水线中的卡点设计:质量保障的智能防线
运维·驱动开发·测试工具·ui·ar·vr·devops
小贺儿开发7 小时前
Unity3D 八大菜系连连看
游戏·unity·互动·传统文化
在路上看风景7 小时前
25. 屏幕像素和纹理像素不匹配
unity
特立独行的猫a8 小时前
从XML到Compose的UI变革:现代(2026)Android开发指南
android·xml·ui·compose·jetpack
微祎_8 小时前
Flutter for OpenHarmony:构建一个 Flutter 单词拼图游戏,深入解析状态驱动 UI、交互式字母操作与教育类应用设计
javascript·flutter·ui
FuckPatience8 小时前
WPF xaml中的 xmlns:d=“http://schemas.microsoft.com/expression/blend/2008“ 的使用
ui·wpf
ۓ明哲ڪ8 小时前
Unity功能——创建新脚本时自动添加自定义头注释
unity·游戏引擎