< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%220100%
OnJump()0%330100%
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 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    [SerializeField]
 12    Vector3 jumpLandParticlesOffset;
 13    [SerializeField]
 14    StickersController stickersController;
 15
 16    float intervalTimer = 0f;
 17
 18    AudioEvent footstepJump;
 19    AudioEvent footstepLand;
 20    AudioEvent footstepWalk;
 21    AudioEvent footstepRun;
 22    AudioEvent clothesRustleShort;
 23
 24    private void Start()
 25    {
 12326        var characterController = DCLCharacterController.i;
 27
 12328        if (characterController != null)
 29        {
 12330            characterController.OnJump += OnJump;
 12331            characterController.OnHitGround += OnLand;
 12332            characterController.OnMoved += OnWalk;
 33        }
 34
 12335        AudioContainer ac = GetComponent<AudioContainer>();
 12336        footstepJump = ac.GetEvent("FootstepJump");
 12337        footstepLand = ac.GetEvent("FootstepLand");
 12338        footstepWalk = ac.GetEvent("FootstepWalk");
 12339        footstepRun = ac.GetEvent("FootstepRun");
 12340        clothesRustleShort = ac.GetEvent("ClothesRustleShort");
 12341    }
 42
 43    void OnJump()
 44    {
 145        if (footstepJump != null)
 146            footstepJump.Play(true);
 147        if (stickersController != null)
 148            stickersController.PlaySticker("footstepJump", transform.position + jumpLandParticlesOffset, Vector3.up, fal
 149    }
 50
 51    void OnLand()
 52    {
 11253        if (footstepLand != null)
 11254            footstepLand.Play(true);
 11255        if (stickersController != null)
 11256            stickersController.PlaySticker("footstepLand", transform.position + jumpLandParticlesOffset, Vector3.up, fal
 11257    }
 58
 59    // Faking footsteps when in first-person mode, since animations won't play
 60    void OnWalk(float distance)
 61    {
 252962        if (CommonScriptableObjects.cameraMode.Get() != CameraMode.ModeId.FirstPerson)
 54463            return;
 64
 198565        if (intervalTimer < 0f)
 66        {
 8567            distance /= Time.deltaTime;
 68
 8569            if (distance > WALK_RUN_CROSSOVER_DISTANCE)
 70            {
 371                if (footstepRun != null)
 372                    footstepRun.Play(true);
 73
 374                if (clothesRustleShort != null)
 375                    clothesRustleShort.Play(true);
 76
 377                intervalTimer = RUN_INTERVAL_SEC;
 378            }
 79            else
 80            {
 8281                if (footstepWalk != null)
 8282                    footstepWalk.Play(true);
 83
 8284                if (clothesRustleShort != null)
 8285                    clothesRustleShort.PlayScheduled(Random.Range(0.05f, 0.1f));
 86
 8287                intervalTimer = WALK_INTERVAL_SEC;
 88            }
 89        }
 90
 198591        intervalTimer -= Time.deltaTime;
 198592    }
 93}