65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ashwild.Settings
|
|
{
|
|
public class GraphicsSettingsSubPanel : SettingsSubPanel
|
|
{
|
|
[Header("Controls")]
|
|
[SerializeField] private TMP_Dropdown qualityDropdown;
|
|
[SerializeField] private Toggle vsyncToggle;
|
|
[SerializeField] private Slider targetFpsSlider;
|
|
[SerializeField] private TMP_Text targetFpsLabel;
|
|
[SerializeField] private Slider fovSlider;
|
|
[SerializeField] private TMP_Text fovLabel;
|
|
|
|
private bool wiring;
|
|
|
|
private void Awake()
|
|
{
|
|
qualityDropdown.onValueChanged.AddListener(v => { if (!wiring) SettingsManager.Instance.SetQualityLevel(v); });
|
|
vsyncToggle.onValueChanged.AddListener(v => { if (!wiring) SettingsManager.Instance.SetVSync(v); });
|
|
targetFpsSlider.onValueChanged.AddListener(OnTargetFpsChanged);
|
|
fovSlider.onValueChanged.AddListener(OnFovChanged);
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
SettingsManager s = SettingsManager.Instance;
|
|
if (s == null) return;
|
|
|
|
wiring = true;
|
|
|
|
qualityDropdown.ClearOptions();
|
|
qualityDropdown.AddOptions(new List<string>(QualitySettings.names));
|
|
qualityDropdown.value = Mathf.Clamp(s.QualityLevel, 0, qualityDropdown.options.Count - 1);
|
|
qualityDropdown.RefreshShownValue();
|
|
|
|
vsyncToggle.SetIsOnWithoutNotify(s.VSync);
|
|
|
|
targetFpsSlider.SetValueWithoutNotify(s.TargetFps);
|
|
if (targetFpsLabel != null) targetFpsLabel.text = $"{s.TargetFps} FPS";
|
|
|
|
fovSlider.SetValueWithoutNotify(s.Fov);
|
|
if (fovLabel != null) fovLabel.text = $"{s.Fov:F0}°";
|
|
|
|
wiring = false;
|
|
}
|
|
|
|
private void OnTargetFpsChanged(float v)
|
|
{
|
|
int fps = Mathf.RoundToInt(v);
|
|
if (targetFpsLabel != null) targetFpsLabel.text = $"{fps} FPS";
|
|
if (!wiring) SettingsManager.Instance.SetTargetFps(fps);
|
|
}
|
|
|
|
private void OnFovChanged(float v)
|
|
{
|
|
if (fovLabel != null) fovLabel.text = $"{v:F0}°";
|
|
if (!wiring) SettingsManager.Instance.SetFov(v);
|
|
}
|
|
}
|
|
}
|