PlayerPrefManager.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerPrefManager
  5. {
  6. public const string INTERACT_CONFIG = "Interact_Config";
  7. public const string PLAYER_CONFIG = "Player_Config";
  8. public static bool GetBool(string label, bool defaultValue)
  9. {
  10. int i = PlayerPrefs.GetInt(label, -1);
  11. if (i == -1)
  12. {
  13. return defaultValue;
  14. }
  15. if (i == 0)
  16. {
  17. return false;
  18. }
  19. else
  20. {
  21. return true;
  22. }
  23. }
  24. public static void SaveBool(string label, bool value)
  25. {
  26. if (value)
  27. {
  28. PlayerPrefs.SetInt(label, 1);
  29. }
  30. else
  31. {
  32. PlayerPrefs.SetInt(label, 0);
  33. }
  34. PlayerPrefs.Save();
  35. }
  36. public static string GetStr(string label, string defaultValue)
  37. {
  38. string str = PlayerPrefs.GetString(label, "null");
  39. if (str == "null")
  40. {
  41. return defaultValue;
  42. }
  43. return str;
  44. }
  45. public static void SaveStr(string label, string value)
  46. {
  47. PlayerPrefs.SetString(label, value);
  48. PlayerPrefs.Save();
  49. }
  50. }