feat : basic footstep controller system
This commit is contained in:
@@ -180,8 +180,8 @@ MonoBehaviour:
|
||||
Sprite: {fileID: 0}
|
||||
Languages:
|
||||
Default: 0
|
||||
SaveWritten: {fileID: 11400000, guid: 32dca1ce9df9b064b8a0a2b3ab0fd8dd, type: 2}
|
||||
SaveAudio: {fileID: 11400000, guid: 225ffb773e59f8141bacbba2a9ede731, type: 2}
|
||||
SaveWritten: {fileID: 0}
|
||||
SaveAudio: {fileID: 0}
|
||||
Overrides: []
|
||||
Scenes:
|
||||
SceneDatas: []
|
||||
|
||||
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.1f;
|
||||
[SerializeField] private float rayDistance = 1.2f;
|
||||
[SerializeField] private LayerMask groundLayer;
|
||||
|
||||
private CharacterController _controller;
|
||||
private float _timer;
|
||||
private Dictionary<string, AK.Wwise.Switch> _surfaceCache;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_controller = GetComponent<CharacterController>();
|
||||
|
||||
// On remplit le dictionnaire pour un accès ultra-rapide par le nom du tag
|
||||
_surfaceCache = new Dictionary<string, AK.Wwise.Switch>();
|
||||
foreach (var mapping in surfaces)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(mapping.tag))
|
||||
{
|
||||
// On stocke en minuscule pour éviter les erreurs de casse
|
||||
_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();
|
||||
|
||||
// On cherche le switch dans le dictionnaire
|
||||
if (_surfaceCache.TryGetValue(currentTag, out AK.Wwise.Switch targetSwitch))
|
||||
{
|
||||
targetSwitch.SetValue(gameObject);
|
||||
// Debug.Log($"[Footsteps] Switch Wwise réglé sur : {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
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 585ef86653ff8b34996821f778cfa782
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7b54f077b8751ef4fab18faa68deb555, type: 3}
|
||||
m_Name: 022E15A9-DB2C-45F3-8D60-42B5972AD986
|
||||
m_EditorClassIdentifier: AK.Wwise.Unity.API.WwiseTypes::WwiseSwitchReference
|
||||
objectName: carpet
|
||||
id: 2412606308
|
||||
guid: 022E15A9-DB2C-45F3-8D60-42B5972AD986
|
||||
WwiseSwitchGroupReference: {fileID: 11400000, guid: 7894acdae10032b4fa5eb169b135dab7, type: 2}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cba7dd3dc6dddc744b665136cf09f95f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7b54f077b8751ef4fab18faa68deb555, type: 3}
|
||||
m_Name: 1B0178C8-ACAF-41A3-83AA-085C6045F07C
|
||||
m_EditorClassIdentifier: AK.Wwise.Unity.API.WwiseTypes::WwiseSwitchReference
|
||||
objectName: wood
|
||||
id: 2058049674
|
||||
guid: 1B0178C8-ACAF-41A3-83AA-085C6045F07C
|
||||
WwiseSwitchGroupReference: {fileID: 11400000, guid: 7894acdae10032b4fa5eb169b135dab7, type: 2}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90b25d313fd10fe4bb34ce68d987f60e
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7b54f077b8751ef4fab18faa68deb555, type: 3}
|
||||
m_Name: C2B3EAC0-49E1-4C4B-A47E-8667C7765937
|
||||
m_EditorClassIdentifier: AK.Wwise.Unity.API.WwiseTypes::WwiseSwitchReference
|
||||
objectName: stone
|
||||
id: 1216965916
|
||||
guid: C2B3EAC0-49E1-4C4B-A47E-8667C7765937
|
||||
WwiseSwitchGroupReference: {fileID: 11400000, guid: 7894acdae10032b4fa5eb169b135dab7, type: 2}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cea23ef8af49aa54f9c3833465570bb2
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10d78c2f2a4c09a409f48d467acfee5f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: cb51cd373049a214d85ff57cc88668be, type: 3}
|
||||
m_Name: 8CACC1F3-9150-4639-BB38-0F00BB2E289F
|
||||
m_EditorClassIdentifier: AK.Wwise.Unity.API.WwiseTypes::WwiseSwitchGroupReference
|
||||
objectName: footstepsType
|
||||
id: 520915638
|
||||
guid: 8CACC1F3-9150-4639-BB38-0F00BB2E289F
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7894acdae10032b4fa5eb169b135dab7
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user