< Summary

Class:AvatarAnchorPoints
Assembly:AvatarAnchorPoints
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAnchorPoints/Implementation/AvatarAnchorPoints.cs
Covered lines:2
Uncovered lines:18
Coverable lines:20
Total lines:61
Line coverage:10% (2 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarAnchorPoints()0%110100%
AvatarAnchorPoints()0%110100%
Prepare(...)0%12300%
GetTransform(...)0%56700%
TryGetIdFromBoneName(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Avatar/AvatarAnchorPoints/Implementation/AvatarAnchorPoints.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using UnityEngine;
 4
 5public class AvatarAnchorPoints : IAvatarAnchorPoints
 6{
 17    private static readonly Dictionary<AvatarAnchorPointIds, string> boneMapping = new Dictionary<AvatarAnchorPointIds, 
 8    {
 9        { AvatarAnchorPointIds.LeftHand, "Avatar_LeftHand" },
 10        { AvatarAnchorPointIds.RightHand, "Avatar_RightHand" },
 11    };
 12
 68713    private readonly Dictionary<AvatarAnchorPointIds, Transform> boneTransformMapping = new Dictionary<AvatarAnchorPoint
 14
 15    private Transform avatarTransform;
 16    private float nameTagY;
 17
 18    void IAvatarAnchorPoints.Prepare(Transform avatarTransform, Transform[] bones, float nameTagY)
 19    {
 020        this.avatarTransform = avatarTransform;
 021        this.nameTagY = nameTagY;
 22
 023        boneTransformMapping.Clear();
 24
 025        foreach (var bone in bones)
 26        {
 027            if (TryGetIdFromBoneName(bone.name, out AvatarAnchorPointIds anchorPointId))
 28            {
 029                boneTransformMapping.Add(anchorPointId, bone);
 30            }
 31        }
 032    }
 33    (Vector3 position, Quaternion rotation, Vector3 scale) IAvatarAnchorPoints.GetTransform(AvatarAnchorPointIds anchorP
 34    {
 035        if (anchorPointId == AvatarAnchorPointIds.Position && avatarTransform != null)
 36        {
 037            return (avatarTransform.position, avatarTransform.rotation, Vector3.one);
 38        }
 39
 040        if (anchorPointId == AvatarAnchorPointIds.NameTag && avatarTransform != null)
 41        {
 042            return (avatarTransform.position + Vector3.up * nameTagY, avatarTransform.rotation, Vector3.one);
 43        }
 44
 045        if (boneTransformMapping.TryGetValue(anchorPointId, out Transform bone))
 46        {
 047            if (bone != null)
 48            {
 049                return (bone.position, bone.rotation, bone.lossyScale);
 50            }
 51        }
 052        return (Vector3.zero, Quaternion.identity, Vector3.one);
 53    }
 54
 55    private static bool TryGetIdFromBoneName(string boneName, out AvatarAnchorPointIds id)
 56    {
 057        var result = boneMapping.FirstOrDefault(pair => pair.Value == boneName);
 058        id = result.Key;
 059        return !string.IsNullOrEmpty(result.Value);
 60    }
 61}