Advertisement
leomovskii

UISettings.cs

Feb 7th, 2022
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Audio;
  5. using UnityEngine.UI;
  6.  
  7. public class UISettings : MonoBehaviour {
  8.  
  9.     public AudioMixer audioMixer;
  10.  
  11.     public Dropdown resolutionsDropdown;
  12.     public Toggle fullScreenToggle;
  13.  
  14.     Vector2Int[] resolutions;
  15.  
  16.     void Start() {
  17.         resolutions = new Vector2Int[3];
  18.         resolutions[0] = new Vector2Int(800, 600);
  19.         resolutions[1] = new Vector2Int(1024, 768);
  20.         resolutions[2] = new Vector2Int(1366, 768);
  21.     }
  22.  
  23.     public void SetResolution(int resolutionIndex) {
  24.         Vector2Int resolution = resolutions[resolutionIndex];
  25.         Screen.SetResolution(resolution.x, resolution.y, Screen.fullScreen);
  26.     }
  27.  
  28.     public void SetVolume(float volume) {
  29.         audioMixer.SetFloat("volume", volume);
  30.     }
  31.  
  32.     public void SetQuality(int qualityIndex) {
  33.         QualitySettings.SetQualityLevel(qualityIndex);
  34.     }
  35.  
  36.     public void SetFullscreen(bool isFullscreen) {
  37.         Screen.fullScreen = isFullscreen;
  38.     }
  39.  
  40.     public void OnExit() {
  41.         #if UNITY_EDITOR
  42.         UnityEditor.EditorApplication.isPlaying = false;
  43.         #else
  44.         Application.Quit();
  45.         #endif
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement