2025-09-17 18:56:28 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.Rendering;
|
|
|
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using System.Collections;
|
2025-10-09 07:51:05 +08:00
|
|
|
using System.Collections.Generic;
|
2025-09-17 18:56:28 +08:00
|
|
|
|
2025-09-29 07:45:07 +08:00
|
|
|
public class GraphicsPanel : UIBasePanel, ISettingsPanel
|
2025-09-17 18:56:28 +08:00
|
|
|
{
|
|
|
|
|
[Header("UI References")]
|
|
|
|
|
[SerializeField] private TMP_Dropdown qualityDropdown;
|
|
|
|
|
[SerializeField] private Toggle vsyncToggle;
|
|
|
|
|
[SerializeField] private Slider shadowDistanceSlider;
|
|
|
|
|
[SerializeField] private TMP_Dropdown antiAliasingDropdown;
|
|
|
|
|
[SerializeField] private Toggle bloomToggle;
|
|
|
|
|
[SerializeField] private Slider renderScaleSlider;
|
|
|
|
|
|
2025-10-09 07:51:05 +08:00
|
|
|
[SerializeField] private TMP_Dropdown resolutionDropdown;
|
|
|
|
|
[SerializeField] private Toggle fullscreenToggle;
|
|
|
|
|
[SerializeField] private Toggle borderlessToggle;
|
|
|
|
|
[SerializeField] private TMP_Dropdown displayDropdown;
|
|
|
|
|
|
|
|
|
|
private Resolution[] resolutions;
|
|
|
|
|
bool init = false;
|
|
|
|
|
|
2025-09-29 11:03:26 +08:00
|
|
|
public override void OnShow()
|
2025-09-17 18:56:28 +08:00
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
var settings =SettingsManager.Inst.CurrentSettings;
|
|
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
|
{
|
|
|
|
|
InitializeResolutionDropdown();
|
|
|
|
|
InitializeDisplayDropdown();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-29 11:03:26 +08:00
|
|
|
qualityDropdown.SetValueWithoutNotify(settings.graphicsSettings.qualityLevel);
|
|
|
|
|
vsyncToggle.SetIsOnWithoutNotify(settings.graphicsSettings.vsyncEnabled);
|
|
|
|
|
shadowDistanceSlider.SetValueWithoutNotify(settings.graphicsSettings.shadowDistance);
|
|
|
|
|
antiAliasingDropdown.SetValueWithoutNotify(settings.graphicsSettings.antiAliasing);
|
|
|
|
|
bloomToggle.SetIsOnWithoutNotify(settings.graphicsSettings.bloomEnabled);
|
|
|
|
|
renderScaleSlider.SetValueWithoutNotify(settings.graphicsSettings.renderScale);
|
2025-10-09 07:51:05 +08:00
|
|
|
|
|
|
|
|
resolutionDropdown.SetValueWithoutNotify(settings.graphicsSettings.resolutionIndex);
|
|
|
|
|
fullscreenToggle.SetIsOnWithoutNotify(settings.graphicsSettings.fullscreen);
|
|
|
|
|
borderlessToggle.SetIsOnWithoutNotify(settings.graphicsSettings.borderless);
|
|
|
|
|
displayDropdown.SetValueWithoutNotify(settings.graphicsSettings.displayIndex);
|
|
|
|
|
}
|
|
|
|
|
private void InitializeResolutionDropdown()
|
|
|
|
|
{
|
|
|
|
|
resolutions = Screen.resolutions;
|
|
|
|
|
resolutionDropdown.ClearOptions();
|
|
|
|
|
|
|
|
|
|
var options = new List<string>();
|
|
|
|
|
for (int i = 0; i < resolutions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int refreshRate = Mathf.RoundToInt((float)resolutions[i].refreshRateRatio.value);
|
|
|
|
|
options.Add($"{resolutions[i].width}x{resolutions[i].height} {refreshRate}Hz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resolutionDropdown.AddOptions(options);
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-09 07:51:05 +08:00
|
|
|
private void InitializeDisplayDropdown()
|
|
|
|
|
{
|
|
|
|
|
displayDropdown.ClearOptions();
|
|
|
|
|
var options = new List<string>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Display.displays.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
options.Add($"Display {i + 1}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayDropdown.AddOptions(options);
|
|
|
|
|
}
|
2025-09-17 18:56:28 +08:00
|
|
|
|
|
|
|
|
public void OnQualityChanged(int index)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.qualityLevel = index;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnVSyncChanged(bool value)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.vsyncEnabled = value;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnShadowDistanceChanged(float value)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.shadowDistance = value;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnAntiAliasingChanged(int index)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.antiAliasing = index;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnBloomChanged(bool value)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.bloomEnabled = value;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnRenderScaleChanged(float value)
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.renderScale = value;
|
|
|
|
|
}
|
|
|
|
|
public void OnResolutionChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.resolutionIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFullscreenChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.fullscreen = value;
|
|
|
|
|
UpdateBorderlessToggleState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnBorderlessChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.borderless = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDisplayChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings.displayIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBorderlessToggleState()
|
|
|
|
|
{
|
|
|
|
|
borderlessToggle.interactable = fullscreenToggle.isOn;
|
|
|
|
|
if (!fullscreenToggle.isOn)
|
|
|
|
|
borderlessToggle.isOn = false;
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ApplySettings()
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
GraphicsManager.Inst.ApplySettings();
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|
2025-09-29 07:45:07 +08:00
|
|
|
|
|
|
|
|
public void ResetToDefault()
|
|
|
|
|
{
|
2025-10-09 07:51:05 +08:00
|
|
|
SettingsManager.Inst.CurrentSettings.graphicsSettings = SettingsManager.Inst.DefSetting.graphicsSettings;
|
2025-09-29 07:45:07 +08:00
|
|
|
}
|
2025-09-17 18:56:28 +08:00
|
|
|
}
|