< 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:98
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 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        {
 58330            var characterController = DCLCharacterController.i;
 31
 58332            if (characterController != null)
 33            {
 58334                characterController.OnJump += OnJump;
 58335                characterController.OnHitGround += OnLand;
 58336                characterController.OnMoved += OnWalk;
 37            }
 38
 58339            AudioContainer ac = GetComponent<AudioContainer>();
 58340            footstepJump = ac.GetEvent("FootstepJump");
 58341            footstepLand = ac.GetEvent("FootstepLand");
 58342            footstepWalk = ac.GetEvent("FootstepWalk");
 58343            footstepRun = ac.GetEvent("FootstepRun");
 58344            clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 58345        }
 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        {
 1957            if (footstepLand != null)
 1958                footstepLand.Play(true);
 1959            if (stickersController != null)
 1960                stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up,
 1961        }
 62
 63        // Faking footsteps when in first-person mode, since animations won't play
 64        void OnWalk(float distance)
 65        {
 2466            if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 067                return;
 68
 2469            if (intervalTimer < 0f)
 70            {
 571                distance /= Time.deltaTime;
 72
 573                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                {
 485                    if (footstepWalk != null)
 486                        footstepWalk.Play(true);
 87
 488                    if (clothesRustleShort != null)
 489                        clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 90
 491                    intervalTimer = WALK_INTERVAL_SEC;
 92                }
 93            }
 94
 2495            intervalTimer -= Time.deltaTime;
 2496        }
 97    }
 98}