pgiz4_moi/Assets/Scripts/ThemeManager.cs

61 lines
1.6 KiB
C#
Raw Permalink 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 System.Collections.Generic;
public class ThemeManager : MonoBehaviour
{
public static ThemeManager Instance { get; private set; }
public List<VisualTheme> themes;
private VisualTheme currentTheme;
private const string SelectedThemeKey = "SelectedThemeIndex";
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
LoadTheme();
}
private void LoadTheme()
{
int selectedThemeIndex = PlayerPrefs.GetInt(SelectedThemeKey, 0);
if (themes != null && themes.Count > selectedThemeIndex)
{
currentTheme = themes[selectedThemeIndex];
Debug.Log("Тема загружена: " + currentTheme.themeName);
}
else
{
Debug.LogError("Не удалось загрузить тему! Проверьте список тем в ThemeManager.");
}
}
public void SetTheme(int themeIndex)
{
if (themes != null && themes.Count > themeIndex)
{
PlayerPrefs.SetInt(SelectedThemeKey, themeIndex);
PlayerPrefs.Save();
currentTheme = themes[themeIndex];
Debug.Log("Тема выбрана: " + currentTheme.themeName);
}
}
// Методы для получения ассетов текущей темы
public VisualTheme GetCurrentTheme()
{
if (currentTheme == null)
{
LoadTheme();
}
return currentTheme;
}
}