using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Console;
namespace Cyber.Controls {
///
/// Handles grabbing the cursor when needed and provides info about the mouse.
///
public class CursorHandler : MonoBehaviour {
private static CursorHandler Singleton;
///
/// The mouse sensitivity on the screen's x-axis.
///
[Range(1f, 5.0f)]
public float MouseSensitivityX = 2.5f;
///
/// The mouse sensitivity on the screen's y-axis.
///
[Range(1f, 5.0f)]
public float MouseSensitivityY = 2.5f;
private bool CursorLocked = true;
private bool RequestedLockState = true;
///
/// Sets the Singleton.
///
public CursorHandler() {
Singleton = this;
}
///
/// Gets the mouse sentivity on the x-axis.
///
/// The mouse sentivity on the x-axis.
public static float GetMouseSensitivityX() {
return Singleton.MouseSensitivityX;
}
///
/// Gets the mouse sentivity on the y-axis.
///
/// The mouse sentivity on the y-axis.
public static float GetMouseSensitivityY() {
return Singleton.MouseSensitivityY;
}
///
/// Request a new lock state. The cursor will be locked in case there
/// isn't another reason to have it in a different state (like the
/// being up).
///
/// If set to true, cursor might bse
/// locked.
public static void RequestLockState(bool locked) {
Singleton.RequestedLockState = locked;
}
///
/// Is the cursor currently locked?
///
public static bool Locked() {
return Term.IsVisible() || Singleton.RequestedLockState;
}
private void Start() {
UpdateCursor();
}
private void Update() {
if (Term.IsVisible()) {
CursorLocked = false;
UpdateCursor();
} else {
CursorLocked = RequestedLockState;
UpdateCursor();
}
}
private void UpdateCursor() {
if (CursorLocked) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
} else {
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
}
}