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

相关推荐
狂人开飞机29 分钟前
27、实战物理益智游戏
游戏·游戏引擎·godot
小小数媒成员16 小时前
如何优化代码适应托管内存?
游戏·unity·游戏引擎
HwJack2018 小时前
【HarmonyOS开发小实践】ArkUI 应用级状态AppStorage 与跨页面共享、持久化
ui·华为·性能优化·harmonyos
undsky_21 小时前
传统色 × 现代和弦:专为 UI/UX 打造的国风配色 Skill
ui·ai·aigc·ai编程·ux
狂人开飞机1 天前
21、游戏架构设计模式
游戏·游戏引擎·godot
新的瑞拉公主2 天前
Unity游戏发布微信小游戏:从构建到提审
unity·webgl·微信小游戏·开放数据域
Wang's Blog3 天前
Java框架快速入门: Spring Security+OAuth2之多因子认证与TOTP实战
java·spring·ui
狂人开飞机3 天前
14、游戏手感与视觉打磨
游戏·游戏引擎·godot
Huanzhi_Lin3 天前
UI业务模块化随笔
ui·mvc·mvp·ecs·ui框架·模块化开发