fix bug animation wound npc
This commit is contained in:
@@ -1,38 +1,40 @@
|
||||
using Animancer;
|
||||
using Animancer;
|
||||
using BrewMonster;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerVisual : MonoBehaviour
|
||||
{
|
||||
[SerializeField] NamedAnimancerComponent namedAnimancer;
|
||||
[SerializeField] NamedAnimancerComponent namedAnimancer;
|
||||
|
||||
[SerializeField] private INFO _playerInfo;
|
||||
|
||||
|
||||
[SerializeField] private AnimancerState _currentState;
|
||||
private readonly Queue<string> _animationQueue = new Queue<string>();
|
||||
[SerializeField] private bool pActFlag;
|
||||
[SerializeField] private bool isHit;
|
||||
|
||||
|
||||
private void PlayActionEventHandler(PlayActionEvent @event)
|
||||
{
|
||||
_currentState = namedAnimancer.TryPlay(@event.AnimationName);
|
||||
if(_currentState == null)
|
||||
if (_currentState == null)
|
||||
{
|
||||
BMLogger.LogError("HoangDev: PlayActionEventHandler Failed ");
|
||||
BMLogger.LogError("HoangDev: PlayActionEventHandler Failed " + @event.AnimationName);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitHostPlayerEventDoneHandler()
|
||||
{
|
||||
namedAnimancer = GetComponentInChildren<NamedAnimancerComponent>();
|
||||
if(namedAnimancer == null)
|
||||
if (namedAnimancer == null)
|
||||
{
|
||||
BrewMonster.BMLogger.LogError("animancer == null");
|
||||
return;
|
||||
}
|
||||
var player = GetComponentInParent<CECPlayer>();
|
||||
if(player == null)
|
||||
if (player == null)
|
||||
{
|
||||
BrewMonster.BMLogger.LogError("player == null");
|
||||
return;
|
||||
@@ -44,39 +46,49 @@ public class PlayerVisual : MonoBehaviour
|
||||
|
||||
private void QueueActionEventHandler(QueueActionEvent @event)
|
||||
{
|
||||
if(!EnqueueAnimation(@event.AnimationName))
|
||||
if (!EnqueueAnimation(@event))
|
||||
{
|
||||
BMLogger.LogError("HoangDev : EnqueueAnimation Failed");
|
||||
}
|
||||
}
|
||||
public bool EnqueueAnimation(string animName)
|
||||
private void Update()
|
||||
{
|
||||
PlayNext();
|
||||
}
|
||||
public bool EnqueueAnimation(QueueActionEvent @event)
|
||||
{
|
||||
if (namedAnimancer == null) return false;
|
||||
_animationQueue.Enqueue(animName);
|
||||
if (!namedAnimancer.IsPlaying())
|
||||
PlayNext();
|
||||
else
|
||||
{
|
||||
if (_currentState == null) return false;
|
||||
_currentState.Events.OnEnd = PlayNext;
|
||||
}
|
||||
BMLogger.LogError("HoangDev : @event.PActFlag1 :" + @event.PActFlag);
|
||||
|
||||
_animationQueue.Enqueue(@event.AnimationName);
|
||||
pActFlag = @event.PActFlag;
|
||||
isHit = @event.IsHitAnim;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void PlayNext()
|
||||
{
|
||||
if (_animationQueue.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_currentState == null) return;
|
||||
if(_currentState.IsPlaying) return;
|
||||
if(isHit)
|
||||
{
|
||||
SetpActFlagTrue();
|
||||
isHit = false;
|
||||
return;
|
||||
}
|
||||
string animName = _animationQueue.Dequeue();
|
||||
var state = namedAnimancer.TryPlay(animName);
|
||||
|
||||
// Khi clip kết thúc thì gọi tiếp cái kế tiếp
|
||||
state.Events.OnEnd = PlayNext;
|
||||
}
|
||||
private void SetpActFlagTrue()
|
||||
{
|
||||
pActFlag = true;
|
||||
BMLogger.LogError("HoangDev : SetpActFlagTrue :");
|
||||
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
EventBus.UnsubscribeAllInChannel(_playerInfo.cid);
|
||||
|
||||
Reference in New Issue
Block a user