142fabf108
# Conflicts: # Assets/PerfectWorld/Prefab/GameController.prefab # Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs # Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs # Assets/Scripts/CECGameRun.cs # Assets/Scripts/CECHostPlayer.cs # Assets/Scripts/PlayerVisual.cs
135 lines
4.2 KiB
C#
135 lines
4.2 KiB
C#
using Animancer;
|
|
using BrewMonster;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static CECPlayer;
|
|
|
|
public class PlayerVisual : MonoBehaviour
|
|
{
|
|
[SerializeField] NamedAnimancerComponent namedAnimancer;
|
|
|
|
[SerializeField] private INFO _playerInfo;
|
|
private Dictionary<string, AnimancerState> _activeStates = new();
|
|
[SerializeField] private AnimancerState _currentState;
|
|
[SerializeField] private Queue<string> _animationQueue = new Queue<string>();
|
|
[SerializeField] private bool isHit;
|
|
[SerializeField] private int id;
|
|
|
|
QueueActionEvent queueActionEvent;
|
|
|
|
private void PlayActionEventHandler(PlayActionEvent @event)
|
|
{
|
|
_currentState = namedAnimancer.TryPlay(@event.AnimationName);
|
|
if (_currentState == null)
|
|
{
|
|
BMLogger.LogError("HoangDev: PlayActionEventHandler Failed " + @event.AnimationName);
|
|
}
|
|
}
|
|
public void InitPlayerEventDoneHandler()
|
|
{
|
|
namedAnimancer = GetComponentInChildren<NamedAnimancerComponent>();
|
|
if (namedAnimancer == null)
|
|
{
|
|
BrewMonster.BMLogger.LogWarning("InitPlayerEventDoneHandler animancer == null");
|
|
return;
|
|
}
|
|
var player = GetComponentInParent<CECPlayer>();
|
|
if (player == null)
|
|
{
|
|
BMLogger.LogWarning("player == null");
|
|
return;
|
|
}
|
|
|
|
_playerInfo = player.GetPlayInfo();
|
|
id = _playerInfo.cid;
|
|
EventBus.SubscribeChannel<PlayActionEvent>(_playerInfo.cid, PlayActionEventHandler);
|
|
EventBus.SubscribeChannelClass<QueueActionEvent>(_playerInfo.cid, QueueActionEventHandler);
|
|
EventBus.SubscribeChannel<CleearComActFlagAllRankNodesEvent>(_playerInfo.cid, CleearComActFlagAllRankNodesEventHandler);
|
|
}
|
|
|
|
public void InitElsePlayerEventDoneHandler(INFO playerInfo)
|
|
{
|
|
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 = playerInfo;//player.GetPlayInfo();
|
|
EventBus.SubscribeChannel<PlayActionEvent>(_playerInfo.cid, PlayActionEventHandler);
|
|
EventBus.SubscribeChannelClass<QueueActionEvent>(_playerInfo.cid, QueueActionEventHandler);
|
|
EventBus.SubscribeChannel<CleearComActFlagAllRankNodesEvent>(_playerInfo.cid, CleearComActFlagAllRankNodesEventHandler);
|
|
}
|
|
|
|
private void CleearComActFlagAllRankNodesEventHandler(CleearComActFlagAllRankNodesEvent @event)
|
|
{
|
|
_animationQueue.Clear();
|
|
if (isHit)
|
|
{
|
|
ApplyDamage();
|
|
}
|
|
}
|
|
|
|
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;
|
|
_animationQueue.Enqueue(@event.AnimationName);
|
|
if (!isHit)
|
|
{
|
|
queueActionEvent = @event;
|
|
isHit = @event.IsHitAnim;
|
|
}
|
|
return true;
|
|
}
|
|
private void PlayNext()
|
|
{
|
|
if (_animationQueue.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (_currentState == null) return;
|
|
if (_currentState.NormalizedTime < 1f) return;
|
|
if (isHit)
|
|
{
|
|
ApplyDamage();
|
|
}
|
|
string animName = _animationQueue.Dequeue();
|
|
_currentState = namedAnimancer.TryPlay(animName);
|
|
|
|
}
|
|
void ApplyDamage()
|
|
{
|
|
if(queueActionEvent == null) return;
|
|
isHit = false;
|
|
queueActionEvent.SetFlag(true, queueActionEvent.AttackEvent);
|
|
queueActionEvent = null;
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
EventBus.UnsubscribeAllInChannel(_playerInfo.cid);
|
|
}
|
|
public bool IsAnimationExist(string animationName)
|
|
{
|
|
return namedAnimancer.States.TryGet("ActionName", out var existingState) ? true : false;
|
|
}
|
|
}
|