This commit is contained in:
Ferlat Thibaud
2026-03-27 16:36:18 +01:00
18 changed files with 503 additions and 40178 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,87 @@
using UnityEngine;
using System.Collections.Generic;
using AK.Wwise;
[RequireComponent(typeof(CharacterController))]
public class Audio_FootstepsController : MonoBehaviour
{
[System.Serializable]
public struct SurfaceMapping
{
public string tag;
public AK.Wwise.Switch wwiseSwitch;
}
[Header("Wwise Assets")]
public AK.Wwise.Event footstepEvent;
[Header("Surface Configuration")]
public List<SurfaceMapping> surfaces = new List<SurfaceMapping>();
public AK.Wwise.Switch defaultSwitch;
[Header("Movement Settings")]
[SerializeField] private float _stepInterval = 0.5f;
[SerializeField] private float _minVelocity = 0.3f;
[SerializeField] private float _rayDistance = 0.2f;
[SerializeField] private LayerMask _groundLayer;
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()
{
if (_controller.isGrounded && _controller.velocity.magnitude > _minVelocity)
{
_timer += Time.deltaTime;
if (_timer >= _stepInterval)
{
PlayFootstep();
_timer = 0f;
}
}
else
{
_timer = _stepInterval;
}
}
private void PlayFootstep()
{
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))
{
targetSwitch.SetValue(gameObject);
// Debug.Log($"[Footsteps] Switch Wwise set on : {currentTag}");
}
else
{
defaultSwitch.SetValue(gameObject);
Debug.LogWarning($"[Footsteps] Tag '{currentTag}' inconnu. Utilisation du switch par défaut.");
}
footstepEvent.Post(gameObject);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a11b07babb12d446a356745e7a37303