WinterJamSnowman/Assets/Scripts/LemonGenericLib/Visual Effects/VFX_Manager.cs

69 lines
1.7 KiB
C#
Raw Normal View History

2023-01-24 13:51:46 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
//namespace Lemon.GenericLib.VFX
//{
public class VFX_Manager : MonoBehaviour
{
public static VFX_Manager insatnceVFXM;
private void Awake()
{
if (insatnceVFXM == null)
{
insatnceVFXM = this;
}
if (insatnceVFXM != this)
{
Destroy(gameObject);
}
}
[SerializeField] vfxData[] allVFXData;
private Dictionary<string, vfxData> vfxDictionary;
[Serializable]
struct vfxData
{
public string vfxName;
public GameObject vfxObject;
public bool shouldKill;
public float lifeTime;
}
private void Start()
{
vfxDictionary = new Dictionary<string, vfxData>();
foreach (var item in allVFXData)
{
vfxDictionary.Add(item.vfxName, item);
}
}
public GameObject spawnVFX(string vfxname, Vector3 position)
{
if (vfxDictionary.ContainsKey(vfxname))
{
GameObject newVFX = Instantiate(vfxDictionary[vfxname].vfxObject, position, Quaternion.identity);
if (vfxDictionary[vfxname].shouldKill)
{
Destroy(newVFX, vfxDictionary[vfxname].lifeTime);
}
return newVFX;
}
else
{
Debug.LogError($"vfx with name {vfxname} does not exist.\nPlease check if the spelling is correct.");
return null;
}
}
}
//}