码迷,mamicode.com
首页 > 移动开发 > 详细

unity基础开发----Unity获取PC,Ios系统的mac地址等信息

时间:2018-01-18 19:36:57      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:cad   ret   nic   else   using   软件   安卓   tar   nice   

在软件开发中可以会用到mac地址作为,设备的唯一标示,我们也可以通过unity获取,经测试pc,ios都可以但是安卓没有获取到。

代码如下:

using UnityEngine;
using System.Collections;
using System.Net.NetworkInformation;

public class NetWorkInfo : MonoBehaviour
{
    void Start()
    {
        Debug.Log(GetMacAddress());
    }

    public static string GetMacAddress()
    {
        string physicalAddress = "";
        NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface adaper in nice)
        {
            Debug.Log(adaper.Description);
            if (adaper.Description == "en0")
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                break;
            }
            else
            {
                physicalAddress = adaper.GetPhysicalAddress().ToString();
                if (physicalAddress != "")
                {
                    break;
                };
            }
        }
        return physicalAddress;
    }
void OnGUI() { GUI.Label(new Rect(0, 0, 200, 100), "MAC=" + GetMacAddress()); } }

补充说明:

using UnityEngine;
using System.Collections;
using System.Net.NetworkInformation;

public class Test : MonoBehaviour {

    void Start() {
        NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface ni in nis) {
            Debug.Log ("Name = " + ni.Name);
            Debug.Log ("Des = " + ni.Description);
            Debug.Log ("Type = " + ni.NetworkInterfaceType.ToString() );
            Debug.Log ("Mac地址 = " + ni.GetPhysicalAddress().ToString() );
            Debug.Log ("------------------------------------------------");
        }
    }
}

 

unity基础开发----Unity获取PC,Ios系统的mac地址等信息

标签:cad   ret   nic   else   using   软件   安卓   tar   nice   

原文地址:https://www.cnblogs.com/crazytomato/p/8311733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!