/// <summary>
        /// Generate unique machine identifier. Value should be with guid key in Attributes dictionary.
        /// Machine id is equal to mac address of first network interface. If network interface in unvailable, random long will be generated.
        /// </summary>
        /// <returns>Machine uuid</returns>
        private string GenerateMachineId()
        {
            if (SystemInfo.deviceUniqueIdentifier != SystemInfo.unsupportedIdentifier)
            {
                return(SystemInfo.deviceUniqueIdentifier);
            }
            var networkInterface =
                NetworkInterface.GetAllNetworkInterfaces()
                .FirstOrDefault(n => n.OperationalStatus == OperationalStatus.Up);

            PhysicalAddress physicalAddr = null;
            string          macAddress   = null;

            if (networkInterface == null ||
                (physicalAddr = networkInterface.GetPhysicalAddress()) == null ||
                string.IsNullOrEmpty(macAddress = physicalAddr.ToString()))
            {
                return(Guid.NewGuid().ToString());
            }

            string hex   = macAddress.Replace(":", string.Empty);
            var    value = Convert.ToInt64(hex, 16);

            return(GuidExtensions.FromLong(value).ToString());
        }
Exemple #2
0
        /// <summary>
        /// Generate unique machine identifier. Value should be with guid key in Attributes dictionary.
        /// Machine id is equal to mac address of first network interface. If network interface in unvailable, random long will be generated.
        /// </summary>
        /// <returns>Machine uuid</returns>
        private static string GenerateMachineId()
        {
#if !UNITY_WEBGL && !UNITY_SWITCH
            // DeviceUniqueIdentifier will return "Switch" on Nintendo Switch
            // try to generate random guid instead
            if (SystemInfo.deviceUniqueIdentifier != SystemInfo.unsupportedIdentifier)
            {
                return(SystemInfo.deviceUniqueIdentifier);
            }
            var networkInterface =
                NetworkInterface.GetAllNetworkInterfaces()
                .FirstOrDefault(n => n.OperationalStatus == OperationalStatus.Up);

            PhysicalAddress physicalAddr = null;
            string          macAddress   = null;
            if (networkInterface == null ||
                (physicalAddr = networkInterface.GetPhysicalAddress()) == null ||
                string.IsNullOrEmpty(macAddress = physicalAddr.ToString()))
            {
                return(Guid.NewGuid().ToString());
            }

            string hex   = macAddress.Replace(":", string.Empty);
            var    value = Convert.ToInt64(hex, 16);
            return(GuidExtensions.FromLong(value).ToString());
#else
            return(Guid.NewGuid().ToString());
#endif
        }