Skip to content

Commit 7a83ba8

Browse files
author
wanderer
committed
整理平台名称
1 parent f458100 commit 7a83ba8

File tree

2 files changed

+73
-15
lines changed

2 files changed

+73
-15
lines changed

GameFramework/Runtime/Utility/Utility.cs

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,84 @@
44

55
namespace Wanderer.GameFramework
66
{
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 = "";
1616
#if UNITY_IOS
17-
platformName = "IOS";
17+
platformName = "iOS";
1818
#elif UNITY_ANDROID
19-
platformName = "Android";
19+
platformName = "Android";
2020
#elif UNITY_STANDALONE_OSX
21-
platformName = "StandaloneOSX";
21+
platformName = "OSX";
2222
#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";
2428
#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();
2683
}
84+
2785
}
2886

2987
}

GameState/CheckResourceState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private void OnHttpReadTextSuccess(object sender, IEventArgs e)
130130
if (ne.Url == Path.Combine(_remoteUpdatePath, _assetPlatformVersionText))
131131
{
132132
PlatformVersionInfo assetPlatform = JsonUtility.FromJson<PlatformVersionInfo>(ne.Content);
133-
string platformName = Utility.GetPlatformName();
133+
string platformName = Utility.GetRuntimePlatformName();
134134
if (assetPlatform.Platforms.Contains(platformName))
135135
{
136136
//更新远程资源的路径

0 commit comments

Comments
 (0)