< Summary

Class:DCL.AvatarAudioHandlerLocal
Assembly:AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAudioHandlerLocal.cs
Covered lines:34
Uncovered lines:6
Coverable lines:40
Total lines:97
Line coverage:85% (34 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%220100%
OnJump()0%12300%
OnLand()0%330100%
OnWalk(...)0%8.018094.44%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAudioHandlerLocal.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace 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        {
 59729            var characterController = DCLCharacterController.i;
 30
 59731            if (characterController != null)
 32            {
 59733                characterController.OnJump += OnJump;
 59734                characterController.OnHitGround += OnLand;
 59735                characterController.OnMoved += OnWalk;
 36            }
 37
 59738            AudioContainer ac = GetComponent<AudioContainer>();
 59739            footstepJump = ac.GetEvent("FootstepJump");
 59740            footstepLand = ac.GetEvent("FootstepLand");
 59741            footstepWalk = ac.GetEvent("FootstepWalk");
 59742            footstepRun = ac.GetEvent("FootstepRun");
 59743            clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 59744        }
 45
 46        void OnJump()
 47        {
 048            if (footstepJump != null)
 049                footstepJump.Play(true);
 050            if (stickersController != null)
 051                stickersController.PlaySticker("footstepJump", transform.position + jumpLandParticlesOffset, Vector3.up,
 052        }
 53
 54        void OnLand()
 55        {
 5456            if (footstepLand != null)
 5457                footstepLand.Play(true);
 5458            if (stickersController != null)
 5459                stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up,
 5460        }
 61
 62        // Faking footsteps when in first-person mode, since animations won't play
 63        void OnWalk(float distance)
 64        {
 5965            if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 066                return;
 67
 5968            if (intervalTimer < 0f)
 69            {
 870                distance /= Time.deltaTime;
 71
 872                if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 73                {
 174                    if (footstepRun != null)
 175                        footstepRun.Play(true);
 76
 177                    if (clothesRustleShort != null)
 178                        clothesRustleShort.Play(true);
 79
 180                    intervalTimer = RUN_INTERVAL_SEC;
 181                }
 82                else
 83                {
 784                    if (footstepWalk != null)
 785                        footstepWalk.Play(true);
 86
 787                    if (clothesRustleShort != null)
 788                        clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 89
 790                    intervalTimer = WALK_INTERVAL_SEC;
 91                }
 92            }
 93
 5994            intervalTimer -= Time.deltaTime;
 5995        }
 96    }
 97}