SHA256
27 lines
900 B
C#
27 lines
900 B
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using UnityEngine;
|
|
|
|
namespace ADOFAIRenderer.Util
|
|
{
|
|
internal static class ParticleUtil
|
|
{
|
|
private static readonly ConditionalWeakTable<ParticleSystem, ParticleSystemRenderer> Cache = new();
|
|
|
|
public static ParticleSystemRenderer? GetRenderer(this ParticleSystem ps)
|
|
{
|
|
if (!ps) return null;
|
|
if (Cache.TryGetValue(ps, out var renderer) && renderer) return renderer;
|
|
|
|
var particleSystems = ps.GetComponents<ParticleSystem>();
|
|
var renderers = ps.GetComponents<ParticleSystemRenderer>();
|
|
var index = Array.IndexOf(particleSystems, ps);
|
|
|
|
renderer = index >= 0 && index < renderers.Length ? renderers[index] : ps.GetComponent<ParticleSystemRenderer>();
|
|
if (renderer) Cache.Add(ps, renderer);
|
|
|
|
return renderer;
|
|
}
|
|
}
|
|
}
|