Ver.0.3.0.33
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization.Settings;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于规定配置如何影响游戏内容
|
||||
/// </summary>
|
||||
public class SettingLoader
|
||||
{
|
||||
private static readonly string SettingPath = Application.streamingAssetsPath + "/Config/setting.json";
|
||||
|
||||
private readonly ConfigContainer _container;
|
||||
|
||||
private SettingLoader()
|
||||
{
|
||||
// 读取数据
|
||||
_container = new ConfigContainer(SettingPath);
|
||||
LoadAllSetting();
|
||||
// 注册回调函数
|
||||
_container.OnWrite += OnSettingChanged;
|
||||
}
|
||||
|
||||
private void LoadAllSetting()
|
||||
{
|
||||
var settingConfig = _container.ReadAll();
|
||||
foreach (var pair in settingConfig)
|
||||
{
|
||||
OnSettingChanged(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSettingChanged(string propName, string value)
|
||||
{
|
||||
// 配置项同步
|
||||
switch (propName)
|
||||
{
|
||||
case "Volume":
|
||||
AudioManager.Instance.SetVolume(float.Parse(value));
|
||||
break;
|
||||
case "TextSpeed":
|
||||
// TODO 调整文字速度
|
||||
break;
|
||||
case "Resolution":
|
||||
// TODO 调整分辨率
|
||||
break;
|
||||
case "WindowMode":
|
||||
// 屏幕模式
|
||||
GameManager.Instance.SetScreenMode(value);
|
||||
break;
|
||||
case "Language":
|
||||
// TODO 修改语言
|
||||
LocalizationKit.SwitchLanguage(value);
|
||||
break;
|
||||
default:
|
||||
Debug.Log($"{propName}未正确处理");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(string propName, string value)
|
||||
{
|
||||
_container.Write(propName, value);
|
||||
}
|
||||
|
||||
public bool TryRead(string key, out string value)
|
||||
{
|
||||
return _container.TryRead(key, out value);
|
||||
}
|
||||
|
||||
public Dictionary<string, string> ReadAll()
|
||||
{
|
||||
return _container.ReadAll();
|
||||
}
|
||||
|
||||
#region 单例部分
|
||||
|
||||
public static SettingLoader Instance { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Instance = new SettingLoader();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user