Compare commits

...

2 Commits

6 changed files with 124 additions and 5 deletions

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0cf0b14ac17d48d1a56f2418fb75e8ab
timeCreated: 1753327587

View File

@ -0,0 +1,110 @@
/*
* @Author:
* @Description:
* @Date: 20250724 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 void Init()
{
if (Config != null) return;
string path = Application.persistentDataPath + "/game_record.json";
if (File.Exists(path))
{
string json = File.ReadAllText(path);
Config = JsonUtility.FromJson<GameConfig>(json);
}
Config ??= new GameConfig();
}
public void Update()
{
if (Config == null || !Config.IsChanged) return;
string json = JsonUtility.ToJson(Config);
File.WriteAllText(Application.persistentDataPath + "/game_record.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;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cfee53245b0c45f3b8b8727bd959b1db
timeCreated: 1753327592

View File

@ -7,6 +7,7 @@
using System;
using Logic.AI;
using Logic.Audio;
using Logic.Config;
using Logic.CrashSight;
using Logic.Multilingual;
using Logic.Timeline;
@ -87,6 +88,7 @@ namespace Logic
new ResourceCache(); //ResourceCache单例 缓存所有resource
ResourceCache.Instance.Init();
ConfigManager.Instance.Init();
GameRecordManager.Instance.Init();
AudioManager.Instance.Init();
MultilingualManager.Instance.Init();
@ -195,6 +197,7 @@ namespace Logic
Timer.Instance.Update();
AudioManager.Instance.Update();
TimelineManager.Instance.Update();
ConfigManager.Instance.Update();
}
public bool HasArchive()

View File

@ -16,6 +16,7 @@ namespace Logic.Multilingual
{
public enum MultilingualType
{
None,
ZH,
TDZH,
EN,

View File

@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Linq;
using Logic.Config;
using Logic.CrashSight;
using TMPro;
using UnityEngine;
@ -27,9 +28,8 @@ namespace Logic.Multilingual
public void Init()
{
RefreshMultilingualData();
var multilingualValue = PlayerPrefs.GetInt("Multilingual", -1);
if (multilingualValue == -1) _currentType = GetSystemLanguage();
else _currentType = (MultilingualType)multilingualValue;
_currentType = ConfigManager.Instance.Config.MultilingualType;
if (_currentType == MultilingualType.None) _currentType = GetSystemLanguage();
ChangedMultilingual(_currentType);
}
@ -51,8 +51,7 @@ namespace Logic.Multilingual
RefreshTextComs();
_currentType = type;
foreach (var textCom in _textComs) textCom.OnMultilingualChanged();
PlayerPrefs.SetInt("Multilingual", (int)_currentType);
PlayerPrefs.Save();
ConfigManager.Instance.Config.MultilingualType = _currentType;
}
public uint GetFontGroupID(TMP_FontAsset font)