168 lines
5.0 KiB
C#
168 lines
5.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using TMPro;
|
|
|
|
public class GameUIManager : MonoBehaviour
|
|
{
|
|
public GameObject deathScreen;
|
|
public GameObject winScreen;
|
|
public GameObject settingsMenu;
|
|
public Slider mouseSensitivitySlider;
|
|
public Slider soundVolumeSlider;
|
|
public TMP_InputField mouseSensitivityInput;
|
|
public TMP_InputField soundVolumeInput;
|
|
public Button restartButton;
|
|
public Button mainMenuButton;
|
|
public Button exitButton;
|
|
|
|
private PlaerController playerController;
|
|
private bool isPaused = false;
|
|
private float defaultMouseSensitivity = 200f;
|
|
private float defaultSoundVolume = 1f;
|
|
|
|
void Start()
|
|
{
|
|
Time.timeScale = 1f;
|
|
|
|
playerController = FindObjectOfType<PlaerController>();
|
|
if (playerController == null)
|
|
{
|
|
Debug.LogError("PlaerController не найден в сцене!");
|
|
return;
|
|
}
|
|
|
|
deathScreen.SetActive(false);
|
|
winScreen.SetActive(false);
|
|
settingsMenu.SetActive(false);
|
|
|
|
mouseSensitivitySlider.value = playerController.GetSensitivity();
|
|
soundVolumeSlider.value = AudioListener.volume;
|
|
if (mouseSensitivityInput != null)
|
|
mouseSensitivityInput.text = mouseSensitivitySlider.value.ToString();
|
|
if (soundVolumeInput != null)
|
|
soundVolumeInput.text = soundVolumeSlider.value.ToString("F2");
|
|
|
|
restartButton.onClick.AddListener(RestartGame);
|
|
mainMenuButton.onClick.AddListener(GoToMainMenu);
|
|
exitButton.onClick.AddListener(ExitGame);
|
|
|
|
mouseSensitivitySlider.onValueChanged.AddListener(UpdateMouseSensitivity);
|
|
soundVolumeSlider.onValueChanged.AddListener(UpdateSoundVolume);
|
|
|
|
if (mouseSensitivityInput != null)
|
|
mouseSensitivityInput.onEndEdit.AddListener(UpdateMouseSensitivityFromInput);
|
|
if (soundVolumeInput != null)
|
|
soundVolumeInput.onEndEdit.AddListener(UpdateSoundVolumeFromInput);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Escape) && !deathScreen.activeSelf && !winScreen.activeSelf)
|
|
{
|
|
isPaused = !isPaused;
|
|
settingsMenu.SetActive(isPaused);
|
|
Time.timeScale = isPaused ? 0f : 1f;
|
|
Cursor.lockState = isPaused ? CursorLockMode.None : CursorLockMode.Locked;
|
|
Cursor.visible = isPaused;
|
|
if (playerController != null)
|
|
{
|
|
playerController.enabled = !isPaused;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ShowDeathScreen()
|
|
{
|
|
deathScreen.SetActive(true);
|
|
Time.timeScale = 0f;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
if (playerController != null)
|
|
{
|
|
playerController.enabled = false;
|
|
}
|
|
}
|
|
|
|
public void ShowWinScreen()
|
|
{
|
|
winScreen.SetActive(true);
|
|
Time.timeScale = 0f;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
if (playerController != null)
|
|
{
|
|
playerController.enabled = false;
|
|
}
|
|
}
|
|
|
|
void RestartGame()
|
|
{
|
|
Time.timeScale = 1f;
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
|
}
|
|
|
|
void GoToMainMenu()
|
|
{
|
|
Time.timeScale = 1f;
|
|
SceneManager.LoadScene("MainMenu");
|
|
}
|
|
|
|
void ExitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
|
|
void UpdateMouseSensitivity(float value)
|
|
{
|
|
if (playerController != null)
|
|
{
|
|
playerController.SetSensitivity(value);
|
|
Debug.Log($"GameUIManager: Установлена сенса = {value}");
|
|
}
|
|
if (mouseSensitivityInput != null)
|
|
mouseSensitivityInput.text = value.ToString();
|
|
}
|
|
|
|
void UpdateSoundVolume(float value)
|
|
{
|
|
FootstepSounds footstep = FindObjectOfType<FootstepSounds>();
|
|
if (footstep != null)
|
|
{
|
|
footstep.audioSource.volume = value; // Или value * 0.8f для тише
|
|
}
|
|
AudioListener.volume = value;
|
|
if (soundVolumeInput != null)
|
|
soundVolumeInput.text = value.ToString("F2");
|
|
}
|
|
|
|
void UpdateMouseSensitivityFromInput(string inputText)
|
|
{
|
|
if (float.TryParse(inputText, out float value))
|
|
{
|
|
value = Mathf.Clamp(value, 1f, 2000f);
|
|
mouseSensitivitySlider.value = value;
|
|
UpdateMouseSensitivity(value);
|
|
}
|
|
else
|
|
{
|
|
if (mouseSensitivityInput != null)
|
|
mouseSensitivityInput.text = mouseSensitivitySlider.value.ToString();
|
|
}
|
|
}
|
|
|
|
void UpdateSoundVolumeFromInput(string inputText)
|
|
{
|
|
if (float.TryParse(inputText, out float value))
|
|
{
|
|
value = Mathf.Clamp(value, 0f, 1f);
|
|
soundVolumeSlider.value = value;
|
|
UpdateSoundVolume(value);
|
|
}
|
|
else
|
|
{
|
|
if (soundVolumeInput != null)
|
|
soundVolumeInput.text = soundVolumeSlider.value.ToString("F2");
|
|
}
|
|
}
|
|
} |