chore : change footsteps detection from tag to custom comp

This commit is contained in:
Hugo Le Bolloc'h
2026-03-28 19:34:15 +01:00
parent 9f6eb731c4
commit 5c01b640df
9 changed files with 99 additions and 85 deletions
@@ -16,7 +16,7 @@ public class Audio_FootstepsController : MonoBehaviour
public AK.Wwise.Event footstepEvent;
[Header("Surface Configuration")]
public List<SurfaceMapping> surfaces = new List<SurfaceMapping>();
public AK.Wwise.Switch defaultSwitch;
[Header("Movement Settings")]
@@ -27,22 +27,11 @@ public class Audio_FootstepsController : MonoBehaviour
private CharacterController _controller;
private float _timer;
private Dictionary<string, AK.Wwise.Switch> _surfaceCache;
void Awake()
{
_controller = GetComponent<CharacterController>();
_surfaceCache = new Dictionary<string, AK.Wwise.Switch>();
foreach (var mapping in surfaces)
{
if (!string.IsNullOrEmpty(mapping.tag))
{
_surfaceCache[mapping.tag.ToLower()] = mapping.wwiseSwitch;
}
}
}
void Update()
@@ -67,19 +56,18 @@ public class Audio_FootstepsController : MonoBehaviour
RaycastHit hit;
if (Physics.Raycast(transform.position + Vector3.up * 0.1f, Vector3.down, out hit, _rayDistance, _groundLayer))
{
string currentTag = hit.collider.tag.ToLower();
if (_surfaceCache.TryGetValue(currentTag, out AK.Wwise.Switch targetSwitch))
if (hit.collider.TryGetComponent<Audio_SoundSurface>(out var surface))
{
targetSwitch.SetValue(gameObject);
// Debug.Log($"[Footsteps] Switch Wwise set on : {currentTag}");
surface.wwiseSwitch.SetValue(gameObject);
}
else
{
defaultSwitch.SetValue(gameObject);
Debug.LogWarning($"[Footsteps] Tag '{currentTag}' inconnu. Utilisation du switch par défaut.");
Debug.LogWarning($"[Footsteps] No GroundSurface component on '{hit.collider.name}'. Utilisation du switch par défaut.");
}
footstepEvent.Post(gameObject);
}
@@ -0,0 +1,7 @@
using UnityEngine;
using AK.Wwise;
public class Audio_SoundSurface : MonoBehaviour
{
public AK.Wwise.Switch wwiseSwitch;
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3ec78f9fa08450a4fb1c6ef69da4e22c