Jtro的技术分享:Unity中读取PC的硬件信息

作者: UnityPlane | 来源:发表于2017-10-16 15:03 被阅读72次

这个功能似乎没有什么用,但是我在《c#入门到精通》这本书中看到这样的功能,在非unity开发的项目中,假如说你是一个纯c#软件开发者,这个你可以用来保护你的软件,不被肆意传播,起到了很好的著作权保护作用,但是在unity中引用似乎很少,但是,存在即合理。一定有用,所以接下来由鄙人分享这个功能。希望能帮到有需要的人。
首先,新建空工程,然后再新建一个Text文本文件,扩大到画布的大小。如下图所示:

Text组件.PNG

然后新建一个脚本,命名为GetCpuNum,挂载在摄像机上。下面贴出源码,方便大家测试。

//    脚本功能:
//此脚本挂载在:    上
//    初创日期:
//        作者:张曙光
//  第一次修改:
using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class GetcpuNum: MonoBehaviour

{

    //指定输出文本框

    public UnityEngine.UI.Text messageText;

    //存储临时字符串

    System.Text.StringBuilder info = new System.Text.StringBuilder();

    // Use this for initialization

    void Start()

    {
        //将输出文本框置空
        messageText.text = "";

        info.AppendLine("设备与系统信息:");



        //设备的模型

        GetMessage("设备模型",SystemInfo.deviceModel);

        //设备的名称

        GetMessage("设备名称",SystemInfo.deviceName);

        //设备的类型

        GetMessage("设备类型(PC电脑,掌上型)",SystemInfo.deviceType.ToString());

        //系统内存大小

        GetMessage("系统内存大小MB",SystemInfo.systemMemorySize.ToString());

        //操作系统

        GetMessage("操作系统",SystemInfo.operatingSystem);

        //设备的唯一标识符

        GetMessage("设备唯一标识符",SystemInfo.deviceUniqueIdentifier);

        //显卡设备标识ID

        GetMessage("显卡ID",SystemInfo.graphicsDeviceID.ToString());

        //显卡名称

        GetMessage("显卡名称", SystemInfo.graphicsDeviceName);

        //显卡类型

        GetMessage("显卡类型",SystemInfo.graphicsDeviceType.ToString());

        //显卡供应商

        GetMessage("显卡供应商", SystemInfo.graphicsDeviceVendor);

        //显卡供应唯一ID

        GetMessage("显卡供应唯一ID", SystemInfo.graphicsDeviceVendorID.ToString());

        //显卡版本号

        GetMessage("显卡版本号",SystemInfo.graphicsDeviceVersion);

        //显卡内存大小

        GetMessage("显存大小MB",SystemInfo.graphicsMemorySize.ToString());

        //显卡是否支持多线程渲染

        GetMessage("显卡是否支持多线程渲染",SystemInfo.graphicsMultiThreaded.ToString());

        //支持的渲染目标数量

        GetMessage("支持的渲染目标数量", SystemInfo.supportedRenderTargetCount.ToString());
        //输出

        messageText.text = info.ToString();

    }



    // Update is called once per frame

    void Update()

    {

        //退出

        if (Input.GetKeyUp("escape"))

        {



            if (Input.GetKeyUp("escape"))

            {

                Application.Quit();

            }

        }

    }

    void GetMessage(params string[] str)

    {

        if(str.Length==2)

        {

            info.AppendLine(str[0]+":"+str[1]);

        }

    }  

}

保存之后关掉Mono,点击摄像机,把text组件拖到MessageText中。
然后再运行,你会看到类似下图的效果。

运行效果图.PNG

注:由于硬件的不同读取的信息也不一样。
OK,感谢简书,感谢读完的你。

相关文章

网友评论

    本文标题:Jtro的技术分享:Unity中读取PC的硬件信息

    本文链接:https://www.haomeiwen.com/subject/hrwkuxtx.html