This commit is contained in:
2026-06-05 21:24:41 +07:00
parent 91183760fb
commit 98806b862d
16 changed files with 6386 additions and 3028 deletions

View File

@@ -38,6 +38,13 @@ namespace Invector
EditorGUILayout.PropertyField(serializedObject.FindProperty("_useTriggerEnter"));
serializedObject.FindProperty("debugTextureName").boolValue = EditorGUILayout.Toggle("Debug Texture Name", serializedObject.FindProperty("debugTextureName").boolValue);
GUILayout.BeginVertical("box");
GUILayout.Box("AI Noise Settings", GUILayout.ExpandWidth(true));
EditorGUILayout.PropertyField(serializedObject.FindProperty("emitAINoise"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("aiNoiseRange"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("npcLayer"));
GUILayout.EndVertical();
if (serializedObject.FindProperty("animationType").enumValueIndex == (int)AnimationType.Humanoid)
{
GUILayout.BeginHorizontal("box");

View File

@@ -20,6 +20,11 @@ namespace Invector
public bool SpawnParticle { get { return _spawnParticle; } set { _spawnParticle = value; } }
public bool SpawnStepMark { get { return _spawnStepMark; } set { _spawnStepMark = value; } }
[Header("AI Noise Settings")]
public bool emitAINoise = true;
public float aiNoiseRange = 10f;
public LayerMask npcLayer;
protected int surfaceIndex = 0;
protected Terrain terrain;
protected TerrainCollider terrainCollider;
@@ -248,6 +253,37 @@ namespace Invector
currentFootStep.spawnParticleEffect = SpawnParticle;
currentFootStep.spawnStepMarkEffect = SpawnStepMark;
SpawnSurfaceEffect(currentFootStep);
if (emitAINoise) EmitAINoise();
}
}
protected virtual void EmitAINoise()
{
float currentRange = aiNoiseRange;
float currentVolume = Volume;
// Kiểm tra trạng thái ngồi từ Animator
Animator anim = GetComponent<Animator>();
if (anim != null)
{
// Nếu đang ngồi (IsCrouching = true), giảm 50% vùng phát hiện và âm lượng
if (anim.GetBool("IsCrouching"))
{
currentRange *= 0.5f;
currentVolume *= 0.5f;
}
}
// Tìm tất cả Collider trong bán kính tiếng động thuộc Layer NPC
Collider[] hitColliders = Physics.OverlapSphere(transform.position, currentRange, npcLayer);
foreach (var hit in hitColliders)
{
var npc = hit.GetComponentInParent<EnemyAI>();
if (npc != null)
{
npc.HearNoise(transform.position, currentVolume);
}
}
}