2023-07-04 21:32:21 +03:00
|
|
|
using Demonics.Manager;
|
2021-08-25 16:15:09 +02:00
|
|
|
using UnityEngine;
|
2023-03-26 19:50:30 +03:00
|
|
|
using UnityEngine.InputSystem;
|
2021-08-25 16:15:09 +02:00
|
|
|
|
2023-07-04 21:32:21 +03:00
|
|
|
public class MouseSetup : Singleton<MouseSetup>
|
2021-08-25 16:15:09 +02:00
|
|
|
{
|
2022-12-04 19:19:07 +02:00
|
|
|
[SerializeField] private CursorLockMode _cursorLockMode = default;
|
|
|
|
|
[SerializeField] private bool _mouseVisible = default;
|
2023-03-26 19:50:30 +03:00
|
|
|
[SerializeField] private PlayerInput _playerInput = default;
|
2023-07-04 21:32:21 +03:00
|
|
|
[SerializeField] private Texture2D _hoverTexture = default;
|
|
|
|
|
public Texture2D HoverCursor { get { return _hoverTexture; } private set { } }
|
2023-12-04 15:56:46 +02:00
|
|
|
public bool LockCamera { get; private set; }
|
2022-12-04 19:19:07 +02:00
|
|
|
|
2021-09-26 15:03:54 +02:00
|
|
|
void OnApplicationFocus(bool hasFocus)
|
2021-08-25 16:15:09 +02:00
|
|
|
{
|
2022-12-04 19:19:07 +02:00
|
|
|
Cursor.lockState = _cursorLockMode;
|
|
|
|
|
Cursor.visible = _mouseVisible;
|
|
|
|
|
}
|
2023-03-26 19:50:30 +03:00
|
|
|
|
2023-11-11 18:00:20 +02:00
|
|
|
public void SetCursor(bool enable)
|
|
|
|
|
{
|
|
|
|
|
_cursorLockMode = enable ? CursorLockMode.None : CursorLockMode.Locked;
|
|
|
|
|
_mouseVisible = enable;
|
|
|
|
|
Cursor.lockState = _cursorLockMode;
|
|
|
|
|
Cursor.visible = _mouseVisible;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 15:56:46 +02:00
|
|
|
public void SetLock(bool state)
|
|
|
|
|
{
|
2023-12-05 16:46:09 +02:00
|
|
|
Cursor.lockState = CursorLockMode.Locked;
|
2023-12-04 15:56:46 +02:00
|
|
|
Cursor.visible = !state;
|
|
|
|
|
LockCamera = state;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 19:50:30 +03:00
|
|
|
private void Update()
|
|
|
|
|
{
|
2023-12-04 15:56:46 +02:00
|
|
|
if (LockCamera)
|
2023-03-26 19:50:30 +03:00
|
|
|
return;
|
|
|
|
|
if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
|
2023-12-05 16:46:09 +02:00
|
|
|
{
|
|
|
|
|
Cursor.lockState = CursorLockMode.None;
|
2023-03-26 19:50:30 +03:00
|
|
|
_mouseVisible = true;
|
2023-12-05 16:46:09 +02:00
|
|
|
}
|
2023-12-04 15:56:46 +02:00
|
|
|
if (_playerInput != null)
|
|
|
|
|
{
|
|
|
|
|
if (_playerInput.currentControlScheme != null)
|
|
|
|
|
if (!_playerInput.currentControlScheme.Contains("Keyboard"))
|
|
|
|
|
_mouseVisible = false;
|
|
|
|
|
}
|
2023-03-26 19:50:30 +03:00
|
|
|
if (Input.anyKeyDown)
|
|
|
|
|
if (!Input.GetMouseButtonDown(0) && !Input.GetMouseButtonDown(1))
|
|
|
|
|
_mouseVisible = false;
|
2023-09-25 21:58:38 +03:00
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
|
|
|
_mouseVisible = true;
|
2023-12-05 12:42:43 +02:00
|
|
|
if (Cursor.lockState == CursorLockMode.Locked)
|
|
|
|
|
_mouseVisible = false;
|
2023-03-26 19:50:30 +03:00
|
|
|
Cursor.visible = _mouseVisible;
|
2023-12-05 12:42:43 +02:00
|
|
|
|
2023-03-26 19:50:30 +03:00
|
|
|
}
|
2021-08-25 16:15:09 +02:00
|
|
|
}
|