< 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        {
 58529            var characterController = DCLCharacterController.i;
 30
 58531            if (characterController != null)
 32            {
 58533                characterController.OnJump += OnJump;
 58534                characterController.OnHitGround += OnLand;
 58535                characterController.OnMoved += OnWalk;
 36            }
 37
 58538            AudioContainer ac = GetComponent<AudioContainer>();
 58539            footstepJump = ac.GetEvent("FootstepJump");
 58540            footstepLand = ac.GetEvent("FootstepLand");
 58541            footstepWalk = ac.GetEvent("FootstepWalk");
 58542            footstepRun = ac.GetEvent("FootstepRun");
 58543            clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 58544        }
 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        {
 6756            if (footstepLand != null)
 6757                footstepLand.Play(true);
 6758            if (stickersController != null)
 6759                stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up,
 6760        }
 61
 62        // Faking footsteps when in first-person mode, since animations won't play
 63        void OnWalk(float distance)
 64        {
 11265            if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 066                return;
 67
 11268            if (intervalTimer < 0f)
 69            {
 1770                distance /= Time.deltaTime;
 71
 1772                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                {
 1684                    if (footstepWalk != null)
 1685                        footstepWalk.Play(true);
 86
 1687                    if (clothesRustleShort != null)
 1688                        clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 89
 1690                    intervalTimer = WALK_INTERVAL_SEC;
 91                }
 92            }
 93
 11294            intervalTimer -= Time.deltaTime;
 11295        }
 96    }
 97}