< Summary

Class:DCL.AvatarAudioHandlerLocal
Assembly:AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAudioHandlerLocal.cs
Covered lines:35
Uncovered lines:5
Coverable lines:40
Total lines:98
Line coverage:87.5% (35 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%880100%

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 DCL.CameraTool;
 4using UnityEngine;
 5
 6namespace 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        {
 59130            var characterController = DCLCharacterController.i;
 31
 59132            if (characterController != null)
 33            {
 59134                characterController.OnJump += OnJump;
 59135                characterController.OnHitGround += OnLand;
 59136                characterController.OnMoved += OnWalk;
 37            }
 38
 59139            AudioContainer ac = GetComponent<AudioContainer>();
 59140            footstepJump = ac.GetEvent("FootstepJump");
 59141            footstepLand = ac.GetEvent("FootstepLand");
 59142            footstepWalk = ac.GetEvent("FootstepWalk");
 59143            footstepRun = ac.GetEvent("FootstepRun");
 59144            clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 59145        }
 46
 47        void OnJump()
 48        {
 049            if (footstepJump != null)
 050                footstepJump.Play(true);
 051            if (stickersController != null)
 052                stickersController.PlaySticker("footstepJump", transform.position + jumpLandParticlesOffset, Vector3.up,
 053        }
 54
 55        void OnLand()
 56        {
 1257            if (footstepLand != null)
 1258                footstepLand.Play(true);
 1259            if (stickersController != null)
 1260                stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up,
 1261        }
 62
 63        // Faking footsteps when in first-person mode, since animations won't play
 64        void OnWalk(float distance)
 65        {
 1566            if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 167                return;
 68
 1469            if (intervalTimer < 0f)
 70            {
 471                distance /= Time.deltaTime;
 72
 473                if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 74                {
 175                    if (footstepRun != null)
 176                        footstepRun.Play(true);
 77
 178                    if (clothesRustleShort != null)
 179                        clothesRustleShort.Play(true);
 80
 181                    intervalTimer = RUN_INTERVAL_SEC;
 182                }
 83                else
 84                {
 385                    if (footstepWalk != null)
 386                        footstepWalk.Play(true);
 87
 388                    if (clothesRustleShort != null)
 389                        clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 90
 391                    intervalTimer = WALK_INTERVAL_SEC;
 92                }
 93            }
 94
 1495            intervalTimer -= Time.deltaTime;
 1496        }
 97    }
 98}