ClientPrefs.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using UnityEngine;
  2. //客户端本地信息保存。通过PlayerPrefs来保存本地信息
  3. public static class ClientPrefs
  4. {
  5. const string MasterVolumeKey = "MasterVolume";
  6. const string MusicVolumeKey = "MusicVolume";
  7. const string ClientGUIDKey = "client_guid";
  8. const string AvailableProfilesKey = "AvailableProfiles";
  9. const float DefaultMasterVolume = 0.5f;
  10. const float DefaultMusicVolume = 0.8f;
  11. public static float GetMasterVolume()
  12. {
  13. return PlayerPrefs.GetFloat(MasterVolumeKey, DefaultMasterVolume);
  14. }
  15. public static void SetMasterVolume(float volume)
  16. {
  17. PlayerPrefs.SetFloat(MasterVolumeKey, volume);
  18. }
  19. public static float GetMusicVolume()
  20. {
  21. return PlayerPrefs.GetFloat(MusicVolumeKey, DefaultMusicVolume);
  22. }
  23. public static void SetMusicVolume(float volume)
  24. {
  25. PlayerPrefs.SetFloat(MusicVolumeKey, volume);
  26. }
  27. //客户端Guid
  28. public static string GetGuid(bool isNew)
  29. {
  30. if(isNew)
  31. {
  32. //没有则重新生成
  33. return System.Guid.NewGuid().ToString();
  34. }
  35. //缓存中有,返回
  36. if(PlayerPrefs.HasKey(ClientGUIDKey))
  37. {
  38. return PlayerPrefs.GetString(ClientGUIDKey);
  39. }
  40. //没有则重新生成
  41. var guidString = System.Guid.NewGuid().ToString();
  42. PlayerPrefs.SetString(ClientGUIDKey, guidString);
  43. return guidString;
  44. }
  45. public static string GetAvailableProfiles()
  46. {
  47. return PlayerPrefs.GetString(AvailableProfilesKey, "");
  48. }
  49. public static void SetAvailableProfiles(string availableProfiles)
  50. {
  51. PlayerPrefs.SetString(AvailableProfilesKey, availableProfiles);
  52. }
  53. }