r2mods/ilspy_dump/ror2_csproj/RoR2/ScaleParticleSystemDuration.cs

66 lines
1.2 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using UnityEngine;
namespace RoR2;
public class ScaleParticleSystemDuration : MonoBehaviour
{
public float initialDuration = 1f;
private float _newDuration = 1f;
public ParticleSystem[] particleSystems;
public float newDuration
{
get
{
return _newDuration;
}
set
{
if (_newDuration != value)
{
_newDuration = value;
UpdateParticleDurations();
}
}
}
private void Start()
{
UpdateParticleDurations();
}
public void UpdateDuration()
{
float simulationSpeed = initialDuration / _newDuration;
for (int i = 0; i < particleSystems.Length; i++)
{
ParticleSystem particleSystem = particleSystems[i];
if ((bool)particleSystem)
{
ParticleSystem.MainModule main = particleSystem.main;
particleSystem.Stop();
particleSystem.Clear();
main.duration = _newDuration;
main.simulationSpeed = simulationSpeed;
particleSystem.Play();
}
}
}
private void UpdateParticleDurations()
{
float simulationSpeed = initialDuration / _newDuration;
for (int i = 0; i < particleSystems.Length; i++)
{
ParticleSystem particleSystem = particleSystems[i];
if ((bool)particleSystem)
{
ParticleSystem.MainModule main = particleSystem.main;
main.simulationSpeed = simulationSpeed;
}
}
}
}