< Summary

Class:Waypoint
Assembly:Test
File(s):D:/--UnityProject/VR/subjects/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Waypoint.cs
Covered lines:101
Uncovered lines:3
Coverable lines:104
Total lines:215
Line coverage:97.1% (101 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%00089.29%
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/subjects/unity-vr-maze-master/unity-vr-maze-master/Assets/Maze/Scripts/Waypoint.cs

#LineLine coverage
 1using UnityEngine;
 2using System.Collections;
 3using VRExplorer;
 4using System.Diagnostics.CodeAnalysis;
 5
 6public class Waypoint : MonoBehaviour, ITriggerableEntity
 7{
 8    #region Entity
 9    [ExcludeFromCodeCoverage] public float TriggeringTime => 0.05f;
 10    [ExcludeFromCodeCoverage] public string Name => Str.Button;
 11
 12    [ExcludeFromCodeCoverage]
 13    public void Triggerred()
 14    {
 15    Exit();
 16    Click();
 17    }
 18
 19    [ExcludeFromCodeCoverage]
 20    public void Triggerring()
 21    {
 22    Enter();
 23    }
 24    #endregion
 25    private enum State
 26  {
 27    Idle,
 28    Focused,
 29    Clicked,
 30    Approaching,
 31    Moving,
 32    Collect,
 33    Collected,
 34    Occupied,
 35    Open,
 36    Hidden
 37  }
 38
 39  [SerializeField]
 36140  private State      _state          = State.Idle;
 36141  private Color    _color_origional    = new Color(0.0f, 1.0f, 0.0f, 0.5f);
 36142  private Color    _color          = Color.white;
 36143  private float     _scale          = 1.0f;
 36144    private float     _displacement      = 0.0f;
 36145    private Vector3     _displacementVector     = new Vector3(0.0f, 1.0f, 0.0f);
 36146    private Vector3     _rotationVector         = new Vector3(0.0f, 1.0f, 0.0f);
 36147    private float     _animated_lerp      = 1.0f;
 36148  private AudioSource _audio_source      = null;
 36149  private Material  _material        = null;
 50    private Vector3 _initial_position;
 51    // camera should be slightly above
 36152    private Vector3 _cameraDisplacement = new Vector3(0f, 0.7f, 0f);
 53    private GameObject cam;
 54
 55    [Header("Material")]
 36156  public Material  material          = null;
 36157  public Color color_hilight          = new Color(0.8f, 0.8f, 1.0f, 0.125f);
 58
 59  [Header("State Blend Speeds")]
 36160  public float lerp_idle             = 0.0f;
 36161  public float lerp_focus           = 0.0f;
 36162  public float lerp_hide            = 0.0f;
 36163  public float lerp_clicked          = 0.0f;
 64
 65  [Header("State Animation Scales")]
 36166  public float scale_clicked_max        = 0.0f;
 36167  public float scale_animation        = 3.0f;
 36168  public float scale_idle_min         = 0.0f;
 36169  public float scale_idle_max         = 0.0f;
 36170  public float scale_focus_min        = 0.0f;
 36171  public float scale_focus_max        = 0.0f;
 36172    public float displacement_idle_min = -2f;
 36173    public float displacement_idle_max = 2f;
 74
 75    [Header("Misc")]
 36176    public float rotation_speed = 2f;
 77
 78    [Header("Sounds")]
 36179  public AudioClip clip_click          = null;
 80
 81  [Header("Hide Distance")]
 36182  public float threshold            = 0.125f;
 83
 84
 85
 86  void Awake()
 36187  {
 36188    _material          = Instantiate(material);
 36189    _color_origional      = _material.color;
 36190    _color            = _color_origional;
 36191    _audio_source        = gameObject.GetComponent<AudioSource>();
 36192    _audio_source.clip       = clip_click;
 36193    _audio_source.playOnAwake   = false;
 36194        _initial_position = gameObject.transform.position;
 95        // modifying camera's position does not work on Android for some reason (but works in unity)
 96        // so i had to wrap camera in empty object and move this object
 36197        cam = GameObject.Find("Camera Holder");
 36198    }
 99
 100
 101  void Update()
 1990649102  {
 1990649103    bool occupied = cam.transform.position == (_initial_position + _cameraDisplacement);
 104
 1990649105    switch(_state)
 106    {
 107      case State.Idle:
 1888454108        Idle();
 109
 1888454110        _state     = occupied ? State.Occupied : _state;
 1888454111        break;
 112
 113      case State.Focused:
 1560114        Focus();
 1560115        break;
 116
 117      case State.Clicked:
 781118        Clicked();
 781119                bool scaled = _scale >= scale_clicked_max * .95f;
 781120                _state     = scaled ? State.Approaching : _state;
 781121        break;
 122
 123      case State.Approaching:
 478124                Hide();
 478125                Approach();
 478126        _state     = occupied ? State.Occupied : _state;
 478127        break;
 128
 129            case State.Occupied:
 99376130        Hide();
 99376131        _state = !occupied ? State.Idle : _state;
 99376132        break;
 133
 134      case State.Hidden:
 0135        Hide();
 0136        break;
 137
 138      default:
 0139        break;
 140    }
 141
 1990649142    gameObject.GetComponentInChildren<MeshRenderer>().material.color   = _color;
 1990649143    gameObject.transform.localScale                   = Vector3.one * _scale;
 1990649144        _animated_lerp                            = Mathf.Abs(Mathf.Cos(Time.time * scale_animation));
 145
 146        // levitate
 1990649147        gameObject.transform.position = _initial_position + _displacementVector * _displacement;
 148
 149        // rotate waypoint object
 1990649150        gameObject.transform.Rotate(Time.deltaTime * rotation_speed * _rotationVector);
 1990649151    }
 152
 153
 154    public void Enter()
 241155  {
 241156    _state = _state == State.Idle ? State.Focused : _state;
 241157  }
 158
 159
 160  public void Exit()
 241161  {
 162        // only go idle from focued state, to avoid non-working clicks
 241163        _state = _state == State.Focused ? State.Idle : _state;
 241164    }
 165
 166    public void Approach()
 478167    {
 478168        cam.transform.localPosition = _initial_position + _cameraDisplacement;
 478169        cam.transform.rotation = Quaternion.identity;
 478170    }
 171
 172    public void Click()
 241173  {
 241174    _state = State.Clicked;
 241175        _audio_source.Play();
 241176    }
 177
 178
 179    private void Idle()
 1888454180  {
 1888454181    float scale        = Mathf.Lerp(scale_idle_min, scale_idle_max, _animated_lerp);
 1888454182        float displacement      = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 1888454183        Color color        = Color.Lerp(_color_origional,     color_hilight, _animated_lerp);
 184
 1888454185    _scale          = Mathf.Lerp(_scale, scale, lerp_idle);
 1888454186    _color          = Color.Lerp(_color, color, lerp_idle);
 1888454187        _displacement           = Mathf.Lerp(_displacement, displacement, lerp_idle);
 1888454188    }
 189
 190
 191  public void Focus()
 1560192  {
 1560193    float scale        = Mathf.Lerp(scale_focus_min, scale_focus_max, _animated_lerp);
 1560194        float displacement = Mathf.Lerp(displacement_idle_min, displacement_idle_max, _animated_lerp);
 1560195        Color color        = Color.Lerp(   _color_origional,   color_hilight, _animated_lerp);
 196
 1560197    _scale          = Mathf.Lerp(_scale, scale, lerp_focus);
 1560198    _color          = Color.Lerp(_color, color,  lerp_focus);
 1560199        _displacement = Mathf.Lerp(_displacement, displacement, lerp_focus);
 1560200    }
 201
 202
 203  public void Clicked()
 781204  {
 781205    _scale          = Mathf.Lerp(_scale, scale_clicked_max, lerp_clicked);
 781206        _color          = Color.Lerp(_color,     color_hilight, lerp_clicked);
 781207  }
 208
 209
 210  public void Hide()
 99854211  {
 99854212        _scale = Mathf.Lerp(_scale,     0.0f, lerp_hide);
 99854213        _color = Color.Lerp(_color, Color.clear, lerp_hide);
 99854214  }
 215}