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

相关推荐
招风的黑耳27 分钟前
Axure后台管理系统模板:智慧化解决方案的界面设计蓝图
ui·axure·后台原型
weixin_419658313 小时前
UISpy:Windows 界面控件的“显微镜“[特殊字符]
windows·python·测试工具·ui
变身缎带4 小时前
Unity中较为完善的NetworkManager
unity·游戏引擎
作孽就得先起床4 小时前
unity webGL导出.glb模型
unity·c#·游戏引擎·webgl
2301_818732065 小时前
ui库写表单,格式问题可能的原因
ui
心前阳光7 小时前
Unity发布运行在PICO4的安卓程序
android·unity·游戏引擎
孟无岐7 小时前
【Laya】Scene3D 介绍
typescript·游戏引擎·游戏程序·laya
sunfove7 小时前
Python制作小游戏:用线性代数思想构建 2048 游戏引擎
python·线性代数·游戏引擎
孟无岐7 小时前
【Laya】Sprite3D 介绍
typescript·游戏引擎·游戏程序·laya
Howrun7777 小时前
虚幻引擎_创建组件
游戏引擎·虚幻