Refactor change particle system

pull/254/head
AndreevWezom 2023-03-13 13:16:52 +02:00
parent e447c091be
commit 761c50abac
1 changed files with 19 additions and 24 deletions

View File

@ -81,19 +81,8 @@ namespace Coffee.UIExtensions
set set
{ {
m_ParticleSystem = value; m_ParticleSystem = value;
if (m_ParticleSystem == null) if (!ApplyParticleSystem()) return;
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return;
}
enabled = true; enabled = true;
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}
} }
} }
@ -101,18 +90,7 @@ namespace Coffee.UIExtensions
private void OnEnable() private void OnEnable()
{ {
if (m_ParticleSystem == null) if (!ApplyParticleSystem()) return;
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return;
}
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}
UIParticleUpdater.Register(this); UIParticleUpdater.Register(this);
} }
@ -225,5 +203,22 @@ namespace Coffee.UIExtensions
return Vector3.MoveTowards(current, target, speed); 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<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}
return true;
}
} }
} }