TowerDefenseGame/Assets/_GAME_/Vfx/VfxHandlerBase.cs
2025-06-27 21:06:29 -07:00

36 lines
1.3 KiB
C#

using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
[CreateAssetMenu(menuName = "Custom/VfxHandler", fileName = "NewVfxHandler")]
public class VfxHandlerBase : ScriptableObject {
[Header("VFX Dependencies")]
public GameObject VfxExplosion;
private GameObject VfxExplosionParentInstance;
private List<ParticleSystem> VfxExplosionParticles = new List<ParticleSystem>();
private void OnEnable() {
GenerateInstance();
}
private void GenerateInstance() {
VfxExplosionParticles.Clear();
if (VfxExplosion) {
VfxExplosionParentInstance = Instantiate(VfxExplosion, Vector3.one, Quaternion.identity);
var foundParticleSystems = VfxExplosionParentInstance.GetComponentsInChildren<ParticleSystem>();
VfxExplosionParticles.AddRange(foundParticleSystems);
VfxExplosionParticles.ForEach((x) => x.transform.localScale = Vector3.one);
}
}
public void PlayAll(Vector3? location = null, Quaternion? rotation = null) {
if (!VfxExplosionParentInstance) GenerateInstance();
if (location != null) VfxExplosionParentInstance.transform.position = (Vector3)location;
if (rotation != null) VfxExplosionParentInstance.transform.rotation = (Quaternion)rotation;
VfxExplosionParticles.ForEach((x) => x.Play());
}
}