Files
test/Assets/PerfectWorld/Scripts/NPC/NPCVisual.cs
T
2025-10-14 14:57:19 +07:00

54 lines
1.4 KiB
C#

using Animancer;
using BrewMonster;
using UnityEngine;
public class NPCVisual : MonoBehaviour
{
[SerializeField] NamedAnimancerComponent namedAnimancer;
#if UNITY_EDITOR
[SerializeField] bool isDebug;
public void DEBUG(string text)
{
if(!isDebug) return;
BMLogger.LogError(text);
}
#endif
public bool TryPlayAction(string animationName)
{
DEBUG("HoangDev: TryPlayAction: " + animationName);
if (namedAnimancer == null) return false;
if (namedAnimancer.IsPlaying(animationName)) return false;
return namedAnimancer.TryPlay(animationName) == null;
}
public void InitNPCEventDoneHandler()
{
namedAnimancer = GetComponentInChildren<NamedAnimancerComponent>();
if (namedAnimancer == null)
{
BrewMonster.BMLogger.LogError("animancer == null");
return;
}
}
private void OnDestroy()
{
}
public bool IsAnimationExist(string animationName)
{
if (namedAnimancer == null) return false;
return namedAnimancer.States.TryGet(animationName, out var existingState) ? true : false;
}
public bool IsPlayAnimation()
{
if (namedAnimancer == null) return false;
return namedAnimancer.IsPlaying();
}
public bool IsPlayAnimation(string animationName)
{
if (namedAnimancer == null) return false;
return namedAnimancer.IsPlaying(animationName);
}
}