鸟语天空
UnityEngine.ParticleSystem
post by:追风剑情 2022-8-5 14:18
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();
    }
}
评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容