DeviceUniqueIdHelper.cs 846 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. namespace GFGGame
  3. {
  4. public class DeviceUniqueIdHelper
  5. {
  6. private const string UniqueIdentifierKey = "UniqueIdentifier";
  7. public static string GetDeviceUniqueId()
  8. {
  9. // 尝试从本地存储中获取唯一标识符
  10. string uniqueIdentifier = PlayerPrefs.GetString(UniqueIdentifierKey);
  11. // 如果本地存储中不存在唯一标识符,生成一个新的唯一标识符
  12. if (string.IsNullOrEmpty(uniqueIdentifier))
  13. {
  14. uniqueIdentifier = SystemInfo.deviceUniqueIdentifier;
  15. // 将唯一标识符存储到本地存储中
  16. PlayerPrefs.SetString(UniqueIdentifierKey, uniqueIdentifier);
  17. }
  18. return PlayerPrefs.GetString(UniqueIdentifierKey);
  19. }
  20. }
  21. }