Danro/Assets/Scripts/Settings/Core/SettingsButtonActions.cs
Danil Iarosh 4d05d1adbb
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
FEAT: Added new settings system
- Добавил новую систему настроек, возможности:
    - Динамически создает список настроек
    - Сохраняет настройки в JSON-файл
    - Возможность группировать настройки
    - Широкие возможности по кастомизации
    - Применение настроек в реальном времени (частично)
- Добавил префабы для новых элементов настроек
- Изменил поведение игры исходя из нового формата настроек
2026-02-04 14:32:15 +03:00

117 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.SceneManagement;
namespace RR.Common.Settings
{
/// <summary>
/// Готовые методы для кнопок настроек.
/// Эти методы можно вызывать из UnityEvent в SettingsDatabase через Inspector.
/// </summary>
public class SettingsButtonActions : MonoBehaviour
{
public static SettingsButtonActions Instance { get; private set; }
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
/// <summary>
/// Сбросить все настройки к значениям по умолчанию
/// </summary>
public void ResetAllSettings()
{
if (SettingsManager.Instance)
{
SettingsManager.Instance.ResetAllToDefaults();
Debug.Log("[SettingsButtonActions] Настройки сброшены");
}
}
/// <summary>
/// Выход из игры
/// </summary>
public void QuitGame()
{
Debug.Log("[SettingsButtonActions] Выход из игры");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
/// <summary>
/// Загрузить главное меню
/// </summary>
public void LoadMainMenu()
{
LoadScene("MainMenu");
}
/// <summary>
/// Загрузить сцену по имени
/// </summary>
public void LoadScene(string sceneName)
{
if (!string.IsNullOrEmpty(sceneName))
{
Debug.Log($"[SettingsButtonActions] Загрузка сцены: {sceneName}");
SceneManager.LoadScene(sceneName);
}
}
/// <summary>
/// Открыть URL в браузере
/// </summary>
public void OpenURL(string url)
{
if (!string.IsNullOrEmpty(url))
{
Debug.Log($"[SettingsButtonActions] Открытие URL: {url}");
Application.OpenURL(url);
}
}
/// <summary>
/// Открыть папку с сохранениями
/// </summary>
public void OpenSavesFolder()
{
string path = Application.persistentDataPath;
Debug.Log($"[SettingsButtonActions] Открытие папки: {path}");
Application.OpenURL($"file://{path}");
}
/// <summary>
/// Перезагрузить текущую сцену
/// </summary>
public void ReloadCurrentScene()
{
Scene currentScene = SceneManager.GetActiveScene();
Debug.Log($"[SettingsButtonActions] Перезагрузка сцены: {currentScene.name}");
SceneManager.LoadScene(currentScene.name);
}
/// <summary>
/// Применить все настройки заново
/// </summary>
public void ApplyAllSettings()
{
if (SettingsManager.Instance)
{
SettingsManager.Instance.ApplyAll();
Debug.Log("[SettingsButtonActions] Настройки применены");
}
}
}
}