Files
AZTECH_WB/Assets/Scripts/UI/SettingPanel/GraphicsSettingContent.cs

145 lines
6.0 KiB
C#
Raw Permalink Normal View History

2026-01-09 10:43:40 +09:00
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using AZTECHWB.Management;
using AZTECHWB.Extensions;
2026-01-09 10:43:40 +09:00
namespace AZTECHWB.UI
2026-01-09 10:43:40 +09:00
{
public class GraphicsSettingContent : MonoBehaviour
2026-01-09 10:43:40 +09:00
{
private OptionManager optionManager;
private UniversalRenderPipelineAsset urpAsset;
private GraphicsSettingItem ResolutionItem;
private GraphicsSettingItem TextureQualityItem;
private GraphicsSettingItem ShadowQualityItem;
private GraphicsSettingItem AntiAliasingItem;
private GraphicsSettingItem VSyncItem;
private GraphicsSettingItem AnisotropicFilteringItem;
2026-01-09 10:43:40 +09:00
Vector2Int[] resolutions = { new(1280, 720), new(1600, 900), new(1920, 1080), new(2560, 1440) };
FullScreenMode[] screenModes = { FullScreenMode.ExclusiveFullScreen, FullScreenMode.FullScreenWindow, FullScreenMode.Windowed };
string[] textureNames = { "높음", "중간", "낮음" };
string[] shadowNames = { "끄기", "낮음", "중간", "높음" };
string[] aaNames = { "끄기", "MSAA x2", "MSAA x4", "MSAA x8" };
2026-01-09 10:43:40 +09:00
int[] aaValues = { 0, 2, 4, 8 };
int resIndex, screenModeIndex, textureIndex, shadowIndex, aaIndex, vSync, afIndex;
public void Init()
{
transform.TryGetComponentInChildren(nameof(ResolutionItem), out ResolutionItem);
transform.TryGetComponentInChildren(nameof(TextureQualityItem), out TextureQualityItem);
transform.TryGetComponentInChildren(nameof(ShadowQualityItem), out ShadowQualityItem);
transform.TryGetComponentInChildren(nameof(AntiAliasingItem), out AntiAliasingItem);
transform.TryGetComponentInChildren(nameof(VSyncItem), out VSyncItem);
transform.TryGetComponentInChildren(nameof(AnisotropicFilteringItem), out AnisotropicFilteringItem);
2026-01-09 10:43:40 +09:00
string[] resolutionNames = new string[resolutions.Length];
for (int i = 0; i < resolutions.Length; i++)
resolutionNames[i] = $"{resolutions[i].x} x {resolutions[i].y}";
ResolutionItem.InitDropdown(v => resIndex = v);
ResolutionItem.SetDropdownOptions(resolutionNames);
TextureQualityItem.InitDropdown(v => textureIndex = v);
TextureQualityItem.SetDropdownOptions(textureNames);
ShadowQualityItem.InitDropdown(v => shadowIndex = v);
ShadowQualityItem.SetDropdownOptions(shadowNames);
AntiAliasingItem.InitDropdown(v => aaIndex = v);
AntiAliasingItem.SetDropdownOptions(aaNames);
VSyncItem.InitToggle(v => vSync = v ? 1 : 0);
AnisotropicFilteringItem.InitToggle(v => afIndex = v ? 1 : 0);
2026-01-09 10:43:40 +09:00
optionManager = FindAnyObjectByType<OptionManager>();
urpAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
optionManager.onCompletedLoadOption += ApplyIniToUI;
}
public void ApplyIniToUI()
{
resIndex = GetResolutionIndex(optionManager.GetValue("Graphics", "Resolution"));
screenModeIndex = int.Parse(optionManager.GetValue("Graphics", "ScreenMode", "0"));
textureIndex = int.Parse(optionManager.GetValue("Graphics", "Texture", "0"));
shadowIndex = int.Parse(optionManager.GetValue("Graphics", "Shadow", "2"));
aaIndex = int.Parse(optionManager.GetValue("Graphics", "AA", "2"));
vSync = int.Parse(optionManager.GetValue("Graphics", "VSync", "1"));
afIndex = int.Parse(optionManager.GetValue("Graphics", "AF", "1"));
RefreshUI();
}
public void Apply()
{
var r = resolutions[resIndex];
optionManager.SetValue("Graphics", "Resolution", $"{r.x}x{r.y}");
optionManager.SetValue("Graphics", "ScreenMode", screenModeIndex.ToString());
optionManager.SetValue("Graphics", "Texture", textureIndex.ToString());
optionManager.SetValue("Graphics", "Shadow", shadowIndex.ToString());
optionManager.SetValue("Graphics", "AA", aaIndex.ToString());
optionManager.SetValue("Graphics", "VSync", vSync.ToString());
optionManager.SetValue("Graphics", "AF", afIndex.ToString());
Screen.fullScreenMode = screenModes[screenModeIndex];
Screen.SetResolution(r.x, r.y, Screen.fullScreenMode);
QualitySettings.globalTextureMipmapLimit = textureIndex;
QualitySettings.vSyncCount = vSync;
QualitySettings.anisotropicFiltering = (AnisotropicFiltering)afIndex;
ApplyURPShadow();
ApplyURPAntiAliasing();
}
void ApplyURPShadow()
{
if (urpAsset == null) return;
urpAsset.shadowDistance = shadowIndex switch
{
0 => 0,
1 => 20,
2 => 50,
3 => 100,
_ => 50
};
}
void ApplyURPAntiAliasing()
{
if (urpAsset == null) return;
urpAsset.msaaSampleCount = aaValues[aaIndex];
var cam = Camera.main;
if (cam != null && cam.TryGetComponent(out UniversalAdditionalCameraData data))
{
data.antialiasing = aaValues[aaIndex] == 0 ? AntialiasingMode.None : AntialiasingMode.FastApproximateAntialiasing;
}
}
void RefreshUI()
{
ResolutionItem.SetDropdownValue(resIndex);
TextureQualityItem.SetDropdownValue(textureIndex);
ShadowQualityItem.SetDropdownValue(shadowIndex);
AntiAliasingItem.SetDropdownValue(aaIndex);
VSyncItem.SetToggleValue(vSync != 0);
AnisotropicFilteringItem.SetToggleValue(afIndex != 0);
2026-01-09 10:43:40 +09:00
}
int GetResolutionIndex(string value)
{
for (int i = 0; i < resolutions.Length; i++)
{
if ($"{resolutions[i].x}x{resolutions[i].y}" == value)
return i;
}
return 2; // 1920x1080
}
}
}