| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.CameraTool; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class AvatarAudioHandlerLocal : MonoBehaviour |
| | 9 | | { |
| | 10 | | const float WALK_RUN_CROSSOVER_DISTANCE = 7.3f; |
| | 11 | | const float WALK_INTERVAL_SEC = 0.4f; |
| | 12 | | const float RUN_INTERVAL_SEC = 0.27f; |
| | 13 | |
|
| | 14 | | [SerializeField] |
| | 15 | | Vector3 jumpLandParticlesOffset; |
| | 16 | |
|
| | 17 | | [SerializeField] |
| | 18 | | StickersController stickersController; |
| | 19 | |
|
| | 20 | | float intervalTimer = 0f; |
| | 21 | |
|
| | 22 | | AudioEvent footstepJump; |
| | 23 | | AudioEvent footstepLand; |
| | 24 | | AudioEvent footstepWalk; |
| | 25 | | AudioEvent footstepRun; |
| | 26 | | AudioEvent clothesRustleShort; |
| | 27 | |
|
| | 28 | | private void Start() |
| | 29 | | { |
| 592 | 30 | | var characterController = DCLCharacterController.i; |
| | 31 | |
|
| 592 | 32 | | if (characterController != null) |
| | 33 | | { |
| 592 | 34 | | characterController.OnJump += OnJump; |
| 592 | 35 | | characterController.OnHitGround += OnLand; |
| 592 | 36 | | characterController.OnMoved += OnWalk; |
| | 37 | | } |
| | 38 | |
|
| 592 | 39 | | AudioContainer ac = GetComponent<AudioContainer>(); |
| 592 | 40 | | footstepJump = ac.GetEvent("FootstepJump"); |
| 592 | 41 | | footstepLand = ac.GetEvent("FootstepLand"); |
| 592 | 42 | | footstepWalk = ac.GetEvent("FootstepWalk"); |
| 592 | 43 | | footstepRun = ac.GetEvent("FootstepRun"); |
| 592 | 44 | | clothesRustleShort = ac.GetEvent("ClothesRustleShort"); |
| 592 | 45 | | } |
| | 46 | |
|
| | 47 | | void OnJump() |
| | 48 | | { |
| 0 | 49 | | if (footstepJump != null) |
| 0 | 50 | | footstepJump.Play(true); |
| 0 | 51 | | if (stickersController != null) |
| 0 | 52 | | stickersController.PlaySticker("footstepJump", transform.position + jumpLandParticlesOffset, Vector3.up, |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | void OnLand() |
| | 56 | | { |
| 19 | 57 | | if (footstepLand != null) |
| 19 | 58 | | footstepLand.Play(true); |
| 19 | 59 | | if (stickersController != null) |
| 19 | 60 | | stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up, |
| 19 | 61 | | } |
| | 62 | |
|
| | 63 | | // Faking footsteps when in first-person mode, since animations won't play |
| | 64 | | void OnWalk(float distance) |
| | 65 | | { |
| 24 | 66 | | if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson) |
| 24 | 67 | | return; |
| | 68 | |
|
| 0 | 69 | | if (intervalTimer < 0f) |
| | 70 | | { |
| 0 | 71 | | distance /= Time.deltaTime; |
| | 72 | |
|
| 0 | 73 | | if (distance > WALK_RUN_CROSSOVER_DISTANCE) |
| | 74 | | { |
| 0 | 75 | | if (footstepRun != null) |
| 0 | 76 | | footstepRun.Play(true); |
| | 77 | |
|
| 0 | 78 | | if (clothesRustleShort != null) |
| 0 | 79 | | clothesRustleShort.Play(true); |
| | 80 | |
|
| 0 | 81 | | intervalTimer = RUN_INTERVAL_SEC; |
| 0 | 82 | | } |
| | 83 | | else |
| | 84 | | { |
| 0 | 85 | | if (footstepWalk != null) |
| 0 | 86 | | footstepWalk.Play(true); |
| | 87 | |
|
| 0 | 88 | | if (clothesRustleShort != null) |
| 0 | 89 | | clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f)); |
| | 90 | |
|
| 0 | 91 | | intervalTimer = WALK_INTERVAL_SEC; |
| | 92 | | } |
| | 93 | | } |
| | 94 | |
|
| 0 | 95 | | intervalTimer -= Time.deltaTime; |
| 0 | 96 | | } |
| | 97 | | } |
| | 98 | | } |