您的位置:首页 > 移动开发 > Unity3D

【转】使用SYSTEMINFO类获取UNITY3D运行设备的各类信息(CPU类型,显卡类型等)

2017-04-22 22:18 555 查看
转自:使用SYSTEMINFO类获取UNITY3D运行设备的各类信息(CPU类型,显卡类型等)

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 using UnityEngine;

2

3 using System.Collections;

4

5 using System.Collections.Generic;

6

7 public class GameControllerScript: MonoBehaviour

8

9 {

10

11 //指定输出文本框

12

13 public UnityEngine.UI.Text messageText;

14

15 //存储临时字符串

16

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

18

19 // Use this for initialization

20

21 void Start()

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 void Update()

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编辑器中运行的结果:

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

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

6.其他

有兴有趣的话,可以查看官方的文档了解SystemInfo的其他属性和方法,链接是:https://docs.unity3d.com/ScriptReference/SystemInfo.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d 内存
相关文章推荐