Skip to content

Commit

Permalink
feat: add public properties for UIParticleAttractor
Browse files Browse the repository at this point in the history
close #253
  • Loading branch information
mob-sakai committed Aug 18, 2023
1 parent f75fcce commit 392ab6d
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions Scripts/UIParticleAttractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public enum Movement
[SerializeField]
private UnityEvent m_OnAttracted;

public float destinationRadius
{
get
{
return m_DestinationRadius;
}
set
{
m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f);
}
}

public float delay
{
get
Expand Down Expand Up @@ -72,6 +84,18 @@ public Movement movement
}
}

public UnityEvent onAttracted
{
get
{
return m_OnAttracted;
}
set
{
m_OnAttracted = value;
}
}

public ParticleSystem particleSystem
{
get
Expand All @@ -81,25 +105,29 @@ public ParticleSystem particleSystem
set
{
m_ParticleSystem = value;
if (!ApplyParticleSystem()) return;
enabled = true;
ApplyParticleSystem();
}
}

private UIParticle _uiParticle;

private void OnEnable()
{
if (!ApplyParticleSystem()) return;
ApplyParticleSystem();
UIParticleUpdater.Register(this);
}

private void OnDisable()
{
_uiParticle = null;
UIParticleUpdater.Unregister(this);
}

private void OnDestroy()
{
_uiParticle = null;
m_ParticleSystem = null;
}

internal void Attract()
{
if (m_ParticleSystem == null) return;
Expand Down Expand Up @@ -131,6 +159,7 @@ internal void Attract()
Debug.LogException(e);
}
}

continue;
}

Expand Down Expand Up @@ -181,6 +210,7 @@ private Vector3 GetDestinationPosition()
dstPos.Scale(_uiParticle.scale3D.Inverse());
}
}

return dstPos;
}

Expand All @@ -203,22 +233,25 @@ private Vector3 GetAttractedPosition(Vector3 current, Vector3 target, float dura
return Vector3.MoveTowards(current, target, speed);
}

private bool ApplyParticleSystem()
private void ApplyParticleSystem()
{
_uiParticle = null;
if (m_ParticleSystem == null)
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return false;
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
{
Debug.LogError("No particle system attached to particle attractor script", this);
}
return;
}

_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}

return true;
}
}
}

0 comments on commit 392ab6d

Please sign in to comment.