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

相关推荐
Humbunklung10 小时前
Rust Floem UI 框架使用简介
开发语言·ui·rust
不伤欣10 小时前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
Magnum Lehar12 小时前
vulkan游戏引擎test文件memory实现
游戏引擎
Magnum Lehar12 小时前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
快乐觉主吖16 小时前
Unity的日志管理类
android·unity·游戏引擎
CodeCraft Studio1 天前
【案例分享】如何借助JS UI组件库DHTMLX Suite构建高效物联网IIoT平台
javascript·物联网·ui
WarPigs1 天前
Unity性能优化笔记
笔记·unity·游戏引擎
插件开发1 天前
免费插件集-illustrator插件-Ai插件-随机填色
ui·illustrator
T.D.C1 天前
【业务框架】3C-相机-Cinemachine
unity
一线灵2 天前
跨平台游戏引擎 Axmol-2.6.1 发布
游戏引擎