如何获得与 UnityEngine.SystemInfo.deviceUniqueIdentifier 中相同的硬件 id?

问题描述 投票:0回答:2

我想在 Windows 窗体应用程序中获得与我在游戏中使用

UnityEngine.SystemInfo.deviceUniqueIdentifier
时获得的相同的硬件 ID。

如何获得相同的硬件ID?

c# unity-game-engine
2个回答
6
投票

我知道我迟到了,但是 Unity 的 SystemInfo::deviceUniqueIdentifier 是这样构建的:

需要:

using System.Management;
(.NET Framework)
System.Management.dll

我对 Unity 编辑器进行了逆向工程,以找出它在 WMI 中实际查询的内容。这显然是 Windows 实现。


0
投票
https://docs.unity3d.com/ScriptReference/SystemInfo-deviceUniqueIdentifier.html

private string GetDeviceUniqueIdentifier() { string ret = string.Empty; string concatStr = string.Empty; try { using ManagementObjectSearcher searcherBb = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard"); foreach (var obj in searcherBb.Get()) { concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty; } using ManagementObjectSearcher searcherBios = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS"); foreach (var obj in searcherBios.Get()) { concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty; } using ManagementObjectSearcher searcherOs = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"); foreach (var obj in searcherOs.Get()) { concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty; } using var sha1 = SHA1.Create(); ret = string.Join("", sha1.ComputeHash(Encoding.UTF8.GetBytes(concatStr)).Select(b => b.ToString("x2"))); } catch (Exception e) { Console.WriteLine(e.ToString()); } return ret; }

	
© www.soinside.com 2019 - 2024. All rights reserved.