增加游戏配置,自动保存
This commit is contained in:
parent
5b44a49996
commit
f48c5bee8a
3
Unity/Assets/Scripts/Logic/Config.meta
Normal file
3
Unity/Assets/Scripts/Logic/Config.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0cf0b14ac17d48d1a56f2418fb75e8ab
|
||||||
|
timeCreated: 1753327587
|
||||||
110
Unity/Assets/Scripts/Logic/Config/ConfigManager.cs
Normal file
110
Unity/Assets/Scripts/Logic/Config/ConfigManager.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* @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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Unity/Assets/Scripts/Logic/Config/ConfigManager.cs.meta
Normal file
3
Unity/Assets/Scripts/Logic/Config/ConfigManager.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cfee53245b0c45f3b8b8727bd959b1db
|
||||||
|
timeCreated: 1753327592
|
||||||
@ -7,6 +7,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using Logic.AI;
|
using Logic.AI;
|
||||||
using Logic.Audio;
|
using Logic.Audio;
|
||||||
|
using Logic.Config;
|
||||||
using Logic.CrashSight;
|
using Logic.CrashSight;
|
||||||
using Logic.Multilingual;
|
using Logic.Multilingual;
|
||||||
using Logic.Timeline;
|
using Logic.Timeline;
|
||||||
@ -87,6 +88,7 @@ namespace Logic
|
|||||||
new ResourceCache(); //ResourceCache单例 ,缓存所有resource
|
new ResourceCache(); //ResourceCache单例 ,缓存所有resource
|
||||||
ResourceCache.Instance.Init();
|
ResourceCache.Instance.Init();
|
||||||
|
|
||||||
|
ConfigManager.Instance.Init();
|
||||||
GameRecordManager.Instance.Init();
|
GameRecordManager.Instance.Init();
|
||||||
AudioManager.Instance.Init();
|
AudioManager.Instance.Init();
|
||||||
MultilingualManager.Instance.Init();
|
MultilingualManager.Instance.Init();
|
||||||
@ -195,6 +197,7 @@ namespace Logic
|
|||||||
Timer.Instance.Update();
|
Timer.Instance.Update();
|
||||||
AudioManager.Instance.Update();
|
AudioManager.Instance.Update();
|
||||||
TimelineManager.Instance.Update();
|
TimelineManager.Instance.Update();
|
||||||
|
ConfigManager.Instance.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasArchive()
|
public bool HasArchive()
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace Logic.Multilingual
|
|||||||
{
|
{
|
||||||
public enum MultilingualType
|
public enum MultilingualType
|
||||||
{
|
{
|
||||||
|
None,
|
||||||
ZH,
|
ZH,
|
||||||
TDZH,
|
TDZH,
|
||||||
EN,
|
EN,
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Logic.Config;
|
||||||
using Logic.CrashSight;
|
using Logic.CrashSight;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -27,9 +28,8 @@ namespace Logic.Multilingual
|
|||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
RefreshMultilingualData();
|
RefreshMultilingualData();
|
||||||
var multilingualValue = PlayerPrefs.GetInt("Multilingual", -1);
|
_currentType = ConfigManager.Instance.Config.MultilingualType;
|
||||||
if (multilingualValue == -1) _currentType = GetSystemLanguage();
|
if (_currentType == MultilingualType.None) _currentType = GetSystemLanguage();
|
||||||
else _currentType = (MultilingualType)multilingualValue;
|
|
||||||
ChangedMultilingual(_currentType);
|
ChangedMultilingual(_currentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +51,7 @@ namespace Logic.Multilingual
|
|||||||
RefreshTextComs();
|
RefreshTextComs();
|
||||||
_currentType = type;
|
_currentType = type;
|
||||||
foreach (var textCom in _textComs) textCom.OnMultilingualChanged();
|
foreach (var textCom in _textComs) textCom.OnMultilingualChanged();
|
||||||
PlayerPrefs.SetInt("Multilingual", (int)_currentType);
|
ConfigManager.Instance.Config.MultilingualType = _currentType;
|
||||||
PlayerPrefs.Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint GetFontGroupID(TMP_FontAsset font)
|
public uint GetFontGroupID(TMP_FontAsset font)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user