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

相关推荐
速冻鱼Kiel14 小时前
Lyra的相机系统
笔记·ue5·游戏引擎·虚幻
不绝19116 小时前
Unity入门 :场景叠加/预制体资源包/脚本资源/生命周期函数/Inspector页面
unity·游戏引擎
在路上看风景17 小时前
20. 资源和脚本的绑定关系
unity
会一点设计17 小时前
工作总结PPT模板设计指南:从结构到排版的完整解析
ui·powerpoint·ux·ppt
夏河始溢17 小时前
一八零、AG-UI:构建AI前端交互的统一协议
前端·人工智能·ui
ucancode18 小时前
AI --> Mermaid --> 图形可视化 (UI)
人工智能·ui·ai·mermaid
小码过河.19 小时前
设计模式——状态模式
ui·状态模式
yj爆裂鼓手19 小时前
unity对象池
unity·c#
在路上看风景20 小时前
3.7 SRP Batcher
unity
快乐觉主吖20 小时前
Unity方便修改产品名和包名的小工具
unity·游戏引擎