unityzgy/Assets/Scripts/PublicTool/NetHelper.cs
ayuan9957 69641904da fix: 翻译实时更新修复 + 路径检查 + IP选择 + 地形Layer修复
- IconBase: 修复(N)后缀车辆名翻译, 添加OnDestroy取消订阅防止MissingReference
- AnserWindowCtrl: 添加LanguageChanged订阅, 障碍提示实时翻译
- PlanningPlaneCtrl: 修复路径检查Count<0改为<1, 允许单段路径
- CarAIExtendCtrl: 空wayPoints数组防护
- GameObjectCreater: 重复key用索引赋值替代Add
- NetHelper: 优先返回10.x/192.168.x局域网IP, 跳过WSL虚拟网卡
- 海岛/沙漠/丘陵: Terrain Layer设为Floor(8), NavigationStatic
- 沙漠: TerrainLayer smoothness设为0
- 新增本地化条目: 携带装备/搭载人员/装备名称/空袭/维修厂等
2026-07-31 09:30:21 +08:00

55 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using System.Net;
namespace ETModel
{
public static class NetHelper
{
public static string[] GetAddressIPs()
{
//获取本地的IP地址
List<string> addressIPs = new List<string>();
foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
addressIPs.Add(address.ToString());
}
return addressIPs.ToArray();
}
public static string GetAddressIPV4()
{
//获取本地的IPV4地址优先返回局域网IP10.x/192.168.x/172.16-31.x跳过虚拟网卡
string lanIP = "";
string fallbackIP = "";
foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
string ip = address.ToString();
string[] parts = ip.Split('.');
if (parts.Length == 4)
{
// 优先返回10.x和192.168.x网段
if (parts[0] == "10" || (parts[0] == "192" && parts[1] == "168"))
{
lanIP = ip;
}
// 172.16-31.x 也是局域网但可能是虚拟网卡,作为备选
else if (parts[0] == "172")
{
int second = int.Parse(parts[1]);
if (second >= 16 && second <= 31 && string.IsNullOrEmpty(lanIP))
lanIP = ip;
}
else
{
fallbackIP = ip;
}
}
}
}
return !string.IsNullOrEmpty(lanIP) ? lanIP : fallbackIP;
}
}
}