2024-09-16 09:15:45 -07:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
public class InputManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static InputManager Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool mouseActive = true;
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct CameraPreset
|
|
|
|
|
{
|
|
|
|
|
public Vector3 position;
|
|
|
|
|
public Quaternion rotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool lockUserInput = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == null) {
|
|
|
|
|
Instance = this;
|
|
|
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
|
} else {
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
HandleInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleMouseInput()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetMouseButton(0))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.OrbitCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (Input.GetMouseButton(1))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.RotateCamera(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleInput()
|
|
|
|
|
{
|
|
|
|
|
if (!lockUserInput)
|
|
|
|
|
{
|
|
|
|
|
HandleLockableInput();
|
|
|
|
|
}
|
|
|
|
|
HandleNonLockableInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleScrollWheelInput()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.ZoomCamera(Input.GetAxis("Mouse ScrollWheel") * 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleLockableInput()
|
|
|
|
|
{
|
|
|
|
|
|
2024-09-24 17:05:33 -07:00
|
|
|
|
if(mouseActive)
|
|
|
|
|
{
|
|
|
|
|
HandleMouseInput();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 09:15:45 -07:00
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
|
|
|
{
|
2024-09-23 22:00:18 -07:00
|
|
|
|
CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedMax());
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-09-23 22:00:18 -07:00
|
|
|
|
CameraController.Instance.SetCameraSpeed(CameraController.Instance.GetCameraSpeedNormal());
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TRANSLATIONAL MOVEMENT
|
|
|
|
|
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Forward);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Left);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Back);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Right);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.Q))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Up);
|
|
|
|
|
}
|
|
|
|
|
if (Input.GetKey(KeyCode.E))
|
|
|
|
|
{
|
|
|
|
|
CameraController.Instance.TranslateCamera(CameraController.TranslationInput.Down);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleNonLockableInput()
|
|
|
|
|
{
|
|
|
|
|
HandleScrollWheelInput();
|
|
|
|
|
|
2024-09-24 13:59:21 -07:00
|
|
|
|
if(Input.GetKeyDown(KeyCode.Escape))
|
|
|
|
|
{
|
|
|
|
|
Application.Quit();
|
|
|
|
|
}
|
2024-09-16 09:15:45 -07:00
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.C))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 17:05:33 -07:00
|
|
|
|
if(Input.GetKeyDown(KeyCode.R))
|
|
|
|
|
{
|
|
|
|
|
SimManager.Instance.RestartSimulation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.L)) // 'L' for Load
|
|
|
|
|
{
|
|
|
|
|
UIManager.Instance.ToggleConfigSelectorPanel();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 09:15:45 -07:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
|
|
|
{
|
|
|
|
|
// Pause the time
|
|
|
|
|
if (SimManager.Instance.IsSimulationRunning()) {
|
|
|
|
|
SimManager.Instance.PauseSimulation();
|
|
|
|
|
} else {
|
|
|
|
|
SimManager.Instance.ResumeSimulation();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
|
|
|
{
|
2024-09-23 22:00:18 -07:00
|
|
|
|
CameraController.Instance.SetAutoRotate(!CameraController.Instance.IsAutoRotate());
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha1))
|
|
|
|
|
{
|
|
|
|
|
// ORIGIN
|
2024-09-23 12:28:45 -07:00
|
|
|
|
// Set pre-set view 1
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha2))
|
|
|
|
|
{
|
2024-09-23 12:28:45 -07:00
|
|
|
|
// Set pre-set view 2
|
2024-09-16 09:15:45 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha4))
|
|
|
|
|
{
|
2024-09-23 12:28:45 -07:00
|
|
|
|
// Set pre-set view 4
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha5))
|
|
|
|
|
{
|
2024-09-23 12:28:45 -07:00
|
|
|
|
// Set pre-set view 5
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Alpha6))
|
|
|
|
|
{
|
2024-09-23 12:28:45 -07:00
|
|
|
|
// Set pre-set view 6
|
2024-09-16 09:15:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|