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