From a4bcf93022d2729f3d2a74a2cac4f52e68641b18 Mon Sep 17 00:00:00 2001 From: AndreevWezom Date: Sun, 12 Mar 2023 13:33:26 +0200 Subject: [PATCH] feat: add particle system getter and setter for attractor close #253 --- Scripts/UIParticleAttractor.cs | 44 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/Scripts/UIParticleAttractor.cs b/Scripts/UIParticleAttractor.cs index 621a8d9..6c98a59 100644 --- a/Scripts/UIParticleAttractor.cs +++ b/Scripts/UIParticleAttractor.cs @@ -72,22 +72,25 @@ namespace Coffee.UIExtensions } } + public ParticleSystem particleSystem + { + get + { + return m_ParticleSystem; + } + set + { + m_ParticleSystem = value; + if (!ApplyParticleSystem()) return; + enabled = true; + } + } + private UIParticle _uiParticle; private void OnEnable() { - if (m_ParticleSystem == null) - { - Debug.LogError("No particle system attached to particle attractor script", this); - enabled = false; - return; - } - - _uiParticle = m_ParticleSystem.GetComponentInParent(); - if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem)) - { - _uiParticle = null; - } + if (!ApplyParticleSystem()) return; UIParticleUpdater.Register(this); } @@ -200,5 +203,22 @@ namespace Coffee.UIExtensions return Vector3.MoveTowards(current, target, speed); } + private bool ApplyParticleSystem() + { + if (m_ParticleSystem == null) + { + Debug.LogError("No particle system attached to particle attractor script", this); + enabled = false; + return false; + } + + _uiParticle = m_ParticleSystem.GetComponentInParent(); + if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem)) + { + _uiParticle = null; + } + + return true; + } } } \ No newline at end of file