118 lines
2.9 KiB
C#
118 lines
2.9 KiB
C#
/*
|
|
* @Author: 白哉
|
|
* @Description:
|
|
* @Date: 2025年07月24日 星期四 11:07:37
|
|
* @Modify:
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Logic.Multilingual;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace Logic.Config
|
|
{
|
|
public class ConfigManager
|
|
{
|
|
public static ConfigManager Instance = new ConfigManager();
|
|
public GameConfig Config;
|
|
public VersionConfig VersionCfg;
|
|
|
|
|
|
public void Init()
|
|
{
|
|
if (Config == null)
|
|
{
|
|
string path = Application.persistentDataPath + "/game_cfg.json";
|
|
if (File.Exists(path))
|
|
{
|
|
string json = File.ReadAllText(path);
|
|
Config = JsonUtility.FromJson<GameConfig>(json);
|
|
}
|
|
Config ??= new GameConfig();
|
|
}
|
|
|
|
if (!VersionCfg)
|
|
{
|
|
VersionCfg = Resources.Load<VersionConfig>("Export/VersionConfig");
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Config == null || !Config.IsChanged) return;
|
|
string json = JsonUtility.ToJson(Config);
|
|
File.WriteAllText(Application.persistentDataPath + "/game_cfg.json", json);
|
|
}
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class GameConfig
|
|
{
|
|
[SerializeField]
|
|
private MultilingualType _multilingualType;
|
|
[SerializeField]
|
|
private float _musicVolume;
|
|
[SerializeField]
|
|
private float _audioVolume;
|
|
[SerializeField]
|
|
private bool _showReminder;
|
|
private bool _isChanged;
|
|
public bool IsChanged => _isChanged;
|
|
|
|
|
|
public MultilingualType MultilingualType
|
|
{
|
|
get => _multilingualType;
|
|
set
|
|
{
|
|
if (_multilingualType == value) return;
|
|
_isChanged = true;
|
|
_multilingualType = value;
|
|
}
|
|
}
|
|
|
|
public float MusicVolume
|
|
{
|
|
get => _musicVolume;
|
|
set
|
|
{
|
|
if (Math.Abs(_musicVolume - value) < 0.01f) return;
|
|
_isChanged = true;
|
|
_musicVolume = value;
|
|
}
|
|
}
|
|
public float AudioVolume
|
|
{
|
|
get => _audioVolume;
|
|
set
|
|
{
|
|
if (Math.Abs(_audioVolume - value) < 0.01f) return;
|
|
_isChanged = true;
|
|
_audioVolume = value;
|
|
}
|
|
}
|
|
public bool ShowReminder
|
|
{
|
|
get => _showReminder;
|
|
set
|
|
{
|
|
if (_showReminder == value) return;
|
|
_isChanged = true;
|
|
_showReminder = value;
|
|
}
|
|
}
|
|
|
|
|
|
public GameConfig()
|
|
{
|
|
_multilingualType = MultilingualType.None;
|
|
_musicVolume = 0.5f;
|
|
_audioVolume = 0.5f;
|
|
_showReminder = true;
|
|
}
|
|
}
|
|
} |