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

相关推荐
JaneConan3 分钟前
鸿蒙 ArkUI 深水区:@Watch 和 @Observed,状态变了「自动跑」+ 嵌套对象「深层重绘」
开发语言·后端·ui·harmonyos
施棠海3 小时前
设计稿一键变成可运行的Android页面:Pixel2XML全流程UI开发框架实战(附完整源码)
android·ui·架构
郝学胜-神的一滴4 小时前
中级OpenGL教程 022:探秘三维世界的血脉传承——物体父子关系与矩阵递归奥义
c++·线性代数·unity·矩阵·游戏引擎·unreal engine·opengl
Helen_cai5 小时前
OpenHarmony 通用状态加载、空页面、错误兜底组件封装(全局业务通用 UI 组件 API23)
开发语言·ui·华为·php·harmonyos
YM52e5 小时前
鸿蒙 Flutter BoxDecoration装饰:打造精美UI效果
学习·flutter·ui·华为·harmonyos·鸿蒙
qq_463408425 小时前
# 基于 HarmonyOS ArkTS 声明式 UI 构建智能音乐播放器:深色主题圆盘轮播、五 Tab 导航隔离、瀑布流收藏与悬浮迷你播放条实现深度解析
ui·华为·harmonyos
weixin_424294671 天前
Unity的测试Edit Mode和Play Mode,有什么区别?
unity
工业HMI实战笔记1 天前
【无标题】
大数据·人工智能·ui·自动化·人机交互·交互
帅次1 天前
Kotlin Flow 与 StateFlow:UI 单向数据流基础
开发语言·ui·kotlin·stateflow·onlifecycle