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

相关推荐
xcLeigh5 小时前
Unity基础:C#脚本的创建与挂载——让你的游戏物体活起来
游戏·unity·c#·教程
飞凌嵌入式10 小时前
告别多端重复开发:Buildroot+Flutter实现全平台UI风格统一
flutter·ui
DaLiangChen1 天前
Vuforia 地面识别案例
unity·ar
FungLeo1 天前
Flutter 把第三方 UI 库渐进迁回 Material 3:组件映射总表 + 四批次替换实战
flutter·ui
鹤卿1231 天前
「iOS」天气预报仿写总结
ui·ios·objective-c
江畔柳前堤1 天前
YOLO 目标检测全流程深度剖析
人工智能·yolo·目标检测·计算机视觉·unity·面试·vllm
A24207349301 天前
Vue + TypeScript 请求数据后结合 Element UI 实现树形菜单与下拉选择
vue.js·ui·typescript
头茬韭菜1 天前
5.5 权限交互:渐进式信任的 UI 设计
ui·交互
魔术师Dix1 天前
一个轮子:Luban Skill 制作演示
游戏·unity·ai编程