Skip to content

Commit

Permalink
feat: refresh children ParticleSystem with a gameObjects as root
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Sep 2, 2020
1 parent 90593ac commit 8bae1d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ private void Update()
var particle = demo.GetType()
.GetMethod("spawnParticle", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
.Invoke(demo, new object[0]) as GameObject;
particle.transform.SetParent(UiParticle.transform, false);
particle.transform.localScale = Vector3.one;
particle.transform.localPosition = Vector3.zero;
UiParticle.RefreshParticles();
UiParticle.SetParticleSystemInstance(particle);
}

public void SetCanvasWidth(int width)
Expand Down
14 changes: 10 additions & 4 deletions Packages/UIParticle/Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ public void SetParticleSystemInstance(GameObject instance)
SetParticleSystemInstance(instance, true);
}

public void SetParticleSystemInstance(GameObject instance, bool destroy)
public void SetParticleSystemInstance(GameObject instance, bool destroyOldParticles)
{
if (!instance) return;

foreach (Transform child in transform)
{
var go = child.gameObject;
go.SetActive(false);
if (!destroy) continue;
if (!destroyOldParticles) continue;

#if UNITY_EDITOR
if (!Application.isPlaying)
Expand All @@ -151,7 +151,7 @@ public void SetParticleSystemInstance(GameObject instance, bool destroy)
tr.SetParent(transform, false);
tr.localPosition = Vector3.zero;

RefreshParticles();
RefreshParticles(instance);
}

public void SetParticleSystemPrefab(GameObject prefab)
Expand All @@ -163,7 +163,13 @@ public void SetParticleSystemPrefab(GameObject prefab)

public void RefreshParticles()
{
GetComponentsInChildren(particles);
RefreshParticles(gameObject);
}

public void RefreshParticles(GameObject root)
{
if (!root) return;
root.GetComponentsInChildren(particles);

foreach (var ps in particles)
{
Expand Down

0 comments on commit 8bae1d0

Please sign in to comment.