243 lines
6.4 KiB
C#
243 lines
6.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Rendering.PostProcessing;
|
|
using UnityEditor;
|
|
|
|
public class settings : MonoBehaviour
|
|
{
|
|
public AudioSource audSrc;
|
|
public GameObject[] settingsSections;
|
|
public Button[] settingsSectionsBtns;
|
|
public AudioClip settingsSectionSelectedSFX;
|
|
public AudioClip settingsChangedSFX;
|
|
public AudioClip onHoverSfx;
|
|
|
|
[Header("Graphics")]
|
|
public Toggle vsync;
|
|
public Dropdown shadows;
|
|
public Dropdown aa;
|
|
public Dropdown pp;
|
|
public Dropdown particles;
|
|
public Dropdown textureQ;
|
|
public Dropdown lightningQ;
|
|
|
|
|
|
public void show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
|
|
void Start()
|
|
{
|
|
DontDestroyOnLoad(gameObject);
|
|
SettingPage.instance = this;
|
|
vsync.onValueChanged.AddListener((bool b) => {
|
|
PlayerPrefs.SetInt("vsync", (b) ? 1 : 0);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
shadows.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("shadows", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
aa.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("aa", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
pp.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("pp", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
particles.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("particles", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
textureQ.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("textureQ", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
lightningQ.onValueChanged.AddListener((int option) =>
|
|
{
|
|
PlayerPrefs.SetInt("lightningQ", option);
|
|
PlayerPrefs.Save();
|
|
playSettingsChangedSFX();
|
|
reloadGraphicSettings();
|
|
});
|
|
|
|
reloadGraphicSettings();
|
|
|
|
if (settingsSections.Length != settingsSectionsBtns.Length) { Debug.LogError("IMBALANCED SETTINGS CONFIG!"); }
|
|
else
|
|
{
|
|
for (int i = 0; i < settingsSectionsBtns.Length; i++)
|
|
{
|
|
int x = i;
|
|
settingsSectionsBtns[x].onClick.AddListener(() => { onSettingsSectionClick(x); });
|
|
}
|
|
}
|
|
onSettingsSectionClick(0);
|
|
}
|
|
|
|
|
|
void onSettingsSectionClick(int i)
|
|
{
|
|
Debug.Log("Selected " + i + " button");
|
|
for (int x = 0; x < settingsSectionsBtns.Length; x++)
|
|
{
|
|
settingsSectionsBtns[x].interactable = (x != i);
|
|
settingsSections[x].SetActive((x == i));
|
|
}
|
|
reloadGraphicSettings();
|
|
audSrc.PlayOneShot(settingsSectionSelectedSFX);
|
|
}
|
|
|
|
void playSettingsChangedSFX()
|
|
{
|
|
audSrc.PlayOneShot(settingsChangedSFX);
|
|
}
|
|
|
|
public void OnHoverSFX()
|
|
{
|
|
audSrc.PlayOneShot(onHoverSfx);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
{
|
|
hide();
|
|
}
|
|
}
|
|
|
|
|
|
public void reloadGraphicSettings()
|
|
{
|
|
//Read all settings from prefs
|
|
vsync.isOn = PlayerPrefs.GetInt("vsync") == 1;
|
|
shadows.value = PlayerPrefs.GetInt("shadows");
|
|
aa.value = PlayerPrefs.GetInt("aa");
|
|
pp.value = PlayerPrefs.GetInt("pp");
|
|
particles.value = PlayerPrefs.GetInt("particles");
|
|
textureQ.value = PlayerPrefs.GetInt("textureQ");
|
|
lightningQ.value = PlayerPrefs.GetInt("lightningQ");
|
|
|
|
//APPLY EACH
|
|
QualitySettings.vSyncCount = PlayerPrefs.GetInt("vsync");
|
|
QualitySettings.softParticles = pp.value == 1;
|
|
|
|
switch (shadows.value)
|
|
{
|
|
case 0:
|
|
QualitySettings.shadows = ShadowQuality.All;
|
|
QualitySettings.shadowResolution = ShadowResolution.VeryHigh;
|
|
break;
|
|
|
|
case 1:
|
|
QualitySettings.shadows = ShadowQuality.All;
|
|
QualitySettings.shadowResolution = ShadowResolution.High;
|
|
break;
|
|
|
|
case 2:
|
|
QualitySettings.shadows = ShadowQuality.HardOnly;
|
|
QualitySettings.shadowResolution = ShadowResolution.Medium;
|
|
break;
|
|
|
|
case 3:
|
|
QualitySettings.shadows = ShadowQuality.HardOnly;
|
|
QualitySettings.shadowResolution = ShadowResolution.Low;
|
|
break;
|
|
|
|
case 4:
|
|
QualitySettings.shadows = ShadowQuality.Disable;
|
|
break;
|
|
}
|
|
|
|
switch (aa.value)
|
|
{
|
|
case 0:
|
|
QualitySettings.antiAliasing = 0;
|
|
break;
|
|
|
|
case 1:
|
|
QualitySettings.antiAliasing = 2;
|
|
break;
|
|
|
|
case 2:
|
|
QualitySettings.antiAliasing = 4;
|
|
break;
|
|
|
|
case 3:
|
|
QualitySettings.antiAliasing = 8;
|
|
break;
|
|
}
|
|
|
|
PostProcessVolume[] volumes = FindObjectsOfType<PostProcessVolume>();
|
|
switch (pp.value)
|
|
{
|
|
|
|
case 0:
|
|
foreach (PostProcessVolume vol in volumes)
|
|
{
|
|
vol.enabled = true;
|
|
}
|
|
break;
|
|
|
|
case 3:
|
|
foreach(PostProcessVolume vol in volumes)
|
|
{
|
|
vol.enabled = false;
|
|
}
|
|
break;
|
|
}
|
|
|
|
QualitySettings.masterTextureLimit = textureQ.value;
|
|
|
|
switch (lightningQ.value)
|
|
{
|
|
case 0:
|
|
// PlayerSettings.colorSpace = ColorSpace.Linear;
|
|
break;
|
|
|
|
case 1:
|
|
// PlayerSettings.colorSpace = ColorSpace.Gamma;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static class SettingPage
|
|
{
|
|
public static settings instance;
|
|
} |