UI框架开发中

This commit is contained in:
2025-09-29 11:03:26 +08:00
parent 71edbb6088
commit 3ea4257e2d
24 changed files with 292 additions and 266 deletions

View File

@@ -15,160 +15,51 @@ public class GraphicsPanel : UIBasePanel, ISettingsPanel
[SerializeField] private Toggle bloomToggle;
[SerializeField] private Slider renderScaleSlider;
[Header("Graphics References")]
[SerializeField] private VolumeProfile urpVolumeProfile;
[Header("Quality Presets")]
[SerializeField]
private QualityPreset[] qualityPresets = new QualityPreset[4]
public override void OnShow()
{
new QualityPreset("Low", 0, false, 20f, 0, false, 0.8f),
new QualityPreset("Medium", 1, false, 40f, 1, true, 1.0f),
new QualityPreset("High", 2, true, 60f, 2, true, 1.2f),
new QualityPreset("Ultra", 3, true, 100f, 2, true, 1.5f)
};
[System.Serializable]
public class QualityPreset
{
public string name;
public int qualityLevel;
public bool vsyncEnabled;
public float shadowDistance;
public int antiAliasing;
public bool bloomEnabled;
public float renderScale;
public QualityPreset(string name, int qualityLevel, bool vsyncEnabled, float shadowDistance,
int antiAliasing, bool bloomEnabled, float renderScale)
{
this.name = name;
this.qualityLevel = qualityLevel;
this.vsyncEnabled = vsyncEnabled;
this.shadowDistance = shadowDistance;
this.antiAliasing = antiAliasing;
this.bloomEnabled = bloomEnabled;
this.renderScale = renderScale;
}
}
private UniversalRenderPipelineAsset _urpAsset;
private Bloom _bloom;
private void OnEnable()
{
StartCoroutine(InitializeDelayed());
}
private IEnumerator InitializeDelayed()
{
yield return null;
_urpAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
if (_urpAsset == null)
{
Debug.LogError("URP Asset null");
yield break;
}
if (urpVolumeProfile != null && !urpVolumeProfile.TryGet(out _bloom))
{
Debug.LogWarning("Volume Profile Bloom null");
}
//InitializeQualityDropdown();
var settings = SettingsManager.Inst.CurrentSettings;
qualityDropdown.SetValueWithoutNotify(settings.qualityLevel);
vsyncToggle.SetIsOnWithoutNotify(settings.vsyncEnabled);
shadowDistanceSlider.SetValueWithoutNotify(settings.shadowDistance);
antiAliasingDropdown.SetValueWithoutNotify(settings.antiAliasing);
bloomToggle.SetIsOnWithoutNotify(settings.bloomEnabled);
renderScaleSlider.SetValueWithoutNotify(settings.renderScale);
ApplySettings();
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);
}
//private void InitializeQualityDropdown()
//{
// qualityDropdown.ClearOptions();
// foreach (var preset in qualityPresets)
// {
// qualityDropdown.options.Add(new TMP_Dropdown.OptionData(preset.name));
// }
//}
public void OnQualityChanged(int index)
{
SettingsManager.Inst.CurrentSettings.qualityLevel = index;
var settings = SettingsManager.Inst.CurrentSettings;
if (index >= 0 && index < qualityPresets.Length)
{
var preset = qualityPresets[index];
// Ӧ<><D3A6>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
vsyncToggle.SetIsOnWithoutNotify(preset.vsyncEnabled);
shadowDistanceSlider.SetValueWithoutNotify(preset.shadowDistance);
antiAliasingDropdown.SetValueWithoutNotify(preset.antiAliasing);
bloomToggle.SetIsOnWithoutNotify(preset.bloomEnabled);
renderScaleSlider.SetValueWithoutNotify(preset.renderScale);
}
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OnVSyncChanged(settings.vsyncEnabled);
OnShadowDistanceChanged(settings.shadowDistance);
OnAntiAliasingChanged(settings.antiAliasing);
OnBloomChanged(settings.bloomEnabled);
OnRenderScaleChanged(settings.renderScale);
GameSystem.Inst.Graphics.graphicsSetting.qualityLevel = index;
}
public void OnVSyncChanged(bool value)
{
SettingsManager.Inst.CurrentSettings.vsyncEnabled = value;
QualitySettings.vSyncCount = value ? 1 : 0;
GameSystem.Inst.Graphics.graphicsSetting.vsyncEnabled = value;
}
public void OnShadowDistanceChanged(float value)
{
SettingsManager.Inst.CurrentSettings.shadowDistance = value;
if (_urpAsset != null)
_urpAsset.shadowDistance = value;
GameSystem.Inst.Graphics.graphicsSetting.shadowDistance = value;
}
public void OnAntiAliasingChanged(int index)
{
SettingsManager.Inst.CurrentSettings.antiAliasing = index;
if (_urpAsset != null)
_urpAsset.msaaSampleCount = (int)Mathf.Pow(2, index);
GameSystem.Inst.Graphics.graphicsSetting.antiAliasing = index;
}
public void OnBloomChanged(bool value)
{
SettingsManager.Inst.CurrentSettings.bloomEnabled = value;
if (_bloom != null)
_bloom.active = value;
GameSystem.Inst.Graphics.graphicsSetting.bloomEnabled = value;
}
public void OnRenderScaleChanged(float value)
{
SettingsManager.Inst.CurrentSettings.renderScale = value;
if (_urpAsset != null)
_urpAsset.renderScale = value;
GameSystem.Inst.Graphics.graphicsSetting.renderScale = value;
}
public void ApplySettings()
{
if (_urpAsset == null) return;
var settings = SettingsManager.Inst.CurrentSettings;
if (settings.qualityLevel != 4)
QualitySettings.SetQualityLevel(settings.qualityLevel);
QualitySettings.vSyncCount = settings.vsyncEnabled ? 1 : 0;
_urpAsset.shadowDistance = settings.shadowDistance;
_urpAsset.msaaSampleCount = (int)Mathf.Pow(2, settings.antiAliasing);
_urpAsset.renderScale = settings.renderScale;
if (_bloom != null) _bloom.active = settings.bloomEnabled;
GameSystem.Inst.Graphics.ApplySettings();
}
public void ResetToDefault()