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

相关推荐
呆呆敲代码的小Y1 小时前
【Unity 实用工具篇】| UX Tool 工具 快速上手使用,提高日常开发效率
游戏·unity·游戏引擎·游戏程序·ux
世洋Blog1 小时前
Unity开发微信小程序-避开新InputSystem有关坑
unity·微信小程序
小笔学长1 小时前
React 入门:构建交互式 UI 的基础
ui·项目实战·前端开发·react框架·jsx语法
zhaocarbon1 小时前
VUE 4向云台 8向云台UI
css·vue.js·ui
阿蔹1 小时前
UI测试自动化-Web-Python-Appium
前端·python·ui·appium·自动化
lifewange10 小时前
UI自动化页面元素定位有几种方式
前端·ui·自动化
简简单单OnlineZuozuo15 小时前
提示架构:设计可靠、确定性的AI系统
人工智能·unity·架构·游戏引擎·基准测试·the stanford ai·儿童
我送炭你添花1 天前
Pelco KBD300A 模拟器:06+4.KBD300A 键盘 UI 布局的设计与响应式实现(二次迭代)
ui·计算机外设
qq_428639611 天前
ue无双割草项目:4.让AI受伤及添加UI
ui·ue·无双割草
uniGame2 天前
FrameDebugger使用说明
unity·性能优化