mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-15 22:25:07 +00:00
46 lines
No EOL
1.2 KiB
C#
46 lines
No EOL
1.2 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace BezierSolution.Extras
|
|
{
|
|
// This class is used for resetting the particle system attached to a ParticlesFollowBezier
|
|
// component when it is selected. Otherwise, particles move in a chaotic way for a while
|
|
[CustomEditor( typeof( ParticlesFollowBezier ) )]
|
|
[CanEditMultipleObjects]
|
|
public class ParticlesFollowBezierEditor : Editor
|
|
{
|
|
private int particlesReset;
|
|
|
|
private void OnEnable()
|
|
{
|
|
particlesReset = 3;
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.OnInspectorGUI();
|
|
|
|
if( Application.isPlaying )
|
|
return;
|
|
|
|
if( particlesReset > 0 && --particlesReset == 0 )
|
|
{
|
|
foreach( Object target in targets )
|
|
{
|
|
ResetParticles( ( (ParticlesFollowBezier) target ).GetComponentsInParent<ParticlesFollowBezier>() );
|
|
ResetParticles( ( (ParticlesFollowBezier) target ).GetComponentsInChildren<ParticlesFollowBezier>() );
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ResetParticles( ParticlesFollowBezier[] targets )
|
|
{
|
|
foreach( ParticlesFollowBezier target in targets )
|
|
{
|
|
ParticleSystem particleSystem = target.GetComponent<ParticleSystem>();
|
|
if( target.spline != null && particleSystem != null && target.enabled )
|
|
particleSystem.Clear();
|
|
}
|
|
}
|
|
}
|
|
} |