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

相关推荐
学术小李3 小时前
用虚幻引擎(UE)打开Obj模型
游戏引擎·虚幻
zhongben_keji3 小时前
APP WebView 混合开发体系:通信协议、加载优化与安全治理的工程落地
ui·ci/cd·自动化
张不无-Unity4 小时前
Unity的四种灯光Directional、Point、Spot 和 Area
unity·游戏引擎
fatCatLA4 小时前
UI模拟器使用手册
单片机·嵌入式硬件·ui
蓝悦无人机6 小时前
Figma组件库搭建教程(实战篇)
前端·ui·figma
zhongben_keji7 小时前
APP 无障碍与适老化改造工程实践:语义、视觉、交互三层落地
ui·ci/cd·自动化
汉得数字平台1 天前
【汉得飞码】构建接口与UI自动化测试全链路,让验证反馈持续驱动交付
自动化测试·人工智能·ui
淡海水1 天前
02-02-原理篇-Scriban模板引擎原理深度解析
unity·excel·游戏开发·luban
兰亭妙微UI设计公司2 天前
兰亭妙微设计洞察:跳出界面视角,深度理解广义的全链路用户体验
ui·交互·ux
zhongben_keji2 天前
APP 本地数据与持久化体系全解:存储选型、SQLite WAL、数据库迁移与隐私清理
ui·ci/cd·自动化