This commit is contained in:
2025-10-09 07:51:05 +08:00
parent 3ea4257e2d
commit 2aeeaf7659
24 changed files with 3460 additions and 3026 deletions

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : Singleton<AudioManager>
{
public void Init()
{
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b16c03c5d0a387641a3c978840f52037
guid: 0ea56a12bf5c53a4785e752b3a7c00b9
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -6,22 +6,21 @@ public class AudioPanel : UIBasePanel, ISettingsPanel
{
[SerializeField] private Slider masterVolumeSlider;
[SerializeField] private AudioMixer audioMixer;
float masterVolume;
public override void OnShow()
{
masterVolume = masterVolumeSlider.value = SettingsManager.Inst.CurrentSettings.masterVolume;
masterVolumeSlider.value = SettingsManager.Inst.CurrentSettings.masterVolume;
if (audioMixer == null) audioMixer = FindAnyObjectByType<AudioMixer>();
}
public void OnMasterVolumeChanged(float value)
{
masterVolume = value;
SettingsManager.Inst.CurrentSettings.masterVolume = value;
SetVolume(value);
}
public void ApplySettings()
{
SettingsManager.Inst.CurrentSettings.masterVolume = masterVolume;
}
private void SetVolume(float volume)
@@ -32,6 +31,6 @@ public class AudioPanel : UIBasePanel, ISettingsPanel
public void ResetToDefault()
{
SettingsManager.Inst.CurrentSettings.masterVolume = masterVolume = SettingsManager.Inst.DefSetting.masterVolume;
SettingsManager.Inst.CurrentSettings.masterVolume = SettingsManager.Inst.DefSetting.masterVolume;
}
}

View File

@@ -1,141 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using TMPro;
using System.Collections;
public class DisplayPanel : UIBasePanel, ISettingsPanel
{
[Header("UI References")]
[SerializeField] private TMP_Dropdown resolutionDropdown;
[SerializeField] private Toggle fullscreenToggle;
[SerializeField] private Toggle borderlessToggle;
[SerializeField] private TMP_Dropdown displayDropdown;
private Resolution[] resolutions;
private void Awake()
{
InitializeResolutionDropdown();
InitializeDisplayDropdown();
}
private void OnEnable()
{
StartCoroutine(InitializeDelayed());
}
IEnumerator InitializeDelayed()
{
yield return null;
var settings = SettingsManager.Inst.CurrentSettings;
resolutionDropdown.SetValueWithoutNotify(settings.resolutionIndex);
fullscreenToggle.SetIsOnWithoutNotify(settings.fullscreen);
borderlessToggle.SetIsOnWithoutNotify(settings.borderless);
displayDropdown.SetValueWithoutNotify(settings.displayIndex);
UpdateBorderlessToggleState();
}
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);
}
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);
}
public void OnResolutionChanged(int index)
{
SettingsManager.Inst.CurrentSettings.resolutionIndex = index;
ApplySetResolution();
}
public void OnFullscreenChanged(bool value)
{
SettingsManager.Inst.CurrentSettings.fullscreen = value;
UpdateBorderlessToggleState();
ApplySetResolution();
}
public void OnBorderlessChanged(bool value)
{
SettingsManager.Inst.CurrentSettings.borderless = value;
ApplySetResolution();
}
public void OnDisplayChanged(int index)
{
SettingsManager.Inst.CurrentSettings.displayIndex = index;
ApplySetDisplay();
}
private void UpdateBorderlessToggleState()
{
borderlessToggle.interactable = fullscreenToggle.isOn;
if (!fullscreenToggle.isOn)
borderlessToggle.isOn = false;
ApplySetResolution();
}
public void ApplySettings()
{
ApplySetResolution();
ApplySetDisplay();
}
void ApplySetResolution()
{
if (resolutions == null) return;
var settings = SettingsManager.Inst.CurrentSettings;
Resolution res = resolutions[resolutions.Length-1];
if (settings.resolutionIndex < resolutions.Length && settings.resolutionIndex>=0)
{
res = resolutions[settings.resolutionIndex];
}
FullScreenMode mode = settings.borderless ?
FullScreenMode.FullScreenWindow :
(settings.fullscreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed);
Screen.SetResolution(
res.width,
res.height,
mode,
res.refreshRateRatio
);
}
void ApplySetDisplay()
{
var settings = SettingsManager.Inst.CurrentSettings;
if (settings.displayIndex > 0 && settings.displayIndex < Display.displays.Length)
{
Display.displays[settings.displayIndex].Activate();
}
}
public void ResetToDefault()
{
throw new System.NotImplementedException();
}
}

View File

