Files
AZTECH_WB/Assets/Scripts/UI/SettingPanel/GraphicsSettingContent.cs
정영민 5c0ab9e2b0 [정영민] External Tools 한글 인코딩 문제 해결
26.03.11
- 설비 알람 인코딩 오류 수정
- 설비 상태 인코딩 오류 수정
- AI 시뮬레이션 결과 인코딩 오류 수정
- 생산 현황판 인코딩 오류 수정
- TopMenu 인코딩 오류 수정
2026-03-12 10:09:05 +09:00

146 lines
6.3 KiB
C#

using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using AZTECHWB.Management;
using AZTECHWB.Extensions;
namespace AZTECHWB.UI
{
public class GraphicsSettingContent : MonoBehaviour
{
private OptionManager optionManager;
private UniversalRenderPipelineAsset urpAsset;
private GraphicsSettingItem ResolutionItem;
private GraphicsSettingItem TextureQualityItem;
private GraphicsSettingItem ShadowQualityItem;
private GraphicsSettingItem AntiAliasingItem;
private GraphicsSettingItem VSyncItem;
private GraphicsSettingItem AnisotropicFilteringItem;
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 = { "끄기", "낮음", "중간", "높음" };
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);
ResolutionItem.InitOptionItem(() => Change(ref resIndex, resolutions.Length, -1), () => Change(ref resIndex, resolutions.Length, +1));
TextureQualityItem.InitOptionItem(() => Change(ref textureIndex, textureNames.Length, -1), () => Change(ref textureIndex, textureNames.Length, +1));
ShadowQualityItem.InitOptionItem(() => Change(ref shadowIndex, shadowNames.Length, -1), () => Change(ref shadowIndex, shadowNames.Length, +1));
AntiAliasingItem.InitOptionItem(() => Change(ref aaIndex, aaValues.Length, -1), () => Change(ref aaIndex, aaValues.Length, +1));
VSyncItem.InitOptionItem(() => ToggleChange(ref vSync), () => ToggleChange(ref vSync));
AnisotropicFilteringItem.InitOptionItem(() => ToggleChange(ref afIndex), () => ToggleChange(ref afIndex));
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 Change(ref int v, int max, int dir)
{
v = Mathf.Clamp(v + dir, 0, max - 1);
RefreshUI();
}
void ToggleChange(ref int v)
{
v = v == 0 ? 1 : 0;
RefreshUI();
}
void RefreshUI()
{
ResolutionItem.SetOptionItem($"{resolutions[resIndex].x} x {resolutions[resIndex].y}");
TextureQualityItem.SetOptionItem(textureNames[textureIndex]);
ShadowQualityItem.SetOptionItem(shadowNames[shadowIndex]);
AntiAliasingItem.SetOptionItem(aaValues[aaIndex] == 0 ? "끄기" : $"MSAA x{aaValues[aaIndex]}");
VSyncItem.SetOptionItem(vSync == 0 ? "끄기" : "켜기");
AnisotropicFilteringItem.SetOptionItem(afIndex == 0 ? "끄기" : "켜기");
}
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
}
}
}