| using System.Collections; | 
| using System.Collections.Generic; | 
| using UnityEngine; | 
| using System.Net.NetworkInformation; | 
| using System; | 
| using System.Net; | 
| using System.Net.Sockets; | 
| using System.IO; | 
| using System.Text.RegularExpressions; | 
|   | 
| #if UNITY_IOS | 
| using UnityEngine.iOS; | 
| #endif | 
|   | 
|   | 
| public class DeviceUtility | 
| { | 
|   | 
|     static string mac = string.Empty; | 
|     public static string GetMac() | 
|     { | 
|         if (string.IsNullOrEmpty(mac)) | 
|         { | 
|             try | 
|             { | 
|                 var netInterfaces = NetworkInterface.GetAllNetworkInterfaces(); | 
|                 if (netInterfaces != null && netInterfaces.Length > 0) | 
|                 { | 
|                     mac = netInterfaces[0].GetPhysicalAddress().ToString(); | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 Debug.Log(ex); | 
|             } | 
|         } | 
|   | 
|         return mac; | 
|     } | 
|   | 
|     static string ipPattern = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"; | 
|     static string ip = string.Empty; | 
|     public static string GetIp() | 
|     { | 
|         try | 
|         { | 
|             if (string.IsNullOrEmpty(ip)) | 
|             { | 
|                 string url = "http://pv.sohu.com/cityjson"; | 
|                 WebRequest wRequest = WebRequest.Create(url); | 
|                 wRequest.Method = "GET"; | 
|                 wRequest.ContentType = "text/html;charset=UTF-8"; | 
|                 WebResponse wResponse = wRequest.GetResponse(); | 
|                 Stream stream = wResponse.GetResponseStream(); | 
|                 StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default); | 
|                 string str = reader.ReadToEnd(); | 
|   | 
|                 reader.Close(); | 
|                 wResponse.Close(); | 
|   | 
|                 var match = Regex.Match(str, ipPattern); | 
|                 if (match != null) | 
|                 { | 
|                     ip = match.Value; | 
|                 } | 
|             } | 
|         } | 
|         catch (Exception ex) | 
|         { | 
|             Debug.Log(ex); | 
|         } | 
|   | 
|         return ip; | 
|     } | 
|   | 
|     public static string GetDeviceUniquenessIdentify() | 
|     { | 
| #if UNITY_IOS | 
|         return UnityEngine.iOS.Device.advertisingIdentifier; | 
| #else | 
|         return SystemInfo.deviceUniqueIdentifier; | 
| #endif | 
|     } | 
|   | 
|     public static string GetDeviceOSLevel() | 
|     { | 
| #if UNITY_IOS | 
|         return UnityEngine.iOS.Device.systemVersion; | 
| #else | 
|         return SystemInfo.operatingSystem; | 
| #endif | 
|     } | 
|   | 
|     public static string GetDeviceName() | 
|     { | 
| #if UNITY_IOS | 
|         return UnityEngine.iOS.Device.generation.ToString(); | 
| #else | 
|         return SystemInfo.deviceName; | 
| #endif | 
|     } | 
|   | 
|     public static string GetDeviceModel() | 
|     { | 
| #if UNITY_IOS | 
|         return UnityEngine.iOS.Device.generation.ToString(); | 
| #else | 
|         return SystemInfo.deviceModel; | 
| #endif | 
|     } | 
|   | 
|     public static bool IsLowMemory() | 
|     { | 
| #if UNITY_IOS | 
|         if (Application.platform == RuntimePlatform.IPhonePlayer) | 
|         { | 
|             switch (Device.generation) | 
|             { | 
|                 case DeviceGeneration.iPadMini2Gen: | 
|                 case DeviceGeneration.iPhone5S: | 
|                 case DeviceGeneration.iPhone6: | 
|                 case DeviceGeneration.iPhone6Plus: | 
|                     return true; | 
|                 default: | 
|                     return false; | 
|             } | 
|         } | 
|         else | 
|         { | 
|             return false; | 
|         } | 
| #endif | 
|         return false; | 
|     } | 
|   | 
|     public static int cpu = 2; | 
|     public static int memory = 2 * 1024; | 
|   | 
|     public static void GetCpuAndMemory(out int _cpu, out int _memory)//内存单位是MB | 
|     { | 
|         try | 
|         { | 
|             _cpu = Environment.ProcessorCount; | 
|             switch (Application.platform) | 
|             { | 
|                 case RuntimePlatform.Android: | 
|                     _memory = 0; //TODO YL collect device memory //ynmbxxjUtil.Instance.Device.totalMemory; | 
|                     break; | 
|                 case RuntimePlatform.IPhonePlayer: | 
|                     _memory = IsLowMemory() ? 1 : 2 * 1024; | 
|                     break; | 
|                 default: | 
|                     _memory = 4 * 1024; | 
|                     break; | 
|             } | 
|   | 
|             cpu = _cpu; | 
|             memory = _memory; | 
|         } | 
|         catch (Exception ex) | 
|         { | 
|             Debug.Log(ex); | 
|             _cpu = 2; | 
|             _memory = 2 * 1024; | 
|         } | 
|   | 
|     } | 
|   | 
| } |