@@ -5,22 +5,21 @@ using UnityEngine.UI;
public class GeneralPanel : UIBasePanel,ISettingsPanel
{
[SerializeField] private TMP_InputField serverAddressInput;
string serverAddress;
public override void OnShow()
{
serverAddressInput.text = SettingsManager.Inst.CurrentSettings.serverAddress;
}
public void OnServerAddressChanged(string value)
{
serverAddress = value;
SettingsManager.Inst.CurrentSettings.serverAddress = value;
}
public void ApplySettings()
{
SettingsManager.Inst.CurrentSettings.serverAddress = serverAddress;
}
public void ResetToDefault()
{
SettingsManager.Inst.CurrentSettings.serverAddress = serverAddress = SettingsManager.Inst.DefSetting.serverAddress;
SettingsManager.Inst.CurrentSettings.serverAddress = SettingsManager.Inst.DefSetting.serverAddress;
}
}

View File

@@ -8,10 +8,9 @@ using YooAsset;
public class GraphicsManager : Singleton<GraphicsManager>
{
public GraphicsSetting graphicsSetting;
private UniversalRenderPipelineAsset _urpAsset;
private VolumeProfile urpVolumeProfile;
public GraphicsManager()
public void Init()
{
_urpAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
@@ -24,17 +23,50 @@ public class GraphicsManager : Singleton<GraphicsManager>
{
Debug.LogError("VolumeProfile null");
}
graphicsSetting = SettingsManager.Inst.CurrentSettings.graphicsSettings;
ApplySettings();
}
public void ApplySettings()
{
SettingsManager.Inst.CurrentSettings.graphicsSettings = graphicsSetting;
GraphicsSetting graphicsSetting = SettingsManager.Inst.CurrentSettings.graphicsSettings;
SettingsManager.Inst.SaveSettings();
ApplySetURPAsset(graphicsSetting);
ApplySetResolution(graphicsSetting);
ApplySetDisplay(graphicsSetting);
}
void ApplySetURPAsset(GraphicsSetting graphicsSetting)
{
QualitySettings.vSyncCount = graphicsSetting.vsyncEnabled ? 1 : 0;
_urpAsset.shadowDistance = graphicsSetting.shadowDistance;
_urpAsset.msaaSampleCount = (int)Mathf.Pow(2, graphicsSetting.qualityLevel);
_urpAsset.renderScale = graphicsSetting.renderScale;
}
void ApplySetResolution(GraphicsSetting graphicsSetting)
{
if (Screen.resolutions == null) return;
Resolution res = Screen.resolutions[Screen.resolutions.Length - 1];
if (graphicsSetting.resolutionIndex < Screen.resolutions.Length && graphicsSetting.resolutionIndex >= 0)
{
res = Screen.resolutions[graphicsSetting.resolutionIndex];
}
FullScreenMode mode = graphicsSetting.borderless ?
FullScreenMode.FullScreenWindow :
(graphicsSetting.fullscreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed);
Screen.SetResolution(
res.width,
res.height,
mode,
res.refreshRateRatio
);
}
void ApplySetDisplay(GraphicsSetting graphicsSetting)
{
if (graphicsSetting.displayIndex > 0 && graphicsSetting.displayIndex < Display.displays.Length)
{
Display.displays[graphicsSetting.displayIndex].Activate();
}
}
}
[System.Serializable]
public class GraphicsSetting
@@ -47,6 +79,11 @@ public class GraphicsSetting
public float renderScale = 1.0f;
public bool isCustom = false;
public int resolutionIndex = 0;
public bool fullscreen = true;
public bool borderless = false;
public int displayIndex = 0;
public GraphicsSetting() { }
public GraphicsSetting(int quality, bool vsync, float shadows, int aa, bool bloom, float scale)

View File

@@ -4,6 +4,7 @@ using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using TMPro;
using System.Collections;
using System.Collections.Generic;
public class GraphicsPanel : UIBasePanel, ISettingsPanel
{
@@ -15,55 +16,128 @@ public class GraphicsPanel : UIBasePanel, ISettingsPanel
[SerializeField] private Toggle bloomToggle;
[SerializeField] private Slider renderScaleSlider;
[SerializeField] private TMP_Dropdown resolutionDropdown;
[SerializeField] private Toggle fullscreenToggle;
[SerializeField] private Toggle borderlessToggle;
[SerializeField] private TMP_Dropdown displayDropdown;
private Resolution[] resolutions;
bool init = false;
public override void OnShow()
{
var settings = SettingsManager.Inst.CurrentSettings;
var settings =SettingsManager.Inst.CurrentSettings;
if (!init)
{
InitializeResolutionDropdown();
InitializeDisplayDropdown();
}
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);
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);
}
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);
}
public void OnQualityChanged(int index)
{
GameSystem.Inst.Graphics.graphicsSetting.qualityLevel = index;
SettingsManager.Inst.CurrentSettings.graphicsSettings.qualityLevel = index;
}
public void OnVSyncChanged(bool value)
{
GameSystem.Inst.Graphics.graphicsSetting.vsyncEnabled = value;
SettingsManager.Inst.CurrentSettings.graphicsSettings.vsyncEnabled = value;
}
public void OnShadowDistanceChanged(float value)
{
GameSystem.Inst.Graphics.graphicsSetting.shadowDistance = value;
SettingsManager.Inst.CurrentSettings.graphicsSettings.shadowDistance = value;
}
public void OnAntiAliasingChanged(int index)
{
GameSystem.Inst.Graphics.graphicsSetting.antiAliasing = index;
SettingsManager.Inst.CurrentSettings.graphicsSettings.antiAliasing = index;
}
public void OnBloomChanged(bool value)
{
GameSystem.Inst.Graphics.graphicsSetting.bloomEnabled = value;
SettingsManager.Inst.CurrentSettings.graphicsSettings.bloomEnabled = value;
}
public void OnRenderScaleChanged(float value)
{
GameSystem.Inst.Graphics.graphicsSetting.renderScale = value;
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;
}
public void ApplySettings()
{
GameSystem.Inst.Graphics.ApplySettings();
GraphicsManager.Inst.ApplySettings();
}
public void ResetToDefault()
{
throw new System.NotImplementedException();
SettingsManager.Inst.CurrentSettings.graphicsSettings = SettingsManager.Inst.DefSetting.graphicsSettings;
}
}

View File

@@ -2,6 +2,7 @@ using UnityEngine;
using System.IO;
using YooAsset;
using System;
using System.Drawing.Printing;
public class SettingsManager: Singleton<SettingsManager>
{
@@ -9,7 +10,7 @@ public class SettingsManager: Singleton<SettingsManager>
public GameSettings CurrentSettings => _currentSettings;
public GameSettings DefSetting = new GameSettings();
private string settingsPath;
public SettingsManager()
public void Init()
{
settingsPath = Path.Combine(Application.persistentDataPath, "settings.json");
LoadSettings();
@@ -34,16 +35,16 @@ public class SettingsManager: Singleton<SettingsManager>
string json = JsonUtility.ToJson(_currentSettings, true);
File.WriteAllText(settingsPath, json);
}
#region
#endregion
#region
#endregion
public void ResetToDefaultSettings()
{
_currentSettings = DefSetting;
SaveSettings();
}
public void ApplyAllSettings()
{
GraphicsManager.Inst.ApplySettings();
SaveSettings();
}
}
[System.Serializable]
@@ -53,18 +54,7 @@ public class GameSettings
public float masterVolume = 0.75f;
//public int qualityLevel = 2;
//public bool vsyncEnabled = true;
//public float shadowDistance = 50f;
//public int antiAliasing = 2;
//public bool bloomEnabled = true;
//public float renderScale = 1.0f;
public GraphicsSetting graphicsSettings;
public int resolutionIndex = 0;
public bool fullscreen = true;
public bool borderless = false;
public int displayIndex = 0;
}
public interface ISettingsPanel
{

View File

@@ -7,13 +7,11 @@ public class SettingsWindow : UIBaseWindow
public GeneralPanel generalPanel;
public AudioPanel audioPanel;
public GraphicsPanel graphicsPanel;
public DisplayPanel displayPanel;
[Header("Tab Buttons")]
public Button generalTab;
public Button audioTab;
public Button graphicsTab;
public Button displayTab;
[Header("Action Buttons")]
public Button applyButton;
@@ -31,7 +29,6 @@ public class SettingsWindow : UIBaseWindow
generalTab.onClick.AddListener(() => SwitchPanel(generalPanel));
audioTab.onClick.AddListener(() => SwitchPanel(audioPanel));
graphicsTab.onClick.AddListener(() => SwitchPanel(graphicsPanel));
displayTab.onClick.AddListener(() => SwitchPanel(displayPanel));
applyButton.onClick.AddListener(ApplyAllSettings);
cancelButton.onClick.AddListener(() => { UIManager.Inst.HideWindow(nameof(SettingsWindow)); });
@@ -45,9 +42,10 @@ public class SettingsWindow : UIBaseWindow
private void SwitchPanel(UIBasePanel newPanel)
{
if (currentPanel != null)
currentPanel.gameObject.SetActive(false);
newPanel.gameObject.SetActive(true);
{
currentPanel.Hide();
}
newPanel.Show();
currentPanel = newPanel;
UpdateTabButtons();
}
@@ -57,21 +55,11 @@ public class SettingsWindow : UIBaseWindow
generalTab.interactable = currentPanel != generalPanel;
audioTab.interactable = currentPanel != audioPanel;
graphicsTab.interactable = currentPanel != graphicsPanel;
displayTab.interactable = currentPanel != displayPanel;
}
public void ApplyAllSettings()
{
generalPanel.ApplySettings();
displayPanel.ApplySettings();
graphicsPanel.ApplySettings();
audioPanel.ApplySettings();
SettingsManager.Inst.SaveSettings();
SettingsManager.Inst.ApplyAllSettings();
UIManager.Inst.HideWindow(nameof(SettingsWindow));
}