设置扩展
This commit is contained in:
@@ -11,6 +11,7 @@ namespace Ichni.Menu
|
||||
public ValueModifier musicVolumeModifier;
|
||||
public ValueModifier sfxVolumeModifier;
|
||||
public ValueModifier uiVolumeModifier;
|
||||
public Switch inGameAudioEffectsSwitch;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Ichni.Menu
|
||||
mainVolumeModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.masterVolume = mainVolumeModifier.GetValue();
|
||||
gameSettings.ApplyVolume();
|
||||
SettingsManager.instance.ApplyAudioSettings();
|
||||
};
|
||||
|
||||
musicVolumeModifier.SetUp(gameSettings.musicVolume, 10, "Menu UI/Settings_Music_Volume");
|
||||
@@ -27,7 +28,7 @@ namespace Ichni.Menu
|
||||
musicVolumeModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.musicVolume = musicVolumeModifier.GetValue();
|
||||
gameSettings.ApplyVolume();
|
||||
SettingsManager.instance.ApplyAudioSettings();
|
||||
};
|
||||
|
||||
sfxVolumeModifier.SetUp(gameSettings.soundEffectVolume, 10, "Menu UI/Settings_SFX_Volume");
|
||||
@@ -35,7 +36,7 @@ namespace Ichni.Menu
|
||||
sfxVolumeModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.soundEffectVolume = sfxVolumeModifier.GetValue();
|
||||
gameSettings.ApplyVolume();
|
||||
SettingsManager.instance.ApplyAudioSettings();
|
||||
};
|
||||
|
||||
uiVolumeModifier.SetUp(gameSettings.uiVolume, 10, "Menu UI/Settings_UI_Volume");
|
||||
@@ -43,7 +44,15 @@ namespace Ichni.Menu
|
||||
uiVolumeModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.uiVolume = uiVolumeModifier.GetValue();
|
||||
gameSettings.ApplyVolume();
|
||||
SettingsManager.instance.ApplyAudioSettings();
|
||||
};
|
||||
|
||||
inGameAudioEffectsSwitch.SetUp(gameSettings.enableInGameAudioEffects,
|
||||
"Menu UI/Settings_InGame_Audio_Effects");
|
||||
inGameAudioEffectsSwitch.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.enableInGameAudioEffects = inGameAudioEffectsSwitch.GetValue();
|
||||
SettingsManager.instance.ApplyInGameAudioEffectsSettings();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -53,6 +62,7 @@ namespace Ichni.Menu
|
||||
musicVolumeModifier.SetValue(gameSettings.musicVolume);
|
||||
sfxVolumeModifier.SetValue(gameSettings.soundEffectVolume);
|
||||
uiVolumeModifier.SetValue(gameSettings.uiVolume);
|
||||
inGameAudioEffectsSwitch.SetValue(gameSettings.enableInGameAudioEffects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Ichni.UI
|
||||
languageDropdown.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.languageIndex = languageDropdown.selectedIndex;
|
||||
gameSettings.ApplyLanguage();
|
||||
SettingsManager.instance.ApplyLanguageSettings();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,4 +34,4 @@ namespace Ichni.UI
|
||||
languageDropdown.SetValue(gameSettings.languageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,70 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Ichni.Menu
|
||||
{
|
||||
public class GraphicsSettingsWindow : SettingsWindow
|
||||
{
|
||||
public ValueModifier resolutionLevelModifier;
|
||||
private static readonly List<string> QualityPresetOptions = new List<string>
|
||||
{
|
||||
"Performant",
|
||||
"Balanced",
|
||||
"High Fidelity"
|
||||
};
|
||||
|
||||
private static readonly List<string> DisplayModeOptions = new List<string>
|
||||
{
|
||||
"Fullscreen",
|
||||
"Borderless Fullscreen",
|
||||
"Windowed"
|
||||
};
|
||||
|
||||
private static readonly List<string> BloomQualityOptions = new List<string>
|
||||
{
|
||||
"Off",
|
||||
"Performance",
|
||||
"Standard"
|
||||
};
|
||||
|
||||
private static readonly List<string> VfxQualityOptions = new List<string>
|
||||
{
|
||||
"Low",
|
||||
"Medium",
|
||||
"High"
|
||||
};
|
||||
|
||||
private readonly List<Vector2Int> _availableDisplayResolutions = new List<Vector2Int>();
|
||||
private readonly List<string> _displayResolutionOptions = new List<string>();
|
||||
|
||||
public Dropdown qualityPresetDropdown;
|
||||
[FormerlySerializedAs("resolutionLevelModifier")]
|
||||
public ValueModifier renderScaleModifier;
|
||||
public ValueModifier targetFrameModifier;
|
||||
public Switch postProcessingSwitch;
|
||||
public Dropdown bloomQualityDropdown;
|
||||
public Dropdown vfxQualityDropdown;
|
||||
public Switch vSyncSwitch;
|
||||
public Dropdown displayModeDropdown;
|
||||
public Dropdown displayResolutionDropdown;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
resolutionLevelModifier.SetUp(gameSettings.resolutionLevel, 1, "Menu UI/Settings_Resolution_Level");
|
||||
resolutionLevelModifier.SetMinMax(0, 5);
|
||||
resolutionLevelModifier.updateValueAction = () =>
|
||||
qualityPresetDropdown.SetUp((int)gameSettings.graphicsQualityPreset, QualityPresetOptions,
|
||||
"Menu UI/Settings_Quality_Preset");
|
||||
qualityPresetDropdown.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.resolutionLevel = resolutionLevelModifier.GetValue();
|
||||
gameSettings.ApplyGraphic();
|
||||
gameSettings.graphicsQualityPreset = (GraphicsQualityPreset)qualityPresetDropdown.selectedIndex;
|
||||
SettingsManager.instance.ApplyGraphicSettings();
|
||||
};
|
||||
|
||||
renderScaleModifier.SetUp(gameSettings.renderScaleLevel, 1, "Menu UI/Settings_Render_Scale");
|
||||
renderScaleModifier.SetMinMax(0, 5);
|
||||
renderScaleModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.renderScaleLevel = renderScaleModifier.GetValue();
|
||||
SettingsManager.instance.ApplyGraphicSettings();
|
||||
};
|
||||
|
||||
targetFrameModifier.SetUp(gameSettings.targetFrame, 30, "Menu UI/Settings_Target_Frame");
|
||||
@@ -25,14 +73,148 @@ namespace Ichni.Menu
|
||||
targetFrameModifier.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.targetFrame = targetFrameModifier.GetValue();
|
||||
gameSettings.ApplyGraphic();
|
||||
SettingsManager.instance.ApplyGraphicSettings();
|
||||
};
|
||||
|
||||
InitializePostProcessingSettings();
|
||||
|
||||
#if UNITY_STANDALONE || UNITY_EDITOR
|
||||
InitializeDesktopDisplaySettings();
|
||||
#else
|
||||
vSyncSwitch.gameObject.SetActive(false);
|
||||
displayModeDropdown.gameObject.SetActive(false);
|
||||
displayResolutionDropdown.gameObject.SetActive(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void SetValuesFromSettings()
|
||||
{
|
||||
resolutionLevelModifier.SetValue(gameSettings.resolutionLevel);
|
||||
qualityPresetDropdown.SetValue((int)gameSettings.graphicsQualityPreset);
|
||||
renderScaleModifier.SetValue(gameSettings.renderScaleLevel);
|
||||
targetFrameModifier.SetValue(gameSettings.targetFrame);
|
||||
|
||||
if (postProcessingSwitch != null)
|
||||
{
|
||||
postProcessingSwitch.SetValue(gameSettings.enablePostProcessing);
|
||||
bloomQualityDropdown.SetValue((int)gameSettings.bloomQuality);
|
||||
vfxQualityDropdown.SetValue((int)gameSettings.vfxQuality);
|
||||
}
|
||||
|
||||
#if UNITY_STANDALONE || UNITY_EDITOR
|
||||
vSyncSwitch.SetValue(gameSettings.vSyncEnabled);
|
||||
displayModeDropdown.SetValue((int)gameSettings.displayMode);
|
||||
displayResolutionDropdown.SetValue(GetDisplayResolutionIndex());
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化后处理、Bloom 与 VFX 档位。
|
||||
/// 三个标题由 Prefab 上的 Unity Localization 组件管理,因此这里保留原有标题显示,不再由脚本写入本地化 Key。
|
||||
/// 在旧 Prefab 尚未布置这些控件前保留兼容分支,避免更新脚本后立即破坏既有设置页。
|
||||
/// </summary>
|
||||
private void InitializePostProcessingSettings()
|
||||
{
|
||||
if (postProcessingSwitch == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
postProcessingSwitch.SetUp(gameSettings.enablePostProcessing, preservePrefabTitle: true);
|
||||
postProcessingSwitch.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.enablePostProcessing = postProcessingSwitch.GetValue();
|
||||
SettingsManager.instance.ApplyPostProcessingSettings();
|
||||
};
|
||||
|
||||
bloomQualityDropdown.SetUp((int)gameSettings.bloomQuality, BloomQualityOptions, preservePrefabTitle: true);
|
||||
bloomQualityDropdown.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.bloomQuality = (BloomQuality)bloomQualityDropdown.selectedIndex;
|
||||
SettingsManager.instance.ApplyPostProcessingSettings();
|
||||
};
|
||||
|
||||
vfxQualityDropdown.SetUp((int)gameSettings.vfxQuality, VfxQualityOptions, preservePrefabTitle: true);
|
||||
vfxQualityDropdown.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.vfxQuality = (VfxQuality)vfxQualityDropdown.selectedIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#if UNITY_STANDALONE || UNITY_EDITOR
|
||||
private void InitializeDesktopDisplaySettings()
|
||||
{
|
||||
BuildDisplayResolutionOptions();
|
||||
|
||||
vSyncSwitch.SetUp(gameSettings.vSyncEnabled, "Menu UI/Settings_VSync");
|
||||
vSyncSwitch.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.vSyncEnabled = vSyncSwitch.GetValue();
|
||||
SettingsManager.instance.ApplyDisplaySettings();
|
||||
};
|
||||
|
||||
displayModeDropdown.SetUp((int)gameSettings.displayMode, DisplayModeOptions,
|
||||
"Menu UI/Settings_Display_Mode");
|
||||
displayModeDropdown.updateValueAction = () =>
|
||||
{
|
||||
gameSettings.displayMode = (GraphicsDisplayMode)displayModeDropdown.selectedIndex;
|
||||
SettingsManager.instance.ApplyDisplaySettings();
|
||||
};
|
||||
|
||||
displayResolutionDropdown.SetUp(GetDisplayResolutionIndex(), _displayResolutionOptions,
|
||||
"Menu UI/Settings_Display_Resolution");
|
||||
displayResolutionDropdown.updateValueAction = () =>
|
||||
{
|
||||
Vector2Int resolution = _availableDisplayResolutions[displayResolutionDropdown.selectedIndex];
|
||||
gameSettings.displayResolutionWidth = resolution.x;
|
||||
gameSettings.displayResolutionHeight = resolution.y;
|
||||
SettingsManager.instance.ApplyDisplaySettings();
|
||||
};
|
||||
}
|
||||
|
||||
private void BuildDisplayResolutionOptions()
|
||||
{
|
||||
_availableDisplayResolutions.Clear();
|
||||
_displayResolutionOptions.Clear();
|
||||
|
||||
AddDisplayResolution(Screen.width, Screen.height);
|
||||
foreach (Resolution resolution in Screen.resolutions)
|
||||
{
|
||||
AddDisplayResolution(resolution.width, resolution.height);
|
||||
}
|
||||
|
||||
_availableDisplayResolutions.Sort((left, right) =>
|
||||
{
|
||||
int pixelCountComparison = (left.x * left.y).CompareTo(right.x * right.y);
|
||||
return pixelCountComparison != 0 ? pixelCountComparison : left.x.CompareTo(right.x);
|
||||
});
|
||||
|
||||
foreach (Vector2Int resolution in _availableDisplayResolutions)
|
||||
{
|
||||
_displayResolutionOptions.Add($"{resolution.x} x {resolution.y}");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddDisplayResolution(int width, int height)
|
||||
{
|
||||
Vector2Int resolution = new Vector2Int(width, height);
|
||||
if (!_availableDisplayResolutions.Contains(resolution))
|
||||
{
|
||||
_availableDisplayResolutions.Add(resolution);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetDisplayResolutionIndex()
|
||||
{
|
||||
Vector2Int savedResolution = new Vector2Int(gameSettings.displayResolutionWidth,
|
||||
gameSettings.displayResolutionHeight);
|
||||
int savedResolutionIndex = _availableDisplayResolutions.IndexOf(savedResolution);
|
||||
if (savedResolutionIndex >= 0)
|
||||
{
|
||||
return savedResolutionIndex;
|
||||
}
|
||||
|
||||
return _availableDisplayResolutions.IndexOf(new Vector2Int(Screen.width, Screen.height));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Ichni.Menu
|
||||
offsetModifier.SetPrefixAndSuffix("", " ms", true);
|
||||
offsetModifier.updateValueAction = () =>
|
||||
{
|
||||
offset = SettingsManager.instance.gameSettings.beatmapOffset = offsetModifier.GetValue();
|
||||
offset = SettingsManager.instance.settingsSaveData.beatmapOffset = offsetModifier.GetValue();
|
||||
largeOffsetHintText.gameObject.SetActive(Mathf.Abs(offset) > 50);
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Ichni.Menu
|
||||
(uint)AkCallbackType.AK_EnableGetMusicPlayPosition | (uint)AkCallbackType.AK_MusicSyncEntry,
|
||||
OnMusicEvent, null);
|
||||
|
||||
offsetModifier.SetValue(SettingsManager.instance.gameSettings.beatmapOffset);
|
||||
offsetModifier.SetValue(SettingsManager.instance.settingsSaveData.beatmapOffset);
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -141,4 +141,4 @@ namespace Ichni.Menu
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Ichni.Menu
|
||||
{
|
||||
public class SettingsUIPage : UIPageBase
|
||||
{
|
||||
GameSettings gameSettings => SettingsManager.instance.gameSettings;
|
||||
SettingsSaveData gameSettings => SettingsManager.instance.settingsSaveData;
|
||||
|
||||
public Button backButton;
|
||||
public SettingsWindowController settingsWindowController;
|
||||
@@ -23,4 +23,4 @@ namespace Ichni.Menu
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Ichni.Menu
|
||||
{
|
||||
public abstract class SettingsWindow : SerializedMonoBehaviour
|
||||
{
|
||||
public GameSettings gameSettings => SettingsManager.instance.gameSettings;
|
||||
public SettingsSaveData gameSettings => SettingsManager.instance.settingsSaveData;
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
@@ -18,4 +18,4 @@ namespace Ichni.Menu
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Ichni.Menu
|
||||
{
|
||||
public partial class SettingsWindowController : MonoBehaviour
|
||||
{
|
||||
public GameSettings gameSettings => SettingsManager.instance.gameSettings;
|
||||
public SettingsSaveData gameSettings => SettingsManager.instance.settingsSaveData;
|
||||
|
||||
public CanvasGroup canvasGroup;
|
||||
|
||||
@@ -70,4 +70,4 @@ namespace Ichni.Menu
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user