Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
- Добавил новую систему настроек, возможности:
- Динамически создает список настроек
- Сохраняет настройки в JSON-файл
- Возможность группировать настройки
- Широкие возможности по кастомизации
- Применение настроек в реальном времени (частично)
- Добавил префабы для новых элементов настроек
- Изменил поведение игры исходя из нового формата настроек
110 lines
3.5 KiB
C#
110 lines
3.5 KiB
C#
using UnityEngine;
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
namespace RR.Common.Settings
|
|
{
|
|
public static class SettingsApplier
|
|
{
|
|
public static void Apply(SettingEntry def, SettingValue v)
|
|
{
|
|
switch (def.applyTarget)
|
|
{
|
|
case ApplyTarget.None:
|
|
return;
|
|
|
|
case ApplyTarget.AudioMixerFloat01ToDb:
|
|
ApplyAudioMixer(def, v);
|
|
return;
|
|
|
|
case ApplyTarget.QualityLevel:
|
|
ApplyQuality(v.i);
|
|
return;
|
|
|
|
case ApplyTarget.VSync:
|
|
ApplyVSync(v.b);
|
|
return;
|
|
|
|
case ApplyTarget.TargetFps:
|
|
ApplyTargetFps(v.i);
|
|
return;
|
|
|
|
case ApplyTarget.Fullscreen:
|
|
ApplyFullscreen(v.b);
|
|
return;
|
|
|
|
case ApplyTarget.FullscreenMode:
|
|
ApplyFullscreenMode(v.i);
|
|
return;
|
|
|
|
case ApplyTarget.ResolutionIndex:
|
|
ApplyResolutionIndex(v.i);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private static void ApplyAudioMixer(SettingEntry def, SettingValue v)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(def.mixerParameter)) return;
|
|
|
|
float volume = Mathf.Clamp01(v.f);
|
|
|
|
// Применяем через AudioManager
|
|
if (GameManager.Instance?.Audio != null)
|
|
{
|
|
// Определяем тип звука по имени параметра
|
|
string param = def.mixerParameter.ToLower();
|
|
if (param.Contains("music"))
|
|
{
|
|
GameManager.Instance.Audio.SetMusicVolume(volume);
|
|
}
|
|
else if (param.Contains("sfx") || param.Contains("sound") || param.Contains("effect"))
|
|
{
|
|
GameManager.Instance.Audio.SetSfxVolume(volume);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ApplyQuality(int level)
|
|
{
|
|
var names = QualitySettings.names;
|
|
if (names == null || names.Length == 0) return;
|
|
|
|
level = Mathf.Clamp(level, 0, names.Length - 1);
|
|
QualitySettings.SetQualityLevel(level, true);
|
|
}
|
|
|
|
private static void ApplyVSync(bool enabled)
|
|
{
|
|
QualitySettings.vSyncCount = enabled ? 1 : 0;
|
|
}
|
|
|
|
private static void ApplyTargetFps(int fps)
|
|
{
|
|
Application.targetFrameRate = fps > 0 ? fps : -1;
|
|
}
|
|
|
|
private static void ApplyFullscreen(bool fullscreen)
|
|
{
|
|
Screen.fullScreen = fullscreen;
|
|
}
|
|
|
|
private static void ApplyFullscreenMode(int idx)
|
|
{
|
|
// FullScreenMode: 0..3 (ExclusiveFullScreen, FullScreenWindow, MaximizedWindow, Windowed)
|
|
idx = Mathf.Clamp(idx, 0, 3);
|
|
Screen.fullScreenMode = (FullScreenMode)idx;
|
|
}
|
|
|
|
private static void ApplyResolutionIndex(int index)
|
|
{
|
|
var rs = Screen.resolutions;
|
|
if (rs == null || rs.Length == 0) return;
|
|
|
|
index = Mathf.Clamp(index, 0, rs.Length - 1);
|
|
var r = rs[index];
|
|
|
|
// без герцовки — самый совместимый вариант
|
|
Screen.SetResolution(r.width, r.height, Screen.fullScreenMode);
|
|
}
|
|
}
|
|
} |