PlayerPrefsManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using UnityEngine;
  2. using System.Collections;
  3. public class PlayerPrefsManager
  4. {
  5. public static void Set(string title, string label, object value)
  6. {
  7. string key = title+"_"+label;
  8. Set(key, value);
  9. }
  10. public static void Set(string title, int id, object value)
  11. {
  12. string key = title+"_"+id;
  13. Set(key, value);
  14. }
  15. public static void Set(string key, object value)
  16. {
  17. if(value.GetType().Equals(typeof(int)))
  18. {
  19. PlayerPrefs.SetInt(key, (int)value);
  20. }
  21. else if(value.GetType().Equals(typeof(float)))
  22. {
  23. PlayerPrefs.SetFloat(key, (float)value);
  24. }
  25. else if(value.GetType().Equals(typeof(string)))
  26. {
  27. PlayerPrefs.SetString(key, (string)value);
  28. }
  29. }
  30. public static int GetInt(string title, string id)
  31. {
  32. string key = title+"_"+id;
  33. return GetInt(key);
  34. }
  35. public static int GetInt(string key)
  36. {
  37. return PlayerPrefs.GetInt(key);
  38. }
  39. public static float GetFloat(string title, string id)
  40. {
  41. string key = title+"_"+id;
  42. return GetFloat(key);
  43. }
  44. public static float GetFloat(string key)
  45. {
  46. return PlayerPrefs.GetFloat(key);
  47. }
  48. public static string GetString(string title, string id)
  49. {
  50. string key = title+"_"+id;
  51. return GetString(key);
  52. }
  53. public static string GetString(string key)
  54. {
  55. return PlayerPrefs.GetString(key);
  56. }
  57. public static bool HasKey(string title, string label)
  58. {
  59. string key = title+"_"+label;
  60. return HasKey(key);
  61. }
  62. public static bool HasKey(string title, int id)
  63. {
  64. string key = title+"_"+id;
  65. return HasKey(key);
  66. }
  67. public static bool HasKey(string key)
  68. {
  69. return PlayerPrefs.HasKey(key);
  70. }
  71. public static void DeleteKey(string key)
  72. {
  73. PlayerPrefs.DeleteKey(key);
  74. }
  75. public static void DeleteAll()
  76. {
  77. PlayerPrefs.DeleteAll();
  78. }
  79. }