96 lines
1.6 KiB
C#
96 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
[Serializable]
|
|
public class ParticleController
|
|
{
|
|
[SerializeField]
|
|
private ParticleSystem rootParticleSystem;
|
|
|
|
private ParticleSystem[] particles;
|
|
|
|
public ParticleSystem RootParticleSystem
|
|
{
|
|
get
|
|
{
|
|
return rootParticleSystem;
|
|
}
|
|
set
|
|
{
|
|
rootParticleSystem = value;
|
|
}
|
|
}
|
|
|
|
public void Emit(int n)
|
|
{
|
|
if (CheckAndSetup())
|
|
{
|
|
ParticleSystem[] array = particles;
|
|
foreach (ParticleSystem particleSystem in array)
|
|
{
|
|
particleSystem.Emit(n);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
if (CheckAndSetup())
|
|
{
|
|
ParticleSystem[] array = particles;
|
|
foreach (ParticleSystem particleSystem in array)
|
|
{
|
|
particleSystem.Play(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Simulate(float t)
|
|
{
|
|
if (CheckAndSetup())
|
|
{
|
|
ParticleSystem[] array = particles;
|
|
foreach (ParticleSystem particleSystem in array)
|
|
{
|
|
particleSystem.Simulate(t, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Simulate(float t, bool restart)
|
|
{
|
|
if (CheckAndSetup())
|
|
{
|
|
ParticleSystem[] array = particles;
|
|
foreach (ParticleSystem particleSystem in array)
|
|
{
|
|
particleSystem.Simulate(t, false, restart);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
if (CheckAndSetup())
|
|
{
|
|
ParticleSystem[] array = particles;
|
|
foreach (ParticleSystem particleSystem in array)
|
|
{
|
|
particleSystem.Stop(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool CheckAndSetup()
|
|
{
|
|
if (particles == null && rootParticleSystem != null)
|
|
{
|
|
particles = rootParticleSystem.GetComponentsInChildren<ParticleSystem>(true);
|
|
}
|
|
return particles != null;
|
|
}
|
|
}
|
|
}
|