player animation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Animancer;
|
||||
using Animancer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerVisual : MonoBehaviour
|
||||
@@ -8,11 +9,12 @@ public class PlayerVisual : MonoBehaviour
|
||||
|
||||
[SerializeField] private INFO _playerInfo;
|
||||
|
||||
private AnimancerState _currentState;
|
||||
private readonly Queue<string> _animationQueue = new Queue<string>();
|
||||
|
||||
private void PlayActionEventHandler(PlayActionEvent @event)
|
||||
{
|
||||
BrewMonster.BMLogger.Log("PlayActionEventHandler : "+@event.AnimationName);
|
||||
namedAnimancer.TryPlay(@event.AnimationName);
|
||||
_currentState = namedAnimancer.TryPlay(@event.AnimationName);
|
||||
}
|
||||
|
||||
public void InitHostPlayerEventDoneHandler()
|
||||
@@ -23,7 +25,7 @@ public class PlayerVisual : MonoBehaviour
|
||||
BrewMonster.BMLogger.LogError("animancer == null");
|
||||
return;
|
||||
}
|
||||
var player = GetComponentInParent<EC_Player>();
|
||||
var player = GetComponentInParent<CECPlayer>();
|
||||
if(player == null)
|
||||
{
|
||||
BrewMonster.BMLogger.LogError("player == null");
|
||||
@@ -31,7 +33,38 @@ public class PlayerVisual : MonoBehaviour
|
||||
}
|
||||
_playerInfo = player.GetPlayInfo();
|
||||
EventBus.SubscribeChannel<PlayActionEvent>(_playerInfo.cid, PlayActionEventHandler);
|
||||
EventBus.SubscribeChannel<QueueActionEvent>(_playerInfo.cid, QueueActionEventHandler);
|
||||
}
|
||||
|
||||
private void QueueActionEventHandler(QueueActionEvent @event)
|
||||
{
|
||||
EnqueueAnimation(@event.AnimationName);
|
||||
}
|
||||
public void EnqueueAnimation(string animName)
|
||||
{
|
||||
_animationQueue.Enqueue(animName);
|
||||
if (!namedAnimancer.IsPlaying())
|
||||
PlayNext();
|
||||
else
|
||||
{
|
||||
_currentState.Events.OnEnd = PlayNext;
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayNext()
|
||||
{
|
||||
if (_animationQueue.Count == 0)
|
||||
{
|
||||
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 OnDestroy()
|
||||
{
|
||||
EventBus.UnsubscribeAllInChannel(_playerInfo.cid);
|
||||
|
||||
Reference in New Issue
Block a user