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

相关推荐
一线灵7 小时前
跨平台游戏引擎 Axmol-2.11.6 发布
游戏引擎
两水先木示10 小时前
【Unity】Lens Flare光晕简单使用案例
unity·游戏引擎
专注仿真10 小时前
Unity 小游戏实战:2D 横版闯关 / 3D 跑酷 / 塔防 / 解谜四类项目工程化拆解与复用实践
游戏·游戏引擎·游戏程序
郝学胜-神的一滴1 天前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
两水先木示1 天前
【Unity】刮刮乐案例-RenderTexture实现思路
unity·游戏引擎
学术小李1 天前
用虚幻引擎(UE)打开Obj模型
游戏引擎·虚幻
zhongben_keji1 天前
APP WebView 混合开发体系:通信协议、加载优化与安全治理的工程落地
ui·ci/cd·自动化
张不无-Unity1 天前
Unity的四种灯光Directional、Point、Spot 和 Area
unity·游戏引擎
fatCatLA1 天前
UI模拟器使用手册
单片机·嵌入式硬件·ui
蓝悦无人机1 天前
Figma组件库搭建教程(实战篇)
前端·ui·figma