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

相关推荐
郝学胜-神的一滴9 小时前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
两水先木示9 小时前
【Unity】刮刮乐案例-RenderTexture实现思路
unity·游戏引擎
学术小李18 小时前
用虚幻引擎(UE)打开Obj模型
游戏引擎·虚幻
zhongben_keji18 小时前
APP WebView 混合开发体系:通信协议、加载优化与安全治理的工程落地
ui·ci/cd·自动化
张不无-Unity19 小时前
Unity的四种灯光Directional、Point、Spot 和 Area
unity·游戏引擎
fatCatLA19 小时前
UI模拟器使用手册
单片机·嵌入式硬件·ui
蓝悦无人机21 小时前
Figma组件库搭建教程(实战篇)
前端·ui·figma
zhongben_keji1 天前
APP 无障碍与适老化改造工程实践:语义、视觉、交互三层落地
ui·ci/cd·自动化
汉得数字平台2 天前
【汉得飞码】构建接口与UI自动化测试全链路,让验证反馈持续驱动交付
自动化测试·人工智能·ui
淡海水2 天前
02-02-原理篇-Scriban模板引擎原理深度解析
unity·excel·游戏开发·luban