暂存
This commit is contained in:
1 parent
f4cbad819b
commit
0346b650aa
64 files changed
+12634
-12935
No files matched your search
@@ -5,6 +5,8 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
@@ -13,8 +15,64 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
|
||||
public static class Utils
|
||||
{
|
||||
/*获取ip*/
|
||||
public enum ADDRESSFAM
|
||||
{
|
||||
IPv4, IPv6
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本机IP
|
||||
/// </summary>
|
||||
/// <param name="Addfam">要获取的IP类型</param>
|
||||
/// <returns></returns>
|
||||
public static string GetIP(ADDRESSFAM Addfam)
|
||||
{
|
||||
if (Addfam == ADDRESSFAM.IPv6 && !Socket.OSSupportsIPv6)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string output = "";
|
||||
|
||||
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||
NetworkInterfaceType _type1 = NetworkInterfaceType.Wireless80211;
|
||||
NetworkInterfaceType _type2 = NetworkInterfaceType.Ethernet;
|
||||
|
||||
if ((item.NetworkInterfaceType == _type1 || item.NetworkInterfaceType == _type2) && item.OperationalStatus == OperationalStatus.Up)
|
||||
#endif
|
||||
{
|
||||
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
//IPv4
|
||||
if (Addfam == ADDRESSFAM.IPv4)
|
||||
{
|
||||
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
output = ip.Address.ToString();
|
||||
//Debug.Log("IP:" + output);
|
||||
}
|
||||
}
|
||||
|
||||
//IPv6
|
||||
else if (Addfam == ADDRESSFAM.IPv6)
|
||||
{
|
||||
if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
{
|
||||
output = ip.Address.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
/*获取ip*/
|
||||
/*显示简略提示,需要拖Toast的预制件,且保证其他组件名字不是Toast,ToastContainer*/
|
||||
public static void showToast(GameObject game,string text,int duration = 1)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user