Last active
December 27, 2015 06:25
-
-
Save ZeredaGames/76c9c229e610f98cba1e to your computer and use it in GitHub Desktop.
PlayerPrefsManager custom this is just a base just copy the pattern and add too for your liking.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PlayerPrefsManager.cs | |
// | |
// Author: | |
// ${ZeredaGames-AKA Thamas Bell} <${thamasbell@hotmail.com}> | |
// | |
// Copyright (c) ${2015} ${Thamas Bell} | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in | |
// all copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
// THE SOFTWARE. | |
using UnityEngine; | |
using System.Collections; | |
namespace ZG.Managers.PlayerPrefs | |
{ | |
public class PlayerPrefsManager : MonoBehaviour | |
{ | |
/// <summary> | |
/// The The Master Volume Constant | |
/// </summary> | |
const string MASTER_VOLUME_KEY = "master_volume_"; | |
/// <summary> | |
/// The Master Difficulty Constant. | |
/// </summary> | |
const string MASTER_DIFFICULY_KEY = "DiffLvl"; | |
/// <summary> | |
/// The Master Graphics Constant. | |
/// </summary> | |
const string MASTER_GRAPHICS_KEY = "Graphics Settings:"; | |
/// <summary> | |
/// The Master Camera Constant | |
/// </summary> | |
const string MASTER_CAMERA_KEY = "Camera Settings:"; | |
/// <summary> | |
/// Sets the master graphics. | |
/// </summary> | |
/// <param name="graphValue">Graph value.</param> | |
public static void SetMasterGraphics (float graphValue) | |
{ | |
if (graphValue >= 1f && graphValue <= 6f) { | |
PlayerPrefs.SetFloat (MASTER_GRAPHICS_KEY, graphValue); | |
print ("Setting Quality Setting: = " + PlayerPrefs.GetFloat (MASTER_GRAPHICS_KEY)); | |
print (EnumGraphics.GraphicsStates); | |
print (QualitySettings.currentLevel); | |
} else { | |
Debug.LogError ("<color=red>Graphics out of ranger</color> <i>(Above 1 and below 6)</i>"); | |
} | |
} | |
/// <summary> | |
/// Sets the master camera. | |
/// </summary> | |
/// <param name="camValue">Cam value.</param> | |
public static void SetMasterCamera (float camValue) | |
{ | |
if (camValue >= 1f && camValue <= 4f) { | |
PlayerPrefs.SetFloat (MASTER_CAMERA_KEY, camValue); | |
print ("Setting Camera Setting: = " + PlayerPrefs.GetFloat (MASTER_CAMERA_KEY)); | |
print (EnumCamera.CameraStates); | |
} else { | |
Debug.LogError ("<color=red>Camera out of range</color> <i>(Above 1 and below 4)</i>"); | |
} | |
} | |
/// <summary> | |
/// Sets the difficulty. | |
/// </summary> | |
/// <param name="DiffLvl">Diff lvl.</param> | |
public static void SetMasterDifficulty (float DiffLvl) | |
{ | |
if (DiffLvl >= 1f && DiffLvl <= 4f) { | |
PlayerPrefs.SetFloat (MASTER_DIFFICULY_KEY, DiffLvl); | |
print ("Setting Diffitulty Setting: = " + PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY)); | |
} else { | |
Debug.LogError ("<color=red>Difficulty out of range</color> <i>(Above 1 and below 4)</i>"); | |
} | |
} | |
/// <summary> | |
/// This Must be 0 and 1 or the volume doesnt work correctly | |
/// Sets the master volume. | |
/// </summary> | |
/// <param name="master_volume_">Master_volume_.</param> | |
public static void SetMasterVolume (float master_volume_) | |
{ | |
if (master_volume_ > 0f && master_volume_ < 1f) { | |
PlayerPrefs.SetFloat (MASTER_VOLUME_KEY, master_volume_); | |
print ("Setting Volume Setting: = " + PlayerPrefs.GetFloat (MASTER_VOLUME_KEY)); | |
} else { | |
Debug.LogError ("<color=red>Volume out of Ranger</color> <i>(Above 0 and below 1)</i>"); | |
} | |
} | |
/// <summary> | |
/// Gets the master graphics. | |
/// </summary> | |
/// <returns>The master graphics.</returns> | |
public static float GetMasterGraphics () | |
{ | |
print ("Getting Graphic Setting: = " + PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY)); | |
return PlayerPrefs.GetFloat (MASTER_GRAPHICS_KEY); | |
} | |
/// <summary> | |
/// Gets the master camera. | |
/// </summary> | |
/// <returns>The master camera.</returns> | |
public static float GetMasterCamera () | |
{ | |
print ("Getting Camera Setting: = " + PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY)); | |
return PlayerPrefs.GetFloat (MASTER_CAMERA_KEY); | |
} | |
/// <summary> | |
/// Gets the master volume. | |
/// </summary> | |
/// <returns>The master volume.</returns> | |
public static float GetMasterVolume () | |
{ | |
print ("Getting Volume Setting: = " + PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY)); | |
return PlayerPrefs.GetFloat (MASTER_VOLUME_KEY); | |
} | |
/// <summary> | |
/// Gets the difficulty. | |
/// </summary> | |
/// <returns>The difficulty.</returns> | |
public static float GetMasterDifficulty () | |
{ | |
print ("Getting Difficulty Setting: = " + PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY)); | |
return PlayerPrefs.GetFloat (MASTER_DIFFICULY_KEY); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment