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

2 c# unity-game-engine

我想在 Windows 窗体应用程序中获得与UnityEngine.SystemInfo.deviceUniqueIdentifier在游戏中使用时获得的相同的硬件 ID。

如何获得相同的硬件 ID?

Luc*_*ini 5

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

需要:using System.Management;System.Management.dll(.NET Framework)中

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;
    }
Run Code Online (Sandbox Code Playgroud)

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