1.概述

2.创建演示项目

3.编写示例代码

4.执行代码

6.其他

1.概述

研究完Unity3D的Application类后,就该看了一下SystemInfo类。这两个类都在UnityEngine类中。

SystemInfo类中的属性都是只读属性,存储着运行平台的一些信息,主要是显卡和设备信息,如:设备的名称、设备的类型、显卡的类型,显卡的名称、显卡供应商(制造商)、系统内存大小、显存大小、支持的渲染目标数量等等。

2.创建演示项目

(1)打开Unity3D,新建一个项目;

(2)新建一个C#脚本,并将脚本绑定到主相机(MianCamera)上;

(3)单击菜单栏上的GameObject,选择UI,添加一个Text。

3.编写示例代码

(1)双击打开刚才新建的脚本,开始编辑代码(其实SystemInfo类很简单)。

编写的代码如下所示:

1 usingUnityEngine;2

3 usingSystem.Collections;4

5 usingSystem.Collections.Generic;6

7 public classGameControllerScript: MonoBehaviour8

9 {10

11 //指定输出文本框

12

13 publicUnityEngine.UI.Text messageText;14

15 //存储临时字符串

16

17 System.Text.StringBuilder info = newSystem.Text.StringBuilder();18

19 //Use this for initialization

20

21 voidStart()22

23 {24

25

26

27 //将输出文本框置空

28

29 messageText.text = "";30

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

33

34

35 //设备的模型

36

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

39 //设备的名称

40

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

43 //设备的类型

44

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

47 //系统内存大小

48

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

51 //操作系统

52

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

55 //设备的唯一标识符

56

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

59 //显卡设备标识ID

60

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

63 //显卡名称

64

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

67 //显卡类型

68

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

71 //显卡供应商

72

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

75 //显卡供应唯一ID

76

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

79 //显卡版本号

80

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

83 //显卡内存大小

84

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

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

88

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

91 //支持的渲染目标数量

92

93 GetMessage("支持的渲染目标数量", SystemInfo.supportedRenderTargetCount.ToString());94

95

96

97

98

99

100

101

102

103

104

105 //输出

106

107 messageText.text =info.ToString();108

109 }110

111

112

113 //Update is called once per frame

114

115 voidUpdate()116

117 {118

119 //退出

120

121 if (Input.GetKeyUp("escape"))122

123 {124

125

126

127 if (Input.GetKeyUp("escape"))128

129 {130

131 Application.Quit();132

133 }134

135 }136

137 }138

139 void GetMessage(params string[] str)140

141 {142

143 if(str.Length==2)144

145 {146

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

149 }150

151 }152

153 }

(2)保存代码,转到Unity3D编辑器中,将Text绑定到脚本。

4.执行代码

执行代码后可以显示运行设备的一些信息。

(1)在Unity3D编辑器中运行的结果:

6f57f7dc54bf7ca3d687345c822889ac.png

(1)在Windows中的运行的结果:

45f26ecb3fb60ba06af4fc3e6f002d3c.png

(1)在Android中的运行的结果:

cb57b9416e25644f647629cc3ba0845b.png

6.其他

如有错误,还望指正!

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