< 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:99
Uncovered lines:5
Coverable lines:104
Total lines:196
Line coverage:95.1% (99 of 104)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:11
Method coverage:100% (11 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%000100%
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()
 34452783  {
 34452784    bool occupied = cam.transform.position == (_initial_position + _cameraDisplacement);
 85
 34452786    switch(_state)
 87    {
 88      case State.Idle:
 32798789        Idle();
 90
 32798791        _state     = occupied ? State.Occupied : _state;
 32798792        break;
 93
 94      case State.Focused:
 095        Focus();
 096        break;
 97
 98      case State.Clicked:
 1499        Clicked();
 14100                bool scaled = _scale >= scale_clicked_max * .95f;
 14101                _state     = scaled ? State.Approaching : _state;
 14102        break;
 103
 104      case State.Approaching:
 3105                Hide();
 3106                Approach();
 3107        _state     = occupied ? State.Occupied : _state;
 3108        break;
 109
 110            case State.Occupied:
 16523111        Hide();
 16523112        _state = !occupied ? State.Idle : _state;
 16523113        break;
 114
 115      case State.Hidden:
 0116        Hide();
 0117        break;
 118
 119      default:
 0120        break;
 121    }
 122
 344527123    gameObject.GetComponentInChildren<MeshRenderer>().material.color   = _color;
 344527124    gameObject.transform.localScale                   = Vector3.one * _scale;
 344527125        _animated_lerp                            = Mathf.Abs(Mathf.Cos(Time.time * scale_animation));
 126
 127        // levitate
 344527128        gameObject.transform.position = _initial_position + _displacementVector * _displacement;
 129
 130        // rotate waypoint object
 344527131        gameObject.transform.Rotate(Time.deltaTime * rotation_speed * _rotationVector);
 344527132    }
 133
 134
 135    public void Enter()
 3136  {
 3137    _state = _state == State.Idle ? State.Focused : _state;
 3138  }
 139
 140
 141  public void Exit()
 3142  {
 143        // only go idle from focued state, to avoid non-working clicks
 3144        _state = _state == State.Focused ? State.Idle : _state;
 3145    }
 146
 147    public void Approach()
 5148    {
 5149        cam.transform.localPosition = _initial_position + _cameraDisplacement;
 5150        cam.transform.rotation = Quaternion.identity;
 5151    }
 152
 153    public void Click()
 3154  {
 3155    _state = State.Clicked;
 3156        _audio_source.Play();
 3157    }
 158
 159
 160    private void Idle()
 327987161  {
 327987162    float scale        = Mathf.Lerp(scale_idle_min, scale_idle_max, _animated_lerp);
 327987163        float displacement      = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 327987164        Color color        = Color.Lerp(_color_origional,     color_hilight, _animated_lerp);
 165
 327987166    _scale          = Mathf.Lerp(_scale, scale, lerp_idle);
 327987167    _color          = Color.Lerp(_color, color, lerp_idle);
 327987168        _displacement           = Mathf.Lerp(_displacement, displacement, lerp_idle);
 327987169    }
 170
 171
 172  public void Focus()
 2173  {
 2174    float scale        = Mathf.Lerp(scale_focus_min, scale_focus_max, _animated_lerp);
 2175        float displacement = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 2176        Color color        = Color.Lerp(   _color_origional,   color_hilight, _animated_lerp);
 177
 2178    _scale          = Mathf.Lerp(_scale, scale, lerp_focus);
 2179    _color          = Color.Lerp(_color, color,  lerp_focus);
 2180        _displacement = Mathf.Lerp(_displacement, displacement, lerp_focus);
 2181    }
 182
 183
 184  public void Clicked()
 16185  {
 16186    _scale          = Mathf.Lerp(_scale, scale_clicked_max, lerp_clicked);
 16187        _color          = Color.Lerp(_color,     color_hilight, lerp_clicked);
 16188  }
 189
 190
 191  public void Hide()
 16529192  {
 16529193        _scale = Mathf.Lerp(_scale,     0.0f, lerp_hide);
 16529194        _color = Color.Lerp(_color, Color.clear, lerp_hide);
 16529195  }
 196}