ro-webgl/Assets/Src/Utils/UIParticleHelper.cs
2021-12-21 09:40:39 +08:00

63 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIParticleHelper : MonoBehaviour
{
public int AddSortingNum = 0;
ParticleSystem[] pSystems;
Renderer[] pRenderers;
// Start is called before the first frame update
void Start()
{
pSystems = GetComponentsInChildren<ParticleSystem>();
pRenderers = GetComponentsInChildren<Renderer>();
}
public void Init(int baseSortingOrder)
{
if (pSystems == null)
pSystems = GetComponentsInChildren<ParticleSystem>();
if (pRenderers == null)
pRenderers = GetComponentsInChildren<Renderer>();
foreach (var renderer in pRenderers)
{
renderer.sortingOrder += baseSortingOrder + AddSortingNum;
}
}
public void OnDestroy()
{
pSystems = null;
pRenderers = null;
}
public void Update()
{
if (pSystems == null) return;
bool isPlaying = false;
foreach(var system in pSystems)
{
if (system.isPlaying)
{
isPlaying = true;
return;
}
}
if (!isPlaying)
{
gameObject.SetActive(false);
}
}
public void StartPlayParticle()
{
gameObject.SetActive(true);
}
}