< Summary

Class:AvatarAudioHandlerLocal
Assembly:AvatarShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAudioHandlerLocal.cs
Covered lines:36
Uncovered lines:0
Coverable lines:36
Total lines:84
Line coverage:100% (36 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%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 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    {
 12321        var characterController = DCLCharacterController.i;
 22
 12323        if (characterController != null)
 24        {
 12325            characterController.OnJump += OnJump;
 12326            characterController.OnHitGround += OnLand;
 12327            characterController.OnMoved += OnWalk;
 28        }
 29
 12330        AudioContainer ac = GetComponent<AudioContainer>();
 12331        footstepJump = ac.GetEvent("FootstepJump");
 12332        footstepLand = ac.GetEvent("FootstepLand");
 12333        footstepWalk = ac.GetEvent("FootstepWalk");
 12334        footstepRun = ac.GetEvent("FootstepRun");
 12335        clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 12336    }
 37
 38    void OnJump()
 39    {
 140        if (footstepJump != null)
 141            footstepJump.Play(true);
 142    }
 43
 44    void OnLand()
 45    {
 11646        if (footstepLand != null)
 11647            footstepLand.Play(true);
 11648    }
 49
 50    // Faking footsteps when in first-person mode, since animations won't play
 51    void OnWalk(float distance)
 52    {
 262453        if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 20954            return;
 55
 241556        if (intervalTimer < 0f)
 57        {
 10858            distance /= Time.deltaTime;
 59
 10860            if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 61            {
 262                if (footstepRun != null)
 263                    footstepRun.Play(true);
 64
 265                if (clothesRustleShort != null)
 266                    clothesRustleShort.Play(true);
 67
 268                intervalTimer = RUN_INTERVAL_SEC;
 269            }
 70            else
 71            {
 10672                if (footstepWalk != null)
 10673                    footstepWalk.Play(true);
 74
 10675                if (clothesRustleShort != null)
 10676                    clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 77
 10678                intervalTimer = WALK_INTERVAL_SEC;
 79            }
 80        }
 81
 241582        intervalTimer -= Time.deltaTime;
 241583    }
 84}