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

相关推荐
兰亭妙微UI设计公司34 分钟前
兰亭妙微交互设计公司:从4个方面聊聊UI设计规范
ui·设计规范
淡海水2 小时前
03-03-架构篇-SGen GC架构解析
unity·架构·c#·gc·sgen
空堂与归2 小时前
Gemini 4 Argon 发布:物理推理模型控机器人?
人工智能·gpt·ui·ai·机器人
/**书香门第*/2 小时前
Cocos Creator 打螺丝游戏的实现
游戏引擎·cocos2d·螺丝·打螺丝
兰亭妙微UI设计公司20 小时前
兰亭妙微用户体验设计公司的设计细节:关于提示的那些事
ui·ux·ue
萌萌的提莫队长20 小时前
Unity相机捕捉,图像识别,抠像+合成
opencv·unity
UWA21 小时前
UGUI性能排查实战:隐藏血条后耗时下降,减少顶点为何没改善
ui·性能优化·cpu·游戏开发
技术人生0011 天前
Selenium4 Python 完整教程(适合网页自动化、页面数据采集、UI自动化测试)
python·ui·自动化
mxwin2 天前
Unity Shader 光线追踪原理与实战案例
unity·游戏引擎