2023-05-19 22:20:57 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Util
|
|
|
|
{
|
|
|
|
public static class ParticleSystemHelpers
|
|
|
|
{
|
2024-04-05 01:27:59 +00:00
|
|
|
public static void PlayScaledAsync(this ParticleSystem particleSystem, float timeScale, bool respectDistance = false)
|
2023-05-19 22:20:57 +00:00
|
|
|
{
|
2024-04-05 01:27:59 +00:00
|
|
|
SetAsyncScaling(particleSystem, timeScale, respectDistance);
|
2023-05-19 22:20:57 +00:00
|
|
|
particleSystem.Play();
|
|
|
|
}
|
|
|
|
|
2024-04-05 01:27:59 +00:00
|
|
|
public static void SetAsyncScaling(this ParticleSystem particleSystem, float timeScale, bool respectDistance = false)
|
2023-05-19 22:20:57 +00:00
|
|
|
{
|
|
|
|
ParticleSystem.MainModule main = particleSystem.main;
|
2024-03-04 03:50:39 +00:00
|
|
|
main.simulationSpeed = main.simulationSpeed / Conductor.instance.pitchedSecPerBeat * timeScale;
|
2024-04-05 01:27:59 +00:00
|
|
|
// addition by Yin
|
|
|
|
if (respectDistance)
|
|
|
|
{
|
|
|
|
ParticleSystem.EmissionModule emission = particleSystem.emission;
|
|
|
|
emission.rateOverDistanceMultiplier = Conductor.instance.pitchedSecPerBeat * timeScale * 4; // i don't know why 4 is the magic number
|
|
|
|
}
|
2024-03-04 03:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void PlayScaledAsyncAllChildren(this ParticleSystem particleSystem, float timeScale)
|
|
|
|
{
|
|
|
|
particleSystem.PlayScaledAsync(timeScale);
|
|
|
|
|
|
|
|
foreach (var p in particleSystem.GetComponentsInChildren<ParticleSystem>())
|
|
|
|
{
|
|
|
|
if (p == particleSystem) continue;
|
|
|
|
p.PlayScaledAsyncAllChildren(timeScale);
|
|
|
|
}
|
2023-05-19 22:20:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|