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

相关推荐
晓13131 小时前
【Cocos Creator 2.x】篇——第二章 入门
javascript·游戏引擎
nnsix3 小时前
Unity 贴图压缩格式 笔记
笔记·unity·贴图
文创工作室6 小时前
Adobe Illustrator 中文
ui·adobe·illustrator
ysn1111112 小时前
搭建状态同步框架的实践心得
unity·架构
烛衔溟13 小时前
HarmonyOS 基础 UI 构建 —— 组件、布局与沉浸式效果
ui·华为·harmonyos
一线灵14 小时前
Axmol:小众引擎的硬核逆袭
游戏引擎
一次旅行15 小时前
CopilotKit实战:用生成式UI打造智能Agent前端
前端·人工智能·ui
weixin_4419400115 小时前
【Unity教程】使用vuforia创建简单的AR实例
unity·游戏引擎·ar
郝学胜-神的一滴15 小时前
[简化版 GAMES 101] 计算机图形学 12:可见性与 Z‑Buffer 深度缓存
unity·godot·图形渲染·three.js·opengl·unreal
归真仙人1 天前
【UE】LineTraceByProfile
ue5·游戏引擎·ue4·unreal engine