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

相关推荐
骊城英雄1 小时前
基于C#+avalonia ui实现的跨平台点胶机灌胶监控控制上位机软件
开发语言·ui·c#
新手unity自用笔记3 小时前
unity网络基础_1
网络·unity·游戏引擎
天天进步201512 小时前
UI-TARS 源码解析 #16:点击、双击、右键、悬停源码解析:GUI Agent 如何控制鼠标?
ui
谢斯13 小时前
[vscode] 使用unity打开vscode的取消.csproj的显示
ide·vscode·unity
魔术师Dix13 小时前
StartGame:Unity TDD 外部工程指南
学习·游戏·unity·c#·测试驱动开发
小当家.1051 天前
Taste Skill:88KB 提示词如何让 AI 写的 UI 不再像流水线罐头
前端·人工智能·ui·skill
码云数智-大飞1 天前
iOS 卡顿排查指南:主线程阻塞与 UI 渲染优化实战
ui·ios
for_ever_love__1 天前
iOS:天气预报仿写总结
macos·ui·ios·objective-c·cocoa