using asap.core; using asap.core.common; using System; using UnityEngine; namespace Assets.Scripts.UI.PinataPack { public class PinataEffect : MonoBehaviour, IPoolableObject { private IObjectPool _pool; private Transform _parent; private ParticleSystem[] _particleSystems; private void Awake() { if (_particleSystems == null) _particleSystems = GetComponentsInChildren(); } public ParticleSystem[] GetParticleSystems() { if (_particleSystems == null) _particleSystems = GetComponentsInChildren(); return _particleSystems; } public void OnDespawn() { this.gameObject.SetActive(false); } public void OnPoolCreate(IObjectPool objectPool) { _pool = objectPool; } public void OnPoolDestroy() { _pool = null; } public void OnSpawn() { if (_parent == null) { var packData = GContext.container.Resolve(); var packMain = packData?.EventPinataPackMain; var iAct = GContext.container.ResolveAct(packMain.ActPrefab); if (iAct is PinataPackAct pinataPackAct) _parent = pinataPackAct.transform; } if (_parent != null) transform.SetParent(_parent); transform.localScale = Vector3.one; } public void ReturnPool() { _pool?.DespawnObject(this); } } }