Advertisement
Guest User

Simple Unity3D Persistent SETTINGS

a guest
Aug 5th, 2020
3,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. // by @kurtdekker - handy example of simple persistent settings.
  6. //
  7. // To use, just use the variables like any other:
  8. //
  9. //  SETTINGS.VolumeLevel = 1.0f;
  10. //
  11. //  if (SETTINGS.EnableTurboMode)
  12. //  {
  13. //      // Do turbo-mode stuff
  14. //  }
  15. //
  16.  
  17. public static class SETTINGS
  18. {
  19.     private static string s_VolumeLevel = "VolumeLevel";
  20.     public static float VolumeLevel
  21.     {
  22.         get
  23.         {
  24.             return PlayerPrefs.GetFloat(s_VolumeLevel, 1);
  25.         }
  26.         set
  27.         {
  28.             PlayerPrefs.SetFloat(s_VolumeLevel, value);
  29.         }
  30.     }
  31.  
  32.     private static string s_EnableTurboMode = "EnableTurboMode";
  33.     public static bool EnableTurboMode
  34.     {
  35.         get
  36.         {
  37.             return PlayerPrefs.GetInt(s_EnableTurboMode, 1) != 0;
  38.         }
  39.         set
  40.         {
  41.             PlayerPrefs.SetInt(s_EnableTurboMode, value ? 1 : 0);
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement