This commit is contained in:
manhduyhoang90
2026-06-05 17:16:23 +07:00
2 changed files with 113 additions and 87 deletions

View File

@@ -100,8 +100,7 @@ BlendTree:
m_Name: Idle
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 5908583710877457969, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: 5908583710877457969, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -117,8 +116,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 5908583710877457969, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: 5908583710877457969, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -1
@@ -738,8 +736,7 @@ BlendTree:
m_Name: CroouchIdleAiming
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -755,8 +752,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -1
@@ -942,8 +938,7 @@ AnimatorState:
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 6273134904810983842, guid: 632f8ebe81a772e4998224dabbbf836b,
type: 3}
m_Motion: {fileID: 6273134904810983842, guid: 632f8ebe81a772e4998224dabbbf836b, type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
@@ -1066,8 +1061,7 @@ BlendTree:
m_Name: CrouchIdle
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 2
@@ -1083,8 +1077,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -2
@@ -1371,8 +1364,7 @@ BlendTree:
m_Name: Blend Tree
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 6944727830613845018, guid: f63fbd0ba70f1554c9dc5f893ff28546,
type: 3}
m_Motion: {fileID: 6944727830613845018, guid: f63fbd0ba70f1554c9dc5f893ff28546, type: 3}
m_Threshold: -170
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -1380,8 +1372,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 5927633979316069339, guid: f63fbd0ba70f1554c9dc5f893ff28546,
type: 3}
m_Motion: {fileID: 5927633979316069339, guid: f63fbd0ba70f1554c9dc5f893ff28546, type: 3}
m_Threshold: -90
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -1389,8 +1380,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7173170133434809738, guid: f63fbd0ba70f1554c9dc5f893ff28546,
type: 3}
m_Motion: {fileID: 7173170133434809738, guid: f63fbd0ba70f1554c9dc5f893ff28546, type: 3}
m_Threshold: 0
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -1398,8 +1388,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -4636754764438762427, guid: f63fbd0ba70f1554c9dc5f893ff28546,
type: 3}
m_Motion: {fileID: -4636754764438762427, guid: f63fbd0ba70f1554c9dc5f893ff28546, type: 3}
m_Threshold: 90
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -1407,8 +1396,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -606276786794296147, guid: f63fbd0ba70f1554c9dc5f893ff28546,
type: 3}
m_Motion: {fileID: -606276786794296147, guid: f63fbd0ba70f1554c9dc5f893ff28546, type: 3}
m_Threshold: 170
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -14735,7 +14723,7 @@ AnimatorStateMachine:
m_Position: {x: -288, y: -120, z: 0}
- serializedVersion: 1
m_StateMachine: {fileID: 1107822795797827924}
m_Position: {x: -288, y: -180, z: 0}
m_Position: {x: -290, y: -180, z: 0}
- serializedVersion: 1
m_StateMachine: {fileID: 2678945455928377032}
m_Position: {x: -290, y: -240, z: 0}
@@ -20946,8 +20934,7 @@ BlendTree:
m_Name: Bow_Idle
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -744450954914381049, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -744450954914381049, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 2
@@ -20963,8 +20950,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -744450954914381049, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -744450954914381049, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -2
@@ -33694,7 +33680,7 @@ AnimatorStateMachine:
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 1102974793704474096}
m_Position: {x: 264, y: 168, z: 0}
m_Position: {x: 260, y: 170, z: 0}
- serializedVersion: 1
m_State: {fileID: 1102332861771149508}
m_Position: {x: 260, y: 70, z: 0}
@@ -33710,7 +33696,7 @@ AnimatorStateMachine:
m_AnyStatePosition: {x: 48, y: 168, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 504, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 24, y: -24, z: 0}
m_ParentStateMachinePosition: {x: 30, y: -20, z: 0}
m_DefaultState: {fileID: 1102332861771149508}
--- !u!1107 &1107815003637627098
AnimatorStateMachine:
@@ -35894,8 +35880,7 @@ BlendTree:
m_Name: Crouch Idle
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 2
@@ -35911,8 +35896,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -2893743026720447327, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -2
@@ -36478,8 +36462,7 @@ BlendTree:
m_Name: Idle Aiming
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.5
m_Position: {x: 0, y: 0}
m_TimeScale: 2
@@ -36487,8 +36470,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -0.2
m_Position: {x: 0, y: 0}
m_TimeScale: 0.5
@@ -36504,8 +36486,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.2
m_Position: {x: 0, y: 0}
m_TimeScale: -0.5
@@ -36513,8 +36494,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5495367200724739231, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 0.5
m_Position: {x: 0, y: 0}
m_TimeScale: -2
@@ -36682,8 +36662,7 @@ BlendTree:
m_Name: Holding Melee Idle
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: -5508357832084655506, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5508357832084655506, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: -1
m_Position: {x: 0, y: 0}
m_TimeScale: 1
@@ -36699,8 +36678,7 @@ BlendTree:
m_DirectBlendParameter: InputHorizontal
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: -5508357832084655506, guid: 009c43c371cbf974f860ee540816fa3d,
type: 3}
m_Motion: {fileID: -5508357832084655506, guid: 009c43c371cbf974f860ee540816fa3d, type: 3}
m_Threshold: 1
m_Position: {x: 0, y: 0}
m_TimeScale: -1

View File

@@ -70,7 +70,6 @@ public class AnimatorAI : MonoBehaviour
protected virtual void Start()
{
// Sử dụng GetComponentInChildren để tìm Animator ở các đối tượng con (khung Mesh)
animator = GetComponentInChildren<Animator>();
enemyAI = GetComponent<EnemyAI>();
agent = GetComponent<NavMeshAgent>();
@@ -79,54 +78,103 @@ public class AnimatorAI : MonoBehaviour
if (animator == null)
{
Debug.LogError($"<color=red>[AnimatorAI]</color> KHÔNG tìm thấy Animator trên {gameObject.name} hoặc các con của nó!");
}
else if (debugMode)
{
Debug.Log($"<color=green>[AnimatorAI]</color> Đã tìm thấy Animator trên đối tượng: {animator.gameObject.name}");
return;
}
// CHẨN ĐOÁN SÂU:
if (debugMode) StartCoroutine(DeepDiagnosticRoutine());
InitializeParameters();
}
private IEnumerator DeepDiagnosticRoutine()
{
while (true)
{
yield return new WaitForSeconds(2f); // Kiểm tra mỗi 2 giây
if (animator == null) yield break;
// 1. Kiểm tra Avatar
if (animator.avatar == null)
Debug.LogError($"<color=red>[T-POSE ALERT]</color> {animator.gameObject.name} KHÔNG CÓ AVATAR! Đây là lý do bị T-Pose. Hãy kéo Avatar vào component Animator.");
// 2. Kiểm tra Speed
if (animator.speed <= 0)
Debug.LogWarning($"<color=yellow>[T-POSE ALERT]</color> Tốc độ Animator đang bằng {animator.speed}. Nhân vật sẽ không cử động.");
// 3. Kiểm tra Animation Clips
var stateInfo = animator.GetCurrentAnimatorStateInfo(0);
var clipInfo = animator.GetCurrentAnimatorClipInfo(0);
if (clipInfo.Length == 0)
{
Debug.LogError($"<color=red>[T-POSE ALERT]</color> State hiện tại ({stateInfo.fullPathHash}) KHÔNG CÓ Clip animation nào! Hãy kéo file .anim vào ô Motion của State trong Animator Controller.");
}
// 4. Kiểm tra Culling
if (animator.cullingMode == AnimatorCullingMode.CullCompletely)
{
// Đôi khi Unity tự tắt animation nếu camera không nhìn thấy
Debug.Log($"<color=white>[Info]</color> Culling Mode đang là CullCompletely. Nếu nhân vật ở xa có thể sẽ dừng animation.");
}
if (!useSimulation) yield break; // Nếu không dùng simulation thì chỉ check 1 lần rồi thôi
}
}
protected virtual void InitializeParameters()
{
if (animator == null) return;
isDead = new vAnimatorParameter(animator, "isDead");
isGrounded = new vAnimatorParameter(animator, "IsGrounded");
isCrouching = new vAnimatorParameter(animator, "IsCrouching");
isStrafing = new vAnimatorParameter(animator, "IsStrafing");
isSliding = new vAnimatorParameter(animator, "IsSliding");
isSprinting = new vAnimatorParameter(animator, "IsSprinting");
isAiming = new vAnimatorParameter(animator, "IsAiming");
canAim = new vAnimatorParameter(animator, "CanAim");
flipAnimation = new vAnimatorParameter(animator, "FlipAnimation");
flipEquip = new vAnimatorParameter(animator, "FlipEquip");
groundDistance = new vAnimatorParameter(animator, "GroundDistance");
groundAngle = new vAnimatorParameter(animator, "GroundAngle");
verticalVelocity = new vAnimatorParameter(animator, "VerticalVelocity");
moveSet_ID = new vAnimatorParameter(animator, "MoveSet_ID");
upperBody_ID = new vAnimatorParameter(animator, "UpperBody_ID");
idleRandom = new vAnimatorParameter(animator, "IdleRandom");
idleRandomTrigger = new vAnimatorParameter(animator, "IdleRandomTrigger");
randomAttack = new vAnimatorParameter(animator, "RandomAttack");
weakAttack = new vAnimatorParameter(animator, "WeakAttack");
strongAttack = new vAnimatorParameter(animator, "StrongAttack");
isBlocking = new vAnimatorParameter(animator, "IsBlocking");
attackID = new vAnimatorParameter(animator, "AttackID");
defenseID = new vAnimatorParameter(animator, "DefenseID");
recoilID = new vAnimatorParameter(animator, "RecoilID");
reactionID = new vAnimatorParameter(animator, "ReactionID");
triggerRecoil = new vAnimatorParameter(animator, "TriggerRecoil");
triggerReaction = new vAnimatorParameter(animator, "TriggerReaction");
hitDirection = new vAnimatorParameter(animator, "HitDirection");
resetState = new vAnimatorParameter(animator, "ResetState");
reload = new vAnimatorParameter(animator, "Reload");
cancelReload = new vAnimatorParameter(animator, "CancelReload");
reloadID = new vAnimatorParameter(animator, "ReloadID");
shoot = new vAnimatorParameter(animator, "Shoot");
shot_ID = new vAnimatorParameter(animator, "Shot_ID");
powerCharger = new vAnimatorParameter(animator, "PowerCharger");
// Khởi tạo và kiểm tra từng tham số quan trọng
isDead = ValidateAndInit("isDead");
isGrounded = ValidateAndInit("IsGrounded");
isCrouching = ValidateAndInit("IsCrouching");
isStrafing = ValidateAndInit("IsStrafing");
isSliding = ValidateAndInit("IsSliding");
isSprinting = ValidateAndInit("IsSprinting");
isAiming = ValidateAndInit("IsAiming");
canAim = ValidateAndInit("CanAim");
flipAnimation = ValidateAndInit("FlipAnimation");
flipEquip = ValidateAndInit("FlipEquip");
groundDistance = ValidateAndInit("GroundDistance");
groundAngle = ValidateAndInit("GroundAngle");
verticalVelocity = ValidateAndInit("VerticalVelocity");
moveSet_ID = ValidateAndInit("MoveSet_ID");
upperBody_ID = ValidateAndInit("UpperBody_ID");
idleRandom = ValidateAndInit("IdleRandom");
idleRandomTrigger = ValidateAndInit("IdleRandomTrigger");
randomAttack = ValidateAndInit("RandomAttack");
weakAttack = ValidateAndInit("WeakAttack");
strongAttack = ValidateAndInit("StrongAttack");
isBlocking = ValidateAndInit("IsBlocking");
attackID = ValidateAndInit("AttackID");
defenseID = ValidateAndInit("DefenseID");
recoilID = ValidateAndInit("RecoilID");
reactionID = ValidateAndInit("ReactionID");
triggerRecoil = ValidateAndInit("TriggerRecoil");
triggerReaction = ValidateAndInit("TriggerReaction");
hitDirection = ValidateAndInit("HitDirection");
resetState = ValidateAndInit("ResetState");
reload = ValidateAndInit("Reload");
cancelReload = ValidateAndInit("CancelReload");
reloadID = ValidateAndInit("ReloadID");
shoot = ValidateAndInit("Shoot");
shot_ID = ValidateAndInit("Shot_ID");
powerCharger = ValidateAndInit("PowerCharger");
}
private vAnimatorParameter ValidateAndInit(string paramName)
{
vAnimatorParameter p = new vAnimatorParameter(animator, paramName);
if (!p.isValid && debugMode)
{
// Chỉ cảnh báo những biến cốt lõi nếu thiếu
if (paramName == "VerticalVelocity" || paramName == "IsGrounded" || paramName == "IsAiming")
Debug.LogWarning($"<color=yellow>[AnimatorAI]</color> Cảnh báo: Controller thiếu biến quan trọng: <b>{paramName}</b>");
}
return p;
}
protected virtual void Update()