少年修仙传客户端代码仓库
lcy
3 天以前 6d8908e1fcfb62e174d1fa60eb6aa31f65dff3e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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)
            {
                DebugEx.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 = 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;
        }
 
    }
 
}