yyl
2026-03-31 0fa617a09eedf6bdb25eda55fac1d3344859fd93
Main/Utility/DeviceUtility.cs
@@ -1,13 +1,16 @@
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;
using Cysharp.Threading.Tasks;
using UnityEngine.Networking;
#if !UNITY_WEBGL
using System.Net.NetworkInformation;
using System.Net;
using System.IO;
#endif
#if UNITY_IOS
using UnityEngine.iOS;
@@ -20,6 +23,7 @@
    static string mac = string.Empty;
    public static string GetMac()
    {
#if !UNITY_WEBGL
        if (string.IsNullOrEmpty(mac))
        {
            try
@@ -35,12 +39,13 @@
                Debug.Log(ex);
            }
        }
#endif
        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 GetCachedIp() => ip;
    public static async UniTask<string> GetIp()
    {
        try
@@ -48,24 +53,20 @@
            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 = await wRequest.GetResponseAsync();
                Stream stream = wResponse.GetResponseStream();
                StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);
                string str = await reader.ReadToEndAsync();
                reader.Close();
                wResponse.Close();
                var match = Regex.Match(str, ipPattern);
                if (match != null)
                using (var request = UnityWebRequest.Get(url))
                {
                    ip = match.Value;
                    await request.SendWebRequest();
                    if (request.result == UnityWebRequest.Result.Success)
                    {
                        string str = request.downloadHandler.text;
                        var match = Regex.Match(str, ipPattern);
                        if (match != null)
                        {
                            ip = match.Value;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {