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

相关推荐
派葛穆8 小时前
Unity-UI 按钮点击弹窗功能
unity·游戏引擎
toponad12 小时前
Unity Ads Bidding 现已正式加入TopOn 聚合平台
unity·topon
绿浪198413 小时前
WPF UI标准流水线
ui·wpf
unityのkiven15 小时前
Unity UGUI 实战:动态生成任务面板
unity·游戏引擎
郝学胜-神的一滴16 小时前
中级OpenGL教程 026:Assimp库从编译到实战全攻略
c++·unity·游戏引擎·图形渲染·unreal engine·opengl
凯尔3152 天前
Unity简单涂料实现
unity·游戏引擎·图形渲染
刘步权2 天前
KY-RTI分布仿真技术:第十三章 基于Unity的多语言三维态势仿真——以 Island Assault(夺岛突击)想定为例
unity·游戏引擎·仿真·态势·ky-rti·hla·rti
向夏威夷 梦断明暄2 天前
【GUI-Agent】阿里通义MAI-UI 代码阅读(2)--- 实现
ui
ellis19702 天前
C#/Unity清理非托管资源
unity·c#
玖玥拾2 天前
Unity 3D 笔记(十四)Unity/C# Socket 网络笔记3
服务器·网络·unity·c#