JoshuaReason 5 years ago
parent
commit
5f69d2e2f7
3 changed files with 67 additions and 1 deletions
  1. +55
    -0
      Assets/Scipts/IPGrabber.cs
  2. +11
    -0
      Assets/Scipts/IPGrabber.cs.meta
  3. +1
    -1
      Assets/Scipts/Map.cs

+ 55
- 0
Assets/Scipts/IPGrabber.cs View File

@ -0,0 +1,55 @@
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
public class IPGrabber{
public static string GetIP(ADDRESSFAM Addfam)
{
//Return null if ADDRESSFAM is Ipv6 but Os does not support it
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();
}
}
//IPv6
else if (Addfam == ADDRESSFAM.IPv6)
{
if (ip.Address.AddressFamily == AddressFamily.InterNetworkV6)
{
output = ip.Address.ToString();
}
}
}
}
}
return output;
}
}
public enum ADDRESSFAM
{
IPv4, IPv6
}

+ 11
- 0
Assets/Scipts/IPGrabber.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e05bab93a1df3449a51fe90e3551589
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 1
- 1
Assets/Scipts/Map.cs View File

@ -14,7 +14,7 @@ public class Map : MonoBehaviour
public int TileSize = 100;
public Vector2 MapDimensions;
public List<GameObject> VeggieLocations;
public List<GameObject> Veggies;
//Minimum and maximum values for the map
public float minX;
public float maxX;

Loading…
Cancel
Save