feat: add particle system getter and setter for attractor

close #253
pull/289/head
AndreevWezom 2023-03-12 13:33:26 +02:00 committed by mob-sakai
parent a499f0c046
commit a4bcf93022
1 changed files with 32 additions and 12 deletions

View File

@ -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 UIParticle _uiParticle;
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);
} }
@ -200,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;
}
} }
} }