< Summary

Class:InputManager
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Managers/InputManager.cs
Covered lines:0
Uncovered lines:174
Coverable lines:174
Total lines:232
Line coverage:0% (0 of 174)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:15
Method coverage:0% (0 of 15)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputManager()0%2100%
Awake()0%6200%
Start()0%2100%
Update()0%2100%
Handle3DModeMouseInput()0%12300%
HandleInput()0%6200%
Handle3DModeScrollWheelInput()0%6200%
HandleTacticalModeScrollWheelInput()0%6200%
HandleTacticalModeMouseInput()0%20400%
Handle3DModeLockableInput()0%1561200%
HandleTacticalModeLockableInput()0%1561200%
HandleLockableInput()0%30500%
HandleNonLockableInput()0%3421800%

File(s)

/github/workspace/Assets/Scripts/Managers/InputManager.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using System.Linq;
 5
 6public class InputManager : MonoBehaviour {
 07  public static InputManager Instance { get; private set; }
 8
 09  public bool mouseActive = true;
 10  [System.Serializable]
 11  public struct CameraPreset {
 12    public Vector3 position;
 13    public Quaternion rotation;
 14  }
 15
 016  public bool lockUserInput = false;
 17
 018  private void Awake() {
 019    if (Instance == null) {
 020      Instance = this;
 021      DontDestroyOnLoad(gameObject);
 022    } else {
 023      Destroy(gameObject);
 024    }
 025  }
 26
 27  private Vector2 _lastMousePosition;
 028  private bool _isDragging = false;
 29
 030  void Start() {}
 31
 032  void Update() {
 033    HandleInput();
 034  }
 35
 036  private void Handle3DModeMouseInput() {
 037    if (Input.GetMouseButton(0)) {
 038      CameraController.Instance.OrbitCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
 39
 040    } else if (Input.GetMouseButton(1)) {
 041      CameraController.Instance.RotateCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
 042    }
 043  }
 44
 045  private void HandleInput() {
 046    if (!lockUserInput) {
 047      HandleLockableInput();
 048    }
 049    HandleNonLockableInput();
 050  }
 51
 052  void Handle3DModeScrollWheelInput() {
 053    if (Input.GetAxis("Mouse ScrollWheel") != 0) {
 054      CameraController.Instance.ZoomCamera(Input.GetAxis("Mouse ScrollWheel") * 500);
 055    }
 056  }
 57
 058  void HandleTacticalModeScrollWheelInput() {
 059    if (Input.GetAxis("Mouse ScrollWheel") != 0) {
 060      TacticalPanelController.Instance.ZoomIn(Input.GetAxis("Mouse ScrollWheel") * 0.1f);
 061    }
 062  }
 63
 064  private void HandleTacticalModeMouseInput() {
 65    // Start drag on right mouse button
 066    if (Input.GetMouseButtonDown(1)) {
 067      _isDragging = true;
 068      _lastMousePosition = Input.mousePosition;
 069    }
 70    // End drag when button released
 071    else if (Input.GetMouseButtonUp(1)) {
 072      _isDragging = false;
 073    }
 74
 75    // Handle dragging
 076    if (_isDragging) {
 077      Vector2 currentMousePos = Input.mousePosition;
 078      Vector2 delta = currentMousePos - _lastMousePosition;
 079      TacticalPanelController.Instance.Pan(delta);
 080      _lastMousePosition = currentMousePos;
 081    }
 082  }
 83
 084  void Handle3DModeLockableInput() {
 085    if (Input.GetKey(KeyCode.LeftShift)) {
 086      CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedMax());
 087    } else {
 088      CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedNormal());
 089    }
 90
 91    // Translational movement.
 092    if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
 093      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Forward);
 094    }
 095    if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
 096      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Left);
 097    }
 098    if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) {
 099      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Back);
 0100    }
 0101    if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
 0102      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Right);
 0103    }
 0104    if (Input.GetKey(KeyCode.Q)) {
 0105      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Up);
 0106    }
 0107    if (Input.GetKey(KeyCode.E)) {
 0108      CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Down);
 0109    }
 0110  }
 111
 0112  void HandleTacticalModeLockableInput() {
 113    // Handle keyboard input for panning
 0114    Vector2 keyboardPanDirection = Vector2.zero;
 115
 0116    if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
 0117      keyboardPanDirection.y += -1;
 0118    }
 0119    if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) {
 0120      keyboardPanDirection.y += 1;
 0121    }
 0122    if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
 0123      keyboardPanDirection.x += -1;
 0124    }
 0125    if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
 0126      keyboardPanDirection.x += 1;
 0127    }
 128
 0129    if (Input.GetKeyDown(KeyCode.Q)) {
 0130      TacticalPanelController.Instance.CycleRangeUp();
 0131    }
 0132    if (Input.GetKeyDown(KeyCode.E)) {
 0133      TacticalPanelController.Instance.CycleRangeDown();
 0134    }
 135
 0136    if (keyboardPanDirection != Vector2.zero) {
 0137      TacticalPanelController.Instance.PanWithKeyboard(keyboardPanDirection.normalized);
 0138    }
 0139  }
 140
 0141  void HandleLockableInput() {
 0142    if (mouseActive) {
 0143      if (UIManager.Instance.GetUIMode() == UIMode.THREE_DIMENSIONAL) {
 0144        Handle3DModeMouseInput();
 0145        Handle3DModeScrollWheelInput();
 0146      } else {
 0147        HandleTacticalModeMouseInput();
 0148        HandleTacticalModeScrollWheelInput();
 0149      }
 0150    }
 151
 0152    if (UIManager.Instance.GetUIMode() == UIMode.THREE_DIMENSIONAL) {
 0153      Handle3DModeLockableInput();
 0154    } else {
 0155      HandleTacticalModeLockableInput();
 0156    }
 157
 0158    if (Input.GetKeyDown(KeyCode.Tab)) {
 0159      UIManager.Instance.ToggleUIMode();
 0160    }
 0161  }
 162
 0163  void HandleNonLockableInput() {
 0164    if (Input.GetKeyDown(KeyCode.Escape)) {
 0165      SimManager.Instance.QuitSimulation();
 0166    }
 167
 0168    if (Input.GetKeyDown(KeyCode.C)) {}
 169
 0170    if (Input.GetKeyDown(KeyCode.R)) {
 0171      SimManager.Instance.RestartSimulation();
 0172    }
 173
 0174    if (Input.GetKeyDown(KeyCode.L)) {
 0175      UIManager.Instance.ToggleConfigSelectorPanel();
 0176    }
 177
 0178    if (Input.GetKeyDown(KeyCode.C)) {
 0179      ParticleManager.Instance.ClearHitMarkers();
 0180    }
 181
 0182    if (Input.GetKeyDown(KeyCode.Space)) {
 183      // Pause the time.
 184
 0185      if (!SimManager.Instance.IsSimulationPaused()) {
 0186        SimManager.Instance.PauseSimulation();
 0187      } else {
 0188        SimManager.Instance.ResumeSimulation();
 0189      }
 0190    }
 191
 0192    if (Input.GetKeyDown(KeyCode.P)) {
 0193      CameraController.Instance.SetAutoRotate(!CameraController.Instance.IsAutoRotate());
 0194    }
 195
 0196    if (Input.GetKeyDown(KeyCode.Alpha1)) {
 0197      if (Input.GetKey(KeyCode.LeftControl)) {
 0198        CameraController.Instance.FollowNextInterceptorSwarm();
 0199      } else {
 0200        CameraController.Instance.SnapToNextInterceptorSwarm();
 0201      }
 0202    }
 203
 0204    if (Input.GetKeyDown(KeyCode.Alpha2)) {
 0205      if (Input.GetKey(KeyCode.LeftControl)) {
 0206        CameraController.Instance.FollowNextThreatSwarm();
 0207      } else {
 0208        CameraController.Instance.SnapToNextThreatSwarm();
 0209      }
 0210    }
 211
 0212    if (Input.GetKeyDown(KeyCode.Alpha3)) {
 0213      if (Input.GetKey(KeyCode.LeftControl)) {
 0214        CameraController.Instance.FollowCenterAllAgents();
 0215      } else {
 0216        CameraController.Instance.SnapToCenterAllAgents();
 0217      }
 0218    }
 219
 0220    if (Input.GetKeyDown(KeyCode.Alpha4)) {
 221      // Set pre-set view 4.
 0222    }
 223
 0224    if (Input.GetKeyDown(KeyCode.Alpha5)) {
 225      // Set pre-set view 5.
 0226    }
 227
 0228    if (Input.GetKeyDown(KeyCode.Alpha6)) {
 229      // Set pre-set view 6.
 0230    }
 0231  }
 232}