UnityEngine.ParticleSystem

作者:追风剑情 发布于:2022-8-5 14:18 分类:Unity3d

using UnityEngine;
/// <summary>
/// 粒子系统辅助类
/// </summary>
public sealed class ParticleSystemHelper
{
    // 获取对象上的所有粒子系统
    public static ParticleSystem[] GetParticleSystem(Transform transform, bool includeInactive=true)
    {
        if (transform == null)
            return null;
        ParticleSystem[] psArr = transform.GetComponentsInChildren<ParticleSystem>(includeInactive);
        return psArr;
    }

    // 播放
    public static void Play(Transform transform)
    {
        ParticleSystem[] psArr = GetParticleSystem(transform);
        if (psArr == null) return;
        foreach (var ps in psArr)
            ps.Play();
    }

    // 停止
    public static void Stop(Transform transform)
    {
        ParticleSystem[] psArr = GetParticleSystem(transform);
        if (psArr == null) return;
        foreach (var ps in psArr)
            ps.Stop();
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号