using UnityEngine; namespace Thousandto.SkillEditor.Support { public class EditorVFXScript : MonoBehaviour { private ParticleSystem[] _particles = null; private Animation[] _animations = null; private Animator[] _animators = null; private TrailRenderer[] _trails = null; private bool _isEnd = false; private bool _isPlaying = false; public bool IsEnd { get { return _isEnd; } } public bool IsPlaying { get { return _isPlaying; } } private void Awake() { _particles = gameObject.GetComponentsInChildren(); if (_particles != null) { for(int i=0;i< _particles.Length;++i) { _particles[i].Stop(); } } _animations = gameObject.GetComponentsInChildren(); if(_animations != null) { for(int i=0;i< _animations.Length;++i) { _animations[i].Stop(); } } _animators = gameObject.GetComponentsInChildren(); if (_animators != null) { for (int i = 0; i < _animators.Length; ++i) { _animators[i].StopPlayback(); } } _trails = gameObject.GetComponentsInChildren(); } public void UpdateVFX() { if(!_isPlaying) return; bool isFinish = true; if (_particles != null) { for (int i = 0; i < _particles.Length; ++i) { if(_particles[i].isPlaying) { isFinish = false; break; } } } if (_animations != null) { for (int i = 0; i < _animations.Length; ++i) { if(_animations[i].isPlaying) { isFinish = false; break; } } } if (_animators != null) { for (int i = 0; i < _animators.Length; ++i) { AnimatorStateInfo animatorStateInfo = _animators[i].GetCurrentAnimatorStateInfo(0); if (animatorStateInfo.loop || animatorStateInfo.normalizedTime < 1.0f) { isFinish = false; break; } } } if(_trails != null && _trails.Length > 0) { isFinish = false; } _isEnd = isFinish; if(_isEnd) { _isPlaying = false; } } public void Play() { _isPlaying = true; if (_particles != null) { for (int i = 0; i < _particles.Length; ++i) { _particles[i].Play(); } } var _trailRenderers = gameObject.GetComponentsInChildren(true); { for (int i = 0; i < _trailRenderers.Length; i++) { if (_trailRenderers[i] != null) { _trailRenderers[i].Clear(); _trailRenderers[i].enabled = true; } } } if (_animations != null) { for (int i = 0; i < _animations.Length; ++i) { _animations[i].Play(); } } if (_animators != null) { for (int i = 0; i < _animators.Length; ++i) { AnimatorStateInfo animatorStateInfo = _animators[i].GetCurrentAnimatorStateInfo(0); _animators[i].Play(animatorStateInfo.nameHash); } } } public void Stop() { _isPlaying = false; _isEnd = true; if (_particles != null) { for (int i = 0; i < _particles.Length; ++i) { _particles[i].Stop(); } } if (_animations != null) { for (int i = 0; i < _animations.Length; ++i) { _animations[i].Stop(); } } if (_animators != null) { for (int i = 0; i < _animators.Length; ++i) { _animators[i].StopPlayback(); } } } } }