< Summary

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

Metrics

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

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
 5public class AvatarAudioHandlerLocal : MonoBehaviour
 6{
 7    const float WALK_RUN_CROSSOVER_DISTANCE = 7.3f;
 8    const float WALK_INTERVAL_SEC = 0.4f;
 9    const float RUN_INTERVAL_SEC = 0.27f;
 10
 11    float intervalTimer = 0f;
 12
 13    AudioEvent footstepJump;
 14    AudioEvent footstepLand;
 15    AudioEvent footstepWalk;
 16    AudioEvent footstepRun;
 17    AudioEvent clothesRustleShort;
 18
 19    private void Start()
 20    {
 12421        var characterController = DCLCharacterController.i;
 22
 12423        if (characterController != null)
 24        {
 12425            characterController.OnJump += OnJump;
 12426            characterController.OnHitGround += OnLand;
 12427            characterController.OnMoved += OnWalk;
 28        }
 29
 12430        AudioContainer ac = GetComponent<AudioContainer>();
 12431        footstepJump = ac.GetEvent("FootstepJump");
 12432        footstepLand = ac.GetEvent("FootstepLand");
 12433        footstepWalk = ac.GetEvent("FootstepWalk");
 12434        footstepRun = ac.GetEvent("FootstepRun");
 12435        clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 12436    }
 37
 38    void OnJump()
 39    {
 140        if (footstepJump != null)
 141            footstepJump.Play(true);
 142    }
 43
 44    void OnLand()
 45    {
 11346        if (footstepLand != null)
 11347            footstepLand.Play(true);
 11348    }
 49
 50    // Faking footsteps when in first-person mode, since animations won't play
 51    void OnWalk(float distance)
 52    {
 252953        if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 20854            return;
 55
 232156        if (intervalTimer < 0f)
 57        {
 10458            distance /= Time.deltaTime;
 59
 10460            if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 61            {
 062                if (footstepRun != null)
 063                    footstepRun.Play(true);
 64
 065                if (clothesRustleShort != null)
 066                    clothesRustleShort.Play(true);
 67
 068                intervalTimer = RUN_INTERVAL_SEC;
 069            }
 70            else
 71            {
 10472                if (footstepWalk != null)
 10473                    footstepWalk.Play(true);
 74
 10475                if (clothesRustleShort != null)
 10476                    clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 77
 10478                intervalTimer = WALK_INTERVAL_SEC;
 79            }
 80        }
 81
 232182        intervalTimer -= Time.deltaTime;
 232183    }
 84}