Skip to content

Instantly share code, notes, and snippets.

@nipundavid
Created December 14, 2016 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nipundavid/0c314dfe9f2c89c52bc138b04fdfcfaa to your computer and use it in GitHub Desktop.
Save nipundavid/0c314dfe9f2c89c52bc138b04fdfcfaa to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
/// <summary>
/// Quality setting manager.
/// To change the quality of graphics at runtime which will
/// increase quality and power consumption and may decrease framerate vice versa
/// </summary>
public class QualitySettingManager : MonoBehaviour {
private string CURRENT_QUALITY_LEVEL = "CURRENT_QUALITY_LEVEL";
private enum QUALITY_LEVEL
{
HIGH,
MEDIUM,
LOW
};
private QUALITY_LEVEL qualityLevel;
#region MonoBehaviour methods
// Use this for initialization
void Start () {
qualityLevel = (QUALITY_LEVEL)PlayerPrefs.GetInt (CURRENT_QUALITY_LEVEL);
switch (qualityLevel) {
case QUALITY_LEVEL.HIGH:
setHighQuality ();
break;
case QUALITY_LEVEL.MEDIUM:
setMediumQuality ();
break;
case QUALITY_LEVEL.LOW:
setLowQuality ();
break;
default:
break;
}
}
// Update is called once per frame
void Update () {
}
#endregion
#region public methods
/// <summary>
/// Sets the high quality. max power use, low frame rate
/// </summary>
public void setHighQuality() {
Application.targetFrameRate = 60;
QualitySettings.vSyncCount = 0;
QualitySettings.antiAliasing = 4;
QualitySettings.shadowCascades = 2;
QualitySettings.shadowDistance = 1000;
PlayerPrefs.SetInt (CURRENT_QUALITY_LEVEL,(int)QUALITY_LEVEL.HIGH);
Debug.Log ("Current Quality Settings : High");
}
/// <summary>
/// Sets the medium quality. optimal power use, ave frame rate
/// </summary>
public void setMediumQuality() {
Application.targetFrameRate = 50;
QualitySettings.vSyncCount = 0;
QualitySettings.antiAliasing = 2;
QualitySettings.shadowCascades = 1;
QualitySettings.shadowDistance = 500;
PlayerPrefs.SetInt (CURRENT_QUALITY_LEVEL,(int)QUALITY_LEVEL.MEDIUM);
Debug.Log ("Current Quality Settings : Medium");
}
/// <summary>
/// Sets the low quality. low power use, high frame rate
/// </summary>
public void setLowQuality() {
Application.targetFrameRate = 40;
QualitySettings.vSyncCount = 0;
QualitySettings.antiAliasing = 0;
QualitySettings.shadowCascades = 0;
QualitySettings.shadowDistance = 200;
PlayerPrefs.SetInt (CURRENT_QUALITY_LEVEL,(int)QUALITY_LEVEL.LOW);
Debug.Log ("Current Quality Settings : Low");
}
public void enableShadow(bool arg) {
if (arg) {
switch (qualityLevel) {
case QUALITY_LEVEL.HIGH:
QualitySettings.shadowDistance = 1000;
break;
case QUALITY_LEVEL.MEDIUM:
QualitySettings.shadowDistance = 500;
break;
case QUALITY_LEVEL.LOW:
QualitySettings.shadowDistance = 200;
break;
default:
break;
}
} else {
QualitySettings.shadowDistance = 0;
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment