2023-11-15 23:54:54 +08:00
|
|
|
using System;
|
2023-10-29 15:27:13 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITKit.Entities.VFX
|
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
public class EntityVFXPlayer : EntityBehavior
|
2023-10-29 15:27:13 +08:00
|
|
|
{
|
|
|
|
[SerializeReference,SubclassSelector] private IReference[] vfxReferences;
|
|
|
|
[SerializeField] private VFXPlayer vfxPlayer;
|
|
|
|
private readonly List<string> keyWords=new();
|
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
base.OnAwake();
|
|
|
|
keyWords.AddRange(vfxReferences.Select(x=>x.Value));
|
2023-10-30 01:25:53 +08:00
|
|
|
UnityEntity.AddListener<string>(Constant.Animation.Play, Play);
|
2023-10-29 15:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Play(string animationName)
|
|
|
|
{
|
2023-11-15 23:54:54 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (isActiveAndEnabled is false) return;
|
|
|
|
if (keyWords.Contains(animationName) is false) return;
|
|
|
|
vfxPlayer.Execute();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Debug.LogWarning(transform.name);
|
|
|
|
Debug.LogException(e);
|
|
|
|
}
|
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|