меню паузы, механика записок и лифта

This commit is contained in:
lapich committed 2026-10-22 16:08:20 +03:00
1 parent cbda26dfc0
commit cdd1055fd8
55 files changed
+3860 -1087

No files matched your search

+132 -83
View File
@@ -12,9 +12,12 @@ public class PauseMenu : MonoBehaviour
[Header("Кнопки панели действий")]
public Button resumeButton;
public Button settingsButton;
public Button restartButton;
public Button mainMenuButton;
public Button quitButton;
public Button backFromSettingsButton;
public Button resetDefaultsButton;
[Header("Вкладки")]
public Button[] tabButtons;
@@ -38,7 +41,6 @@ public class PauseMenu : MonoBehaviour
private bool isPaused = false;
private bool isInitializing = false;
private bool wasCursorLocked = false;
private List<Resolution> filteredResolutions = new List<Resolution>();
public bool IsPaused => isPaused;
@@ -58,14 +60,15 @@ public class PauseMenu : MonoBehaviour
SetupActionButtons();
SetupTabs();
InitializeSettingsUI();
wasCursorLocked = (Cursor.lockState == CursorLockMode.Locked);
}
private void Update()
{
// Не открываем меню паузы, если активен экран смерти
// Не открываем меню паузы, если активен экран смерти, просмотр записки, клавиатура лифта или экран победы
if (DeathScreenUI.Instance != null && DeathScreenUI.Instance.IsShown) return;
if (NoteViewerUI.Instance != null && NoteViewerUI.Instance.IsOpen) return;
if (ElevatorKeypadUI.Instance != null && ElevatorKeypadUI.Instance.IsOpen) return;
if (LevelSuccessUI.Instance != null && LevelSuccessUI.Instance.IsOpen) return;
bool togglePause = false;
var keyboard = Keyboard.current;
@@ -73,30 +76,25 @@ public class PauseMenu : MonoBehaviour
{
if (keyboard.escapeKey.wasPressedThisFrame ||
keyboard.pKey.wasPressedThisFrame ||
keyboard.tabKey.wasPressedThisFrame ||
keyboard.pauseKey.wasPressedThisFrame)
{
togglePause = true;
}
}
#if ENABLE_LEGACY_INPUT_MANAGER
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.P))
{
togglePause = true;
}
#endif
var gamepad = Gamepad.current;
if (gamepad != null && gamepad.startButton.wasPressedThisFrame)
{
togglePause = true;
}
#if UNITY_EDITOR
// В Unity Editor при заблокированном курсоре нажатие Escape перехватывается редактором
// для снятия блокировки курсора (Cursor.lockState переключается в None) и не передается в Update().
// Поэтому в редакторе переключение lockState из Locked в None трактуется как нажатие Escape!
if (!isPaused && wasCursorLocked && Cursor.lockState != CursorLockMode.Locked)
{
togglePause = true;
}
wasCursorLocked = (Cursor.lockState == CursorLockMode.Locked);
#endif
if (togglePause)
{
if (isPaused)
@@ -123,7 +121,6 @@ public class PauseMenu : MonoBehaviour
Time.timeScale = 0f;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
wasCursorLocked = false;
if (pauseMenuPanel != null)
{
@@ -145,7 +142,6 @@ public class PauseMenu : MonoBehaviour
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
wasCursorLocked = true;
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
if (settingsPanel != null) settingsPanel.SetActive(false);
@@ -163,7 +159,12 @@ public class PauseMenu : MonoBehaviour
public void OpenSettings()
{
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
if (settingsPanel != null) settingsPanel.SetActive(true);
if (settingsPanel != null)
{
settingsPanel.SetActive(true);
InitializeSettingsUI();
SwitchTab(0);
}
}
public void CloseSettings()
@@ -173,6 +174,50 @@ public class PauseMenu : MonoBehaviour
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(true);
}
public void ResetToDefaults()
{
isInitializing = true;
if (volumeSlider != null) volumeSlider.value = 1.0f;
if (muteToggle != null) muteToggle.isOn = false;
PlayerPrefs.SetFloat(GameSettings.KeyMasterVolume, 1.0f);
PlayerPrefs.SetInt(GameSettings.KeyIsMuted, 0);
AudioListener.volume = 1.0f;
UpdateVolumeLabel(1.0f, false);
int defQuality = Mathf.Clamp(QualitySettings.names.Length - 1, 0, QualitySettings.names.Length - 1);
if (qualityDropdown != null)
{
qualityDropdown.value = defQuality;
qualityDropdown.RefreshShownValue();
}
QualitySettings.SetQualityLevel(defQuality, true);
PlayerPrefs.SetInt(GameSettings.KeyQualityLevel, defQuality);
if (fullscreenToggle != null) fullscreenToggle.isOn = true;
Screen.fullScreen = true;
PlayerPrefs.SetInt(GameSettings.KeyFullscreen, 1);
if (resolutionDropdown != null && filteredResolutions.Count > 0)
{
int lastIndex = filteredResolutions.Count - 1;
resolutionDropdown.value = lastIndex;
resolutionDropdown.RefreshShownValue();
var res = filteredResolutions[lastIndex];
Screen.SetResolution(res.width, res.height, FullScreenMode.FullScreenWindow);
PlayerPrefs.SetInt(GameSettings.KeyResolutionWidth, res.width);
PlayerPrefs.SetInt(GameSettings.KeyResolutionHeight, res.height);
}
if (sensitivitySlider != null) sensitivitySlider.value = 1.0f;
PlayerPrefs.SetFloat(GameSettings.KeyMouseSensitivity, 1.0f);
UpdateSensitivityLabel(1.0f);
PlayerPrefs.Save();
isInitializing = false;
Debug.Log("[PauseMenu] Настройки сброшены на значения по умолчанию.");
}
public void ReturnToMainMenu()
{
Time.timeScale = 1f;
@@ -214,16 +259,16 @@ public class PauseMenu : MonoBehaviour
if (img != null)
{
img.color = isActive
? new Color(0.00f, 0.65f, 0.85f, 0.95f) // Неоновый бирюзовый акцент
: new Color(0.06f, 0.10f, 0.16f, 0.85f); // Темный фон неактивной вкладки
? new Color(0.95f, 0.78f, 0.12f, 1.0f) // Золотистый активный
: new Color(0.08f, 0.08f, 0.08f, 0.85f);
}
var text = tabButtons[i].GetComponentInChildren<Text>();
if (text != null)
{
text.color = isActive
? Color.white
: new Color(0.40f, 0.55f, 0.65f, 0.80f);
? new Color(0.06f, 0.06f, 0.06f, 1.0f)
: new Color(0.6f, 0.6f, 0.6f, 0.8f);
}
}
}
@@ -237,8 +282,11 @@ public class PauseMenu : MonoBehaviour
for (int i = 0; i < tabButtons.Length; i++)
{
int index = i;
tabButtons[i].onClick.RemoveAllListeners();
tabButtons[i].onClick.AddListener(() => SwitchTab(index));
if (tabButtons[i] != null)
{
tabButtons[i].onClick.RemoveAllListeners();
tabButtons[i].onClick.AddListener(() => SwitchTab(index));
}
}
}
}
@@ -251,6 +299,12 @@ public class PauseMenu : MonoBehaviour
resumeButton.onClick.AddListener(ResumeGame);
}
if (settingsButton != null)
{
settingsButton.onClick.RemoveAllListeners();
settingsButton.onClick.AddListener(OpenSettings);
}
if (restartButton != null)
{
restartButton.onClick.RemoveAllListeners();
@@ -268,81 +322,76 @@ public class PauseMenu : MonoBehaviour
quitButton.onClick.RemoveAllListeners();
quitButton.onClick.AddListener(QuitGame);
}
if (backFromSettingsButton != null)
{
backFromSettingsButton.onClick.RemoveAllListeners();
backFromSettingsButton.onClick.AddListener(CloseSettings);
}
if (resetDefaultsButton != null)
{
resetDefaultsButton.onClick.RemoveAllListeners();
resetDefaultsButton.onClick.AddListener(ResetToDefaults);
}
}
public void AutoWireUI()
{
if (pauseMenuPanel == null)
{
var root = transform.Find("PauseRootPanel");
if (root != null)
{
pauseMenuPanel = root.gameObject;
}
var pPanel = transform.Find("PauseMenuPanel");
if (pPanel != null) pauseMenuPanel = pPanel.gameObject;
else
{
var panel = transform.Find("PauseMenuPanel");
if (panel != null) pauseMenuPanel = panel.gameObject;
var root = transform.Find("PauseRootPanel");
if (root != null) pauseMenuPanel = root.gameObject;
}
}
Transform window = transform.Find("PauseRootPanel/Settings_Window");
if (window != null)
if (settingsPanel == null)
{
var winRt = window.GetComponent<RectTransform>();
if (winRt != null && (winRt.sizeDelta.x <= 0f || winRt.sizeDelta.y <= 0f))
var sPanel = transform.Find("SettingsPanel");
if (sPanel != null) settingsPanel = sPanel.gameObject;
}
// Кнопки в карточке паузы
Transform pauseCard = transform.Find("PauseMenuPanel/Pause_Card") ?? transform.Find("PauseMenuPanel");
if (pauseCard != null)
{
Transform btnBox = pauseCard.Find("Buttons_Container") ?? pauseCard;
if (resumeButton == null) resumeButton = btnBox.Find("Btn_Resume")?.GetComponent<Button>();
if (settingsButton == null) settingsButton = btnBox.Find("Btn_Settings")?.GetComponent<Button>();
if (restartButton == null) restartButton = btnBox.Find("Btn_Restart")?.GetComponent<Button>();
if (mainMenuButton == null) mainMenuButton = btnBox.Find("Btn_MainMenu")?.GetComponent<Button>();
if (quitButton == null) quitButton = btnBox.Find("Btn_Quit")?.GetComponent<Button>();
}
// Кнопки и контролы в SettingsPanel
Transform sCard = transform.Find("SettingsPanel/Settings_Card");
if (sCard != null)
{
Transform bottomBtns = sCard.Find("Settings_BottomButtons");
if (bottomBtns != null)
{
winRt.anchorMin = new Vector2(0.5f, 0.5f);
winRt.anchorMax = new Vector2(0.5f, 0.5f);
winRt.pivot = new Vector2(0.5f, 0.5f);
winRt.anchoredPosition = Vector2.zero;
winRt.sizeDelta = new Vector2(1100f, 720f);
if (resetDefaultsButton == null) resetDefaultsButton = bottomBtns.Find("Button_ResetDefaults")?.GetComponent<Button>();
if (backFromSettingsButton == null) backFromSettingsButton = bottomBtns.Find("Button_Back")?.GetComponent<Button>();
}
Transform dock = window.Find("Bottom_Action_Dock");
if (dock != null)
Transform sList = sCard.Find("Settings_List");
if (sList != null)
{
if (resumeButton == null) resumeButton = dock.Find("Btn_Resume")?.GetComponent<Button>();
if (restartButton == null) restartButton = dock.Find("Btn_Restart")?.GetComponent<Button>();
if (mainMenuButton == null) mainMenuButton = dock.Find("Btn_MainMenu")?.GetComponent<Button>();
if (quitButton == null) quitButton = dock.Find("Btn_Quit")?.GetComponent<Button>();
if (volumeSlider == null) volumeSlider = sList.Find("Row_Volume/Slider")?.GetComponent<Slider>();
if (volumeValueText == null) volumeValueText = sList.Find("Row_Volume/ValueText")?.GetComponent<Text>();
if (muteToggle == null) muteToggle = sList.Find("Row_Mute/Toggle")?.GetComponent<Toggle>();
if (qualityDropdown == null) qualityDropdown = sList.Find("Row_Quality/Dropdown")?.GetComponent<Dropdown>();
if (fullscreenToggle == null) fullscreenToggle = sList.Find("Row_Fullscreen/Toggle")?.GetComponent<Toggle>();
if (resolutionDropdown == null) resolutionDropdown = sList.Find("Row_Resolution/Dropdown")?.GetComponent<Dropdown>();
if (sensitivitySlider == null) sensitivitySlider = sList.Find("Row_Sensitivity/Slider")?.GetComponent<Slider>();
if (sensitivityValueText == null) sensitivityValueText = sList.Find("Row_Sensitivity/ValueText")?.GetComponent<Text>();
}
Transform tabBar = window.Find("Tab_Bar");
Transform content = window.Find("Content_Area");
if (tabBar != null && (tabButtons == null || tabButtons.Length == 0))
{
tabButtons = new Button[tabBar.childCount];
for (int i = 0; i < tabBar.childCount; i++)
{
tabButtons[i] = tabBar.GetChild(i).GetComponent<Button>();
}
}
if (content != null && (tabPanels == null || tabPanels.Length == 0))
{
tabPanels = new GameObject[]
{
content.Find("Panel_Audio")?.gameObject,
content.Find("Panel_Graphics")?.gameObject,
content.Find("Panel_Controls")?.gameObject,
content.Find("Panel_Briefing")?.gameObject
};
}
if (volumeSlider == null) volumeSlider = content?.Find("Panel_Audio/Row_Volume/Slider")?.GetComponent<Slider>();
if (volumeValueText == null) volumeValueText = content?.Find("Panel_Audio/Row_Volume/ValueText")?.GetComponent<Text>();
if (muteToggle == null) muteToggle = content?.Find("Panel_Audio/Row_Mute/Toggle")?.GetComponent<Toggle>();
if (qualityDropdown == null) qualityDropdown = content?.Find("Panel_Graphics/Row_Quality/Dropdown")?.GetComponent<Dropdown>();
if (fullscreenToggle == null) fullscreenToggle = content?.Find("Panel_Graphics/Row_Fullscreen/Toggle")?.GetComponent<Toggle>();
if (resolutionDropdown == null) resolutionDropdown = content?.Find("Panel_Graphics/Row_Resolution/Dropdown")?.GetComponent<Dropdown>();
if (vsyncToggle == null) vsyncToggle = content?.Find("Panel_Graphics/Row_Vsync/Toggle")?.GetComponent<Toggle>();
if (sensitivitySlider == null) sensitivitySlider = content?.Find("Panel_Controls/Row_Sensitivity/Slider")?.GetComponent<Slider>();
if (sensitivityValueText == null) sensitivityValueText = content?.Find("Panel_Controls/Row_Sensitivity/ValueText")?.GetComponent<Text>();
if (invertYToggle == null) invertYToggle = content?.Find("Panel_Controls/Row_InvertY/Toggle")?.GetComponent<Toggle>();
}
}