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

相关推荐
元气少女小圆丶6 分钟前
unity发布web嵌入到前端页面的接受参数
前端·unity·webgl
HH‘HH31 分钟前
Unity 打包程序设置及注意事项全攻略
unity·游戏引擎
এ慕ོ冬℘゜4 小时前
前端实战:Textarea 实时字数计数输入器(带字数限制+UI优化完整源码)
前端·ui
fqbqrr4 小时前
2607d,parin游戏引擎
游戏引擎·d
qq_170264754 小时前
unity里 Burst的用法
unity·游戏引擎
HH‘HH8 小时前
Unity 相机与光照调整:从基础到进阶的实战指南
unity
todoitbo8 小时前
让数据看板随时可见:Grafana + cpolar 远程访问实战
ui·网络安全·grafana·数据看板·远程访问
Liknana8 小时前
Qt 圆角表格控件实战:setMask + 抗锯齿描边 + 多层阴影
qt·ui
天天进步20159 小时前
UI-TARS 源码解析 #7:Thought + Action 输出格式:GUI Agent 的最小决策闭环
ui
HH‘HH1 天前
Unity引擎界面各个功能面板详细介绍
unity·游戏引擎