player animation

This commit is contained in:
VDH
2025-10-11 16:09:00 +07:00
parent 042b248368
commit bd344fcff5
20 changed files with 211 additions and 873 deletions
+14 -14
View File
@@ -21,7 +21,7 @@ using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Scene = UnityEngine.SceneManagement.Scene;
public class CECHostPlayer : EC_Player
public class CECHostPlayer : CECPlayer
{
[SerializeField] private TextMeshPro txtName;
[SerializeField] private CharacterController controller;
@@ -94,12 +94,12 @@ public class CECHostPlayer : EC_Player
public void SetModelHostPlayer()
{
m_pPlayerModel = NPCManager.Instance.GetModelPlayer();
_pPlayerModel = NPCManager.Instance.GetModelPlayer();
Scene scene = SceneManager.GetSceneByName("WorldRender");
SceneManager.MoveGameObjectToScene(m_pPlayerModel, scene);
m_pPlayerModel.transform.SetParent(parentModel);
m_pPlayerModel.transform.localPosition = Vector3.zero;
m_pPlayerModel.SetActive(true);
SceneManager.MoveGameObjectToScene(_pPlayerModel, scene);
_pPlayerModel.transform.SetParent(parentModel);
_pPlayerModel.transform.localPosition = Vector3.zero;
_pPlayerModel.SetActive(true);
}
private void Start()
{
@@ -374,8 +374,8 @@ public class CECHostPlayer : EC_Player
{
nTimeFly = 700;
if (m_aEquips[(int)EC_IvtrType.IndexOfIteminEquipmentInventory.EQUIPIVTR_PROJECTILE] != 0)
idWeapon = m_aEquips[(int)EC_IvtrType.IndexOfIteminEquipmentInventory.EQUIPIVTR_PROJECTILE];
if (m_aEquips[(int)IndexOfIteminEquipmentInventory.EQUIPIVTR_PROJECTILE] != 0)
idWeapon = m_aEquips[(int)IndexOfIteminEquipmentInventory.EQUIPIVTR_PROJECTILE];
}
}
@@ -466,13 +466,13 @@ public class CECHostPlayer : EC_Player
}
private void OnMsgHstHurtResult(ECMSG Msg)
{
BMLogger.LogError("HoangDev : OnMsgHstHurtResult");
/* BMLogger.LogError("HoangDev : OnMsgHstHurtResult");
int cmd = Convert.ToInt32(Msg.dwParam2);
if (cmd == CommandID.BE_HURT)
{
cmd_be_hurt pCmd = (cmd_be_hurt)Msg.dwParam1;
/* if (pCmd.damage!=0)
Damaged(pCmd->damage);*/
if (pCmd.damage != 0)
Damaged(pCmd->damage);
}
else if (cmd == CommandID.HURT_RESULT)
{
@@ -482,9 +482,9 @@ public class CECHostPlayer : EC_Player
if (UnityGameSession.Instance.GameSession.ISPLAYERID(pCmd.target_id))
{
/*CECElsePlayer pTarget = m_pPlayerMan.GetElsePlayer(pCmd.target_id);
CECElsePlayer pTarget = m_pPlayerMan.GetElsePlayer(pCmd.target_id);
if (pTarget)
pTarget->Damaged(pCmd->damage);*/
pTarget->Damaged(pCmd->damage);
}
else if (UnityGameSession.Instance.GameSession.ISNPCID(pCmd.target_id))
{
@@ -492,7 +492,7 @@ public class CECHostPlayer : EC_Player
if (pTarget)
pTarget.Damaged(pCmd.damage);
}
}
}*/
}
public void OnMsgHstPickupItem(in ECMSG Msg)
{
+3 -3
View File
@@ -4,7 +4,7 @@ using System;
using System.Collections;
using System.Runtime.InteropServices;
using UnityEngine;
using static EC_Player;
using static CECPlayer;
public static class EC_Utility
{
@@ -72,7 +72,7 @@ public static class EC_Utility
{
return Mathf.Sqrt(v.x * v.x + v.z * v.z);
}
public static string BuildActionName(PLAYER_ACTION action, int weaponType)
public static string BuildActionName(PLAYER_ACTION action, int weaponType, string tail = "")
{
string prefix = action.data.ActionPrefix ?? string.Empty;
string suffix = string.Empty;
@@ -84,7 +84,7 @@ public static class EC_Utility
suffix = action.data.action_weapon_suffix[weaponType].Suffix ?? string.Empty;
}
return $"{prefix}_{suffix}";
return $"{prefix}_{suffix}tail";
}
// Build pvp mask
+1 -1
View File
@@ -54,7 +54,7 @@ public class GameController : MonoBehaviour
Debug.LogError("null prefab");
return;
}
EC_Player.InitStaticRes();
CECPlayer.InitStaticRes();
hostPlayer = Instantiate(characterPrefab, transform);
hostPlayer.InitCharacter(info);
cinemachineCamera.Follow = hostPlayer.transform;
+2 -2
View File
@@ -5,11 +5,11 @@ public class InitializePlayer /*: IAutoInitialize*/
{
public void Dispose()
{
EC_Player.Dispose();
CECPlayer.Dispose();
}
public void Initialize()
{
EC_Player.InitStaticRes();
CECPlayer.InitStaticRes();
}
}
+37 -4
View File
@@ -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);