< Summary

Class:DCL.AvatarAudioHandlerLocal
Assembly:AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAudioHandlerLocal.cs
Covered lines:19
Uncovered lines:20
Coverable lines:39
Total lines:98
Line coverage:48.7% (19 of 39)
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%51.978011.76%

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        {
 40530            var characterController = DCLCharacterController.i;
 31
 40532            if (characterController != null)
 33            {
 40534                characterController.OnJump += OnJump;
 40535                characterController.OnHitGround += OnLand;
 40536                characterController.OnMoved += OnWalk;
 37            }
 38
 40539            AudioContainer ac = GetComponent<AudioContainer>();
 40540            footstepJump = ac.GetEvent("FootstepJump");
 40541            footstepLand = ac.GetEvent("FootstepLand");
 40542            footstepWalk = ac.GetEvent("FootstepWalk");
 40543            footstepRun = ac.GetEvent("FootstepRun");
 40544            clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 40545        }
 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        {
 2157            if (footstepLand != null)
 2158                footstepLand.Play(true);
 2159            if (stickersController != null)
 2160                stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up,
 2161        }
 62
 63        // Faking footsteps when in first-person mode, since animations won't play
 64        void OnWalk(float distance)
 65        {
 666            if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 667                return;
 68
 069            if (intervalTimer < 0f)
 70            {
 071                distance /= Time.deltaTime;
 72
 073                if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 74                {
 075                    if (footstepRun != null)
 076                        footstepRun.Play(true);
 77
 078                    if (clothesRustleShort != null)
 079                        clothesRustleShort.Play(true);
 80
 081                    intervalTimer = RUN_INTERVAL_SEC;
 82                }
 83                else
 84                {
 085                    if (footstepWalk != null)
 086                        footstepWalk.Play(true);
 87
 088                    if (clothesRustleShort != null)
 089                        clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 90
 091                    intervalTimer = WALK_INTERVAL_SEC;
 92                }
 93            }
 94
 095            intervalTimer -= Time.deltaTime;
 096        }
 97    }
 98}