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

相关推荐
Wise玩转AI2 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
熊猫悟道8 小时前
Unity shader 之,Shader内部时间离散处理
unity·游戏引擎·材质·着色器
PA_9 小时前
unity Component-Based Architecture游戏框架
游戏·unity·游戏引擎
yi碗汤园12 小时前
C#实现对UI元素的拖拽
开发语言·ui·unity·c#
jtymyxmz12 小时前
《Unity Shader》11.3.2 广告牌技术
unity·游戏引擎
jtymyxmz13 小时前
《Unity Shader》11.3.1 流动的河流
unity·游戏引擎
晚霞的不甘14 小时前
开源鸿蒙(OpenHarmony)实战入门:从 Hello World 到 UI 交互设计
ui·开源·harmonyos
小马过河R14 小时前
开发游戏需要哪些岗位和角色参与
游戏·游戏引擎·游戏程序
jtymyxmz17 小时前
《Unity Shader》11.3.1 续 流动的水流的阴影
unity·游戏引擎