Graphics Reference
In-Depth Information
void SaveOptionsPrefs()
{
PlayerPrefs.SetFloat(gamePrefsName+"_SFXVol",
audioSFXSliderValue);
PlayerPrefs.SetFloat(gamePrefsName+"_MusicVol",
audioMusicSliderValue);
PlayerPrefs.SetFloat(gamePrefsName+"_GraphicsDetail",
graphicsSliderValue);
// set the quality setting
QualitySettings.SetQualityLevel( (int)graphicsSliderValue, true);
}
PlayerPrefs is used to save our settings to disk. he example games in this topic use
an optional string variable called gamePrefsName to attach a prefix to the PlayerPrefs
key names so that our preferences will be saved individually for each game. This is com-
pletely optional—Unity saves preferences on a per-game basis, so your preferences will
never be shared across projects. In this case, as all of the game examples in this topic
are saved into a single Unity project, the prefix ensures that each game will save its set-
tings individually despite them all being lumped into the same project preferences file.
QualitySettings.SetQualityLevel is used to set Unity's quality level. SetQualityLevel
takes an integer index number with its second parameter being a Boolean value to set
whether or not expensive changes should be applied. These are settings that may cause the
game to stall. It may not always be a good idea to cause stalling (e.g., where SetQualityLevel
is used for real-time dynamic quality switching based on frame rate), but in this case,
it will have no noticeable impact for the player, so we can go ahead and apply all settings
here.
10.2 In-Game User Interface
he user interface used for the games in this topic is extremely basic but entirely func-
tional. Each script derives from a class called BaseUIDataManager, which declares several
common variables and provides some basic functions to deal with them. Those are
player_score
The player's score
player_lives
The amount of health or lives that the player has
player_highscore
The highest score achieved in the game so far
gamePrefsName
A string to prefix all PlayerPrefs references (see the earlier section in this
chapter for a more in-depth discussion on how PlayerPrefs is used)
The BaseUIDataManager.cs script looks like this:
using UnityEngine;
using System.Collections;
public class BaseUIDataManager : MonoBehavior
{
// the actual UI drawing is done by a script deriving from this one
public int player_score;
public int player_lives;
Search WWH ::




Custom Search