4
4
5
5
namespace Wanderer . GameFramework
6
6
{
7
- public class Utility
8
- {
9
- /// <summary>
10
- /// 获取平台名称
11
- /// </summary>
12
- /// <returns></returns>
13
- public static string GetPlatformName ( )
14
- {
15
- string platformName = "StandaloneWindows " ;
7
+ public class Utility
8
+ {
9
+ /// <summary>
10
+ /// 获取平台名称
11
+ /// </summary>
12
+ /// <returns></returns>
13
+ public static string GetPlatformName ( )
14
+ {
15
+ string platformName = "" ;
16
16
#if UNITY_IOS
17
- platformName = "IOS " ;
17
+ platformName = "iOS " ;
18
18
#elif UNITY_ANDROID
19
- platformName = "Android" ;
19
+ platformName = "Android" ;
20
20
#elif UNITY_STANDALONE_OSX
21
- platformName = "StandaloneOSX " ;
21
+ platformName = "OSX " ;
22
22
#elif UNITY_STANDALONE_LINUX
23
- platformName = "StandaloneLinux" ;
23
+ platformName = "Linux" ;
24
+ #elif UNITY_STANDALONE_WIN
25
+ platformName = "Windows" ;
26
+ #elif UNITY_WEBGL
27
+ platformName = "WebGL" ;
24
28
#endif
25
- return platformName . ToLower ( ) ;
29
+ return platformName . ToLower ( ) ;
30
+ }
31
+
32
+ /// <summary>
33
+ /// 获取运行平台
34
+ /// </summary>
35
+ /// <returns></returns>
36
+ public static RuntimePlatform GetRuntimePlatform ( )
37
+ {
38
+ return Application . platform ;
39
+ }
40
+
41
+ /// <summary>
42
+ /// 获取运行时间的平台名称
43
+ /// </summary>
44
+ /// <param name="target">编辑器默认以目标平台为准</param>
45
+ /// <returns></returns>
46
+ public static string GetRuntimePlatformName ( bool target = true )
47
+ {
48
+ string platformName = "" ;
49
+ switch ( Application . platform )
50
+ {
51
+ case RuntimePlatform . OSXEditor :
52
+ platformName = target ? GetPlatformName ( ) : "OSX" ;
53
+ break ;
54
+ case RuntimePlatform . OSXPlayer :
55
+ platformName = "OSX" ;
56
+ break ;
57
+ case RuntimePlatform . WindowsPlayer :
58
+ platformName = "Windows" ;
59
+ break ;
60
+ case RuntimePlatform . WindowsEditor :
61
+ platformName = target ? GetPlatformName ( ) : "Windows" ;
62
+ break ;
63
+ case RuntimePlatform . IPhonePlayer :
64
+ platformName = "iOS" ;
65
+ break ;
66
+ case RuntimePlatform . Android :
67
+ platformName = "Android" ;
68
+ break ;
69
+ case RuntimePlatform . LinuxPlayer :
70
+ platformName = "Linux" ;
71
+ break ;
72
+ case RuntimePlatform . LinuxEditor :
73
+ platformName = target ? GetPlatformName ( ) : "Linux" ;
74
+ break ;
75
+ case RuntimePlatform . WebGLPlayer :
76
+ platformName = "WebGL" ;
77
+ break ;
78
+ default :
79
+ platformName = Application . platform . ToString ( ) ;
80
+ break ;
81
+ }
82
+ return platformName . ToLower ( ) ;
26
83
}
84
+
27
85
}
28
86
29
87
}
0 commit comments