101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
using Animancer;
|
|
using BrewMonster;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerVisual : MonoBehaviour
|
|
{
|
|
[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)
|
|
{
|
|
BMLogger.LogError("HoangDev: PlayActionEventHandler Failed " + @event.AnimationName);
|
|
}
|
|
}
|
|
public void InitHostPlayerEventDoneHandler()
|
|
{
|
|
namedAnimancer = GetComponentInChildren<NamedAnimancerComponent>();
|
|
if (namedAnimancer == null)
|
|
{
|
|
BrewMonster.BMLogger.LogError("animancer == null");
|
|
return;
|
|
}
|
|
var player = GetComponentInParent<CECPlayer>();
|
|
if (player == null)
|
|
{
|
|
BrewMonster.BMLogger.LogError("player == null");
|
|
return;
|
|
}
|
|
_playerInfo = player.GetPlayInfo();
|
|
EventBus.SubscribeChannel<PlayActionEvent>(_playerInfo.cid, PlayActionEventHandler);
|
|
EventBus.SubscribeChannel<QueueActionEvent>(_playerInfo.cid, QueueActionEventHandler);
|
|
}
|
|
|
|
private void QueueActionEventHandler(QueueActionEvent @event)
|
|
{
|
|
if (!EnqueueAnimation(@event))
|
|
{
|
|
BMLogger.LogError("HoangDev : EnqueueAnimation Failed");
|
|
}
|
|
}
|
|
private void Update()
|
|
{
|
|
PlayNext();
|
|
}
|
|
public bool EnqueueAnimation(QueueActionEvent @event)
|
|
{
|
|
if (namedAnimancer == null) return false;
|
|
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);
|
|
|
|
}
|
|
private void SetpActFlagTrue()
|
|
{
|
|
pActFlag = true;
|
|
BMLogger.LogError("HoangDev : SetpActFlagTrue :");
|
|
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
EventBus.UnsubscribeAllInChannel(_playerInfo.cid);
|
|
}
|
|
public bool IsAnimationExist(string animationName)
|
|
{
|
|
return namedAnimancer.States.TryGet("ActionName", out var existingState) ? true : false;
|
|
}
|
|
}
|