using UnityEngine; //客户端本地信息保存。通过PlayerPrefs来保存本地信息 public static class ClientPrefs { const string MasterVolumeKey = "MasterVolume"; const string MusicVolumeKey = "MusicVolume"; const string ClientGUIDKey = "client_guid"; const string AvailableProfilesKey = "AvailableProfiles"; const float DefaultMasterVolume = 0.5f; const float DefaultMusicVolume = 0.8f; public static float GetMasterVolume() { return PlayerPrefs.GetFloat(MasterVolumeKey, DefaultMasterVolume); } public static void SetMasterVolume(float volume) { PlayerPrefs.SetFloat(MasterVolumeKey, volume); } public static float GetMusicVolume() { return PlayerPrefs.GetFloat(MusicVolumeKey, DefaultMusicVolume); } public static void SetMusicVolume(float volume) { PlayerPrefs.SetFloat(MusicVolumeKey, volume); } //客户端Guid public static string GetGuid(bool isNew) { if(isNew) { //没有则重新生成 return System.Guid.NewGuid().ToString(); } //缓存中有,返回 if(PlayerPrefs.HasKey(ClientGUIDKey)) { return PlayerPrefs.GetString(ClientGUIDKey); } //没有则重新生成 var guidString = System.Guid.NewGuid().ToString(); PlayerPrefs.SetString(ClientGUIDKey, guidString); return guidString; } public static string GetAvailableProfiles() { return PlayerPrefs.GetString(AvailableProfilesKey, ""); } public static void SetAvailableProfiles(string availableProfiles) { PlayerPrefs.SetString(AvailableProfilesKey, availableProfiles); } }