feat: add public properties for UIParticleAttractor

close #253
pull/289/head
mob-sakai 2023-08-14 16:47:16 +09:00
parent f75fcce0da
commit 392ab6dd76
1 changed files with 43 additions and 10 deletions

View File

@ -36,6 +36,18 @@ namespace Coffee.UIExtensions
[SerializeField] [SerializeField]
private UnityEvent m_OnAttracted; private UnityEvent m_OnAttracted;
public float destinationRadius
{
get
{
return m_DestinationRadius;
}
set
{
m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f);
}
}
public float delay public float delay
{ {
get get
@ -72,6 +84,18 @@ namespace Coffee.UIExtensions
} }
} }
public UnityEvent onAttracted
{
get
{
return m_OnAttracted;
}
set
{
m_OnAttracted = value;
}
}
public ParticleSystem particleSystem public ParticleSystem particleSystem
{ {
get get
@ -81,8 +105,7 @@ namespace Coffee.UIExtensions
set set
{ {
m_ParticleSystem = value; m_ParticleSystem = value;
if (!ApplyParticleSystem()) return; ApplyParticleSystem();
enabled = true;
} }
} }
@ -90,16 +113,21 @@ namespace Coffee.UIExtensions
private void OnEnable() private void OnEnable()
{ {
if (!ApplyParticleSystem()) return; ApplyParticleSystem();
UIParticleUpdater.Register(this); UIParticleUpdater.Register(this);
} }
private void OnDisable() private void OnDisable()
{ {
_uiParticle = null;
UIParticleUpdater.Unregister(this); UIParticleUpdater.Unregister(this);
} }
private void OnDestroy()
{
_uiParticle = null;
m_ParticleSystem = null;
}
internal void Attract() internal void Attract()
{ {
if (m_ParticleSystem == null) return; if (m_ParticleSystem == null) return;
@ -131,6 +159,7 @@ namespace Coffee.UIExtensions
Debug.LogException(e); Debug.LogException(e);
} }
} }
continue; continue;
} }
@ -181,6 +210,7 @@ namespace Coffee.UIExtensions
dstPos.Scale(_uiParticle.scale3D.Inverse()); dstPos.Scale(_uiParticle.scale3D.Inverse());
} }
} }
return dstPos; return dstPos;
} }
@ -203,13 +233,18 @@ namespace Coffee.UIExtensions
return Vector3.MoveTowards(current, target, speed); return Vector3.MoveTowards(current, target, speed);
} }
private bool ApplyParticleSystem() private void ApplyParticleSystem()
{ {
_uiParticle = null;
if (m_ParticleSystem == null) if (m_ParticleSystem == null)
{ {
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
{
Debug.LogError("No particle system attached to particle attractor script", this); Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false; }
return false; return;
} }
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>(); _uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
@ -217,8 +252,6 @@ namespace Coffee.UIExtensions
{ {
_uiParticle = null; _uiParticle = null;
} }
return true;
} }
} }
} }