diff options
author | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-12-30 20:59:04 +0800 |
commit | e9ea621b93fbb58d9edfca8375918791637bbd52 (patch) | |
tree | 19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/ResolutionSlider.cs |
+init
Diffstat (limited to 'Client/Assembly-CSharp/ResolutionSlider.cs')
-rw-r--r-- | Client/Assembly-CSharp/ResolutionSlider.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/ResolutionSlider.cs b/Client/Assembly-CSharp/ResolutionSlider.cs new file mode 100644 index 0000000..088854a --- /dev/null +++ b/Client/Assembly-CSharp/ResolutionSlider.cs @@ -0,0 +1,73 @@ +using System; +using System.Linq; +using UnityEngine; + +public class ResolutionSlider : MonoBehaviour +{ + private int targetIdx; + + private Resolution targetResolution; + + private bool targetFullscreen; + + private Resolution[] allResolutions; + + public SlideBar slider; + + public ToggleButtonBehaviour Fullscreen; + + public ToggleButtonBehaviour VSync; + + public TextRenderer Display; + + public void OnEnable() + { + this.allResolutions = (from r in Screen.resolutions + where r.height > 480 + select r).ToArray<Resolution>(); + this.targetResolution = Screen.currentResolution; + this.targetFullscreen = Screen.fullScreen; + this.targetIdx = this.allResolutions.IndexOf((Resolution e) => e.width == this.targetResolution.width && e.height == this.targetResolution.height); + this.slider.Value = (float)this.targetIdx / ((float)this.allResolutions.Length - 1f); + this.Display.Text = string.Format("{0}x{1}", this.targetResolution.width, this.targetResolution.height); + this.Fullscreen.UpdateText(this.targetFullscreen); + this.VSync.UpdateText(QualitySettings.vSyncCount != 0); + } + + public void ToggleVSync() + { + bool flag = QualitySettings.vSyncCount != 0; + if (flag) + { + QualitySettings.vSyncCount = 0; + } + else + { + QualitySettings.vSyncCount = 1; + } + this.VSync.UpdateText(!flag); + } + + public void ToggleFullscreen() + { + this.targetFullscreen = !this.targetFullscreen; + this.Fullscreen.UpdateText(this.targetFullscreen); + } + + public void OnResChange(SlideBar slider) + { + int num = Mathf.RoundToInt((float)(this.allResolutions.Length - 1) * slider.Value); + if (num != this.targetIdx) + { + this.targetIdx = num; + this.targetResolution = this.allResolutions[num]; + this.Display.Text = string.Format("{0}x{1}", this.targetResolution.width, this.targetResolution.height); + } + slider.Value = (float)this.targetIdx / ((float)this.allResolutions.Length - 1f); + } + + public void SaveChange() + { + ResolutionManager.SetResolution(this.targetResolution.width, this.targetResolution.height, this.targetFullscreen); + } +} |