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

相关推荐
信徒favor6 小时前
我用AI一次性生成3种UI原型(附提示词)
ui
timathy3314 小时前
Unity Addressable 实现Build时自定义剔除资源组
unity·游戏引擎
ll_god15 小时前
android compose ui 结合 ViewModel适配方案
android·ui
SoraLuna18 小时前
KuiklyUI for OpenHarmony 实战 01:源码构建与运行(Mac)
macos·ui·鸿蒙
雨季66618 小时前
构建交互式响应式页面:Flutter 在 OpenHarmony 上的动态 UI 实践
flutter·ui
紫雾凌寒18 小时前
【 HarmonyOS 高频题】2026 最新 ArkUI 开发与组件面试题
ui·华为·面试·程序员·职场发展·harmonyos·ark-ui
bugcome_com18 小时前
WPF 数据模板(DataTemplate):优雅实现数据与 UI 的解耦
ui·wpf
是席木木啊19 小时前
RuoYi-Vue-Plus UI前端页面布局调整
前端·vue.js·ui
UXbot1 天前
UI设计工具推荐合集
前端·人工智能·ui
雨季6661 天前
使用 Flutter for OpenHarmony 构建基础 UI 组件布局:从 Scaffold 到 Container 的实战解析
flutter·ui