117 lines
2.2 KiB
C#
117 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using OHM.UnityToolkit.Pooling;
|
|
|
|
namespace OHM.UnityToolkit
|
|
{
|
|
public class FX : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
public Animator animator;
|
|
|
|
[SerializeField]
|
|
public ParticleSystem[] particlesArray;
|
|
|
|
[SerializeField]
|
|
public SFX soundFx;
|
|
|
|
[SerializeField]
|
|
public string cameraTrigger;
|
|
|
|
[SerializeField]
|
|
public Transform defaultSpawningCont;
|
|
|
|
[SerializeField]
|
|
public ParticleSystem particles;
|
|
|
|
public SFXInstance SfxInstance { get; set; }
|
|
|
|
public void PlayNow()
|
|
{
|
|
PlayInstance(null, null);
|
|
}
|
|
|
|
public static void TryPlayInstance(FX fx, Transform spawnerObj, Transform otherParent)
|
|
{
|
|
if (fx != null)
|
|
{
|
|
fx.PlayInstance(spawnerObj, otherParent);
|
|
}
|
|
}
|
|
|
|
public FX PlayInstance(Transform spawnerObj, Transform otherParent)
|
|
{
|
|
Transform parent = ((otherParent != null) ? otherParent : defaultSpawningCont);
|
|
FX instance = PoolsManager.InstantiatePrefab(this, parent, Vector3.zero, Quaternion.identity);
|
|
instance.gameObject.SetActive(value: true);
|
|
instance.PlayInternal();
|
|
if (spawnerObj != null)
|
|
{
|
|
instance.transform.position = spawnerObj.position;
|
|
instance.transform.rotation = spawnerObj.rotation;
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
protected void PlayInternal()
|
|
{
|
|
if (animator != null)
|
|
{
|
|
animator.SetTrigger("Play");
|
|
}
|
|
PlayParticles();
|
|
if (soundFx != null)
|
|
{
|
|
soundFx.Play(base.transform);
|
|
}
|
|
if (!string.IsNullOrEmpty(cameraTrigger))
|
|
{
|
|
FXCamAnimator camAnimator = Camera.main.GetComponent<FXCamAnimator>();
|
|
if (camAnimator != null)
|
|
{
|
|
camAnimator.Trigger(cameraTrigger);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PlayParticles()
|
|
{
|
|
if (particles != null)
|
|
{
|
|
particles.Play();
|
|
}
|
|
if (particlesArray == null)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < particlesArray.Length; i++)
|
|
{
|
|
if (particlesArray[i] != null)
|
|
{
|
|
particlesArray[i].Play();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopParticles()
|
|
{
|
|
if (particles != null)
|
|
{
|
|
particles.Stop();
|
|
}
|
|
if (particlesArray == null)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < particlesArray.Length; i++)
|
|
{
|
|
if (particlesArray[i] != null)
|
|
{
|
|
particlesArray[i].Stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|