< Summary

Class:OffsetInteractable
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Cooking-Demo/Assets/_Scripts/OffsetInteractable.cs
Covered lines:12
Uncovered lines:15
Coverable lines:27
Total lines:51
Line coverage:44.4% (12 of 27)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:5
Method coverage:40% (2 of 5)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%000100%
OnSelectEntering(...)0%0000%
MatchAttachPoint(...)0%0000%
IsFirstSelecting(...)0%0000%
CreateAttachTransform()0%000100%

File(s)

E:/Unity/Unity Project/VR-Cooking-Demo/Assets/_Scripts/OffsetInteractable.cs

#LineLine coverage
 1/*
 2 * Code adapted from:
 3 *      https://medium.com/@dnwesdman/grab-offset-interactables-with-the-xr-interaction-toolkit-b2c18cec1a52
 4 * by:
 5 *      Dimitrios Vlachos
 6 *      djv1@student.london.ac.uk
 7 *      dimitri.j.vlachos@gmail.com
 8 */
 9using System.Collections;
 10using System.Collections.Generic;
 11using UnityEngine;
 12using UnityEngine.XR.Interaction.Toolkit;
 13
 14public class OffsetInteractable : XRGrabInteractable
 15{
 16    protected override void Awake()
 617    {
 618        base.Awake();
 619        CreateAttachTransform();
 620    }
 21    protected override void OnSelectEntering(SelectEnterEventArgs args)
 022    {
 023        base.OnSelectEntering(args);
 024        MatchAttachPoint(args.interactorObject);
 025    }
 26
 27    protected void MatchAttachPoint(IXRInteractor interactor)
 028    {
 029        if (IsFirstSelecting(interactor))
 030        {
 031            bool isDirect = interactor is XRDirectInteractor;
 032            attachTransform.position = isDirect ? interactor.GetAttachTransform(this).position : transform.position;
 033            attachTransform.rotation = isDirect ? interactor.GetAttachTransform(this).rotation : transform.rotation;
 034        }
 035    }
 36
 37    private bool IsFirstSelecting(IXRInteractor interactor)
 038    {
 039        return interactor == firstInteractorSelecting;
 040    }
 41
 42    private void CreateAttachTransform()
 643    {
 644        if (attachTransform == null)
 645        {
 646            GameObject createdAttachTransform = new GameObject();
 647            createdAttachTransform.transform.parent = this.transform;
 648            attachTransform = createdAttachTransform.transform;
 649        }
 650    }
 51}