< Summary

Class:Waypoint
Assembly:Test
File(s):D:/--UnityProject/VR/subjects1_for_analysis/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Waypoint.cs
Covered lines:91
Uncovered lines:13
Coverable lines:104
Total lines:196
Line coverage:87.5% (91 of 104)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:11
Method coverage:90.9% (10 of 11)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Waypoint()0%000100%
Awake()0%000100%
Update()0%00082.14%
Enter()0%000100%
Exit()0%000100%
Approach()0%000100%
Click()0%000100%
Idle()0%000100%
Focus()0%0000%
Clicked()0%000100%
Hide()0%000100%

File(s)

D:/--UnityProject/VR/subjects1_for_analysis/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Waypoint.cs

#LineLine coverage
 1using UnityEngine;
 2using System.Collections;
 3
 4public class Waypoint : MonoBehaviour
 5{
 6  private enum State
 7  {
 8    Idle,
 9    Focused,
 10    Clicked,
 11    Approaching,
 12    Moving,
 13    Collect,
 14    Collected,
 15    Occupied,
 16    Open,
 17    Hidden
 18  }
 19
 20  [SerializeField]
 3821  private State      _state          = State.Idle;
 3822  private Color    _color_origional    = new Color(0.0f, 1.0f, 0.0f, 0.5f);
 3823  private Color    _color          = Color.white;
 3824  private float     _scale          = 1.0f;
 3825    private float     _displacement      = 0.0f;
 3826    private Vector3     _displacementVector     = new Vector3(0.0f, 1.0f, 0.0f);
 3827    private Vector3     _rotationVector         = new Vector3(0.0f, 1.0f, 0.0f);
 3828    private float     _animated_lerp      = 1.0f;
 3829  private AudioSource _audio_source      = null;
 3830  private Material  _material        = null;
 31    private Vector3 _initial_position;
 32    // camera should be slightly above
 3833    private Vector3 _cameraDisplacement = new Vector3(0f, 0.7f, 0f);
 34    private GameObject cam;
 35
 36    [Header("Material")]
 3837  public Material  material          = null;
 3838  public Color color_hilight          = new Color(0.8f, 0.8f, 1.0f, 0.125f);
 39
 40  [Header("State Blend Speeds")]
 3841  public float lerp_idle             = 0.0f;
 3842  public float lerp_focus           = 0.0f;
 3843  public float lerp_hide            = 0.0f;
 3844  public float lerp_clicked          = 0.0f;
 45
 46  [Header("State Animation Scales")]
 3847  public float scale_clicked_max        = 0.0f;
 3848  public float scale_animation        = 3.0f;
 3849  public float scale_idle_min         = 0.0f;
 3850  public float scale_idle_max         = 0.0f;
 3851  public float scale_focus_min        = 0.0f;
 3852  public float scale_focus_max        = 0.0f;
 3853    public float displacement_idle_min = -2f;
 3854    public float displacement_idle_max = 2f;
 55
 56    [Header("Misc")]
 3857    public float rotation_speed = 2f;
 58
 59    [Header("Sounds")]
 3860  public AudioClip clip_click          = null;
 61
 62  [Header("Hide Distance")]
 3863  public float threshold            = 0.125f;
 64
 65
 66
 67  void Awake()
 1968  {
 1969    _material          = Instantiate(material);
 1970    _color_origional      = _material.color;
 1971    _color            = _color_origional;
 1972    _audio_source        = gameObject.GetComponent<AudioSource>();
 1973    _audio_source.clip       = clip_click;
 1974    _audio_source.playOnAwake   = false;
 1975        _initial_position = gameObject.transform.position;
 76        // modifying camera's position does not work on Android for some reason (but works in unity)
 77        // so i had to wrap camera in empty object and move this object
 1978        cam = GameObject.Find("Camera Holder");
 1979    }
 80
 81
 82  void Update()
 161634983  {
 161634984    bool occupied = cam.transform.position == (_initial_position + _cameraDisplacement);
 85
 161634986    switch(_state)
 87    {
 88      case State.Idle:
 154940089        Idle();
 90
 154940091        _state     = occupied ? State.Occupied : _state;
 154940092        break;
 93
 94      case State.Focused:
 095        Focus();
 096        break;
 97
 98      case State.Clicked:
 9499        Clicked();
 94100                bool scaled = _scale >= scale_clicked_max * .95f;
 94101                _state     = scaled ? State.Approaching : _state;
 94102        break;
 103
 104      case State.Approaching:
 19105                Hide();
 19106                Approach();
 19107        _state     = occupied ? State.Occupied : _state;
 19108        break;
 109
 110            case State.Occupied:
 66836111        Hide();
 66836112        _state = !occupied ? State.Idle : _state;
 66836113        break;
 114
 115      case State.Hidden:
 0116        Hide();
 0117        break;
 118
 119      default:
 0120        break;
 121    }
 122
 1616349123    gameObject.GetComponentInChildren<MeshRenderer>().material.color   = _color;
 1616349124    gameObject.transform.localScale                   = Vector3.one * _scale;
 1616349125        _animated_lerp                            = Mathf.Abs(Mathf.Cos(Time.time * scale_animation));
 126
 127        // levitate
 1616349128        gameObject.transform.position = _initial_position + _displacementVector * _displacement;
 129
 130        // rotate waypoint object
 1616349131        gameObject.transform.Rotate(Time.deltaTime * rotation_speed * _rotationVector);
 1616349132    }
 133
 134
 135    public void Enter()
 37136  {
 37137    _state = _state == State.Idle ? State.Focused : _state;
 37138  }
 139
 140
 141  public void Exit()
 25142  {
 143        // only go idle from focued state, to avoid non-working clicks
 25144        _state = _state == State.Focused ? State.Idle : _state;
 25145    }
 146
 147    public void Approach()
 38148    {
 38149        cam.transform.localPosition = _initial_position + _cameraDisplacement;
 38150        cam.transform.rotation = Quaternion.identity;
 38151    }
 152
 153    public void Click()
 19154  {
 19155    _state = State.Clicked;
 19156        _audio_source.Play();
 19157    }
 158
 159
 160    private void Idle()
 1549400161  {
 1549400162    float scale        = Mathf.Lerp(scale_idle_min, scale_idle_max, _animated_lerp);
 1549400163        float displacement      = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 1549400164        Color color        = Color.Lerp(_color_origional,     color_hilight, _animated_lerp);
 165
 1549400166    _scale          = Mathf.Lerp(_scale, scale, lerp_idle);
 1549400167    _color          = Color.Lerp(_color, color, lerp_idle);
 1549400168        _displacement           = Mathf.Lerp(_displacement, displacement, lerp_idle);
 1549400169    }
 170
 171
 172  public void Focus()
 0173  {
 0174    float scale        = Mathf.Lerp(scale_focus_min, scale_focus_max, _animated_lerp);
 0175        float displacement = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 0176        Color color        = Color.Lerp(   _color_origional,   color_hilight, _animated_lerp);
 177
 0178    _scale          = Mathf.Lerp(_scale, scale, lerp_focus);
 0179    _color          = Color.Lerp(_color, color,  lerp_focus);
 0180        _displacement = Mathf.Lerp(_displacement, displacement, lerp_focus);
 0181    }
 182
 183
 184  public void Clicked()
 94185  {
 94186    _scale          = Mathf.Lerp(_scale, scale_clicked_max, lerp_clicked);
 94187        _color          = Color.Lerp(_color,     color_hilight, lerp_clicked);
 94188  }
 189
 190
 191  public void Hide()
 66857192  {
 66857193        _scale = Mathf.Lerp(_scale,     0.0f, lerp_hide);
 66857194        _color = Color.Lerp(_color, Color.clear, lerp_hide);
 66857195  }
 196}