This commit is contained in:
2020-07-21 22:50:03 +08:00
parent 4730b841ae
commit 3f114a6fca
69 changed files with 4668 additions and 1192 deletions

View File

@@ -2,10 +2,10 @@
using System.Collections;
//using System;
using System.Collections.Generic;
using Coolape;
using System.IO;
//using System.Net;
using System.Text;
using System.Net.Sockets;
using System.Net.NetworkInformation;
namespace Coolape
{
@@ -337,6 +337,7 @@ namespace Coolape
}
}
public static string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Unicode.GetBytes(cnChar);
@@ -364,6 +365,79 @@ namespace Coolape
else
return cnChar;
}
public enum ADDRESSFAM
{
IPv4, IPv6
}
public static string GetMyIP(ADDRESSFAM Addfam)
{
string ret = "";
List<string> IPs = GetAllIPs(Addfam, false);
if (IPs.Count > 0)
{
ret = IPs[IPs.Count - 1];
}
return ret;
}
public static List<string> GetAllIPs(ADDRESSFAM Addfam, bool includeDetails)
{
//Return null if ADDRESSFAM is Ipv6 but Os does not support it
if (Addfam == ADDRESSFAM.IPv6 && !Socket.OSSupportsIPv6)
{
return null;
}
List<string> output = new List<string>();
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
NetworkInterfaceType _type1 = NetworkInterfaceType.Wireless80211;
NetworkInterfaceType _type2 = NetworkInterfaceType.Ethernet;
bool isCandidate = (item.NetworkInterfaceType == _type1 || item.NetworkInterfaceType == _type2);
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
// as of MacOS (10.13) and iOS (12.1), OperationalStatus seems to be always "Unknown".
isCandidate = isCandidate && item.OperationalStatus == OperationalStatus.Up;
#endif
if (isCandidate)
#endif
{
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
{
//IPv4
if (Addfam == ADDRESSFAM.IPv4)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
{
string s = ip.Address.ToString();
if (includeDetails)
{
s += " " + item.Description.PadLeft(6) + item.NetworkInterfaceType.ToString().PadLeft(10);
}
output.Add(s);
}
}
//IPv6
else if (Addfam == ADDRESSFAM.IPv6)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6)
{
output.Add(ip.Address.ToString());
}
}
}
}
}
return output;
}
#if USE_LOCATION_SERVER
public static void StopGPS()
{
@@ -487,7 +561,7 @@ namespace Coolape
public static void setSoftInputMode(string modeType)
{
string mode = "";
switch(modeType)
switch (modeType)
{
case "SOFT_INPUT_ADJUST_NOTHING":
mode = "setAdjustNothing";