Skip to content

Commit 68962fd

Browse files
committed
Unity各平台宏定义
1 parent 52c9669 commit 68962fd

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Doc/Unity各平台宏定义.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Unity各平台宏定义
2+
3+
### 对照表
4+
|| 定义 |
5+
| :---- | :---- |
6+
| UNITY_EDITOR | #define directive for calling Unity Editor scripts from your game code. |
7+
| UNITY_EDITOR_WIN | #define directive for Editor code on Windows. |
8+
| UNITY_EDITOR_OSX | #define directive for Editor code on Mac OS X. |
9+
| UNITY_STANDALONE | #define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux). |
10+
| UNITY_STANDALONE_WIN | #define directive for compiling/executing code specifically for Windows standalone applications. |
11+
| UNITY_STANDALONE_OSX | #define directive for compiling/executing code specifically for Mac OS X (including Universal, PPC and Intel architectures). |
12+
| UNITY_STANDALONE_LINUX | #define directive for compiling/executing code specifically for Linux standalone applications. |
13+
| UNITY_ANDROID | #define directive for the Android platform. |
14+
| UNITY_IOS | #define directive for compiling/executing code for the iOS platform. |
15+
| UNITY_IPHONE | Deprecated. Use UNITY_IOS instead. |
16+
| UNITY_WEBGL | #define directive for WebGL. |
17+
| UNITY_WP_8_1 | #define directive for Windows Phone 8.1. |
18+
| UNITY_PS4 | #define directive for running PlayStation 4 code. |
19+
| UNITY_XBOXONE | #define directive for executing Xbox One code. |
20+
| UNITY_WII | #define directive for compiling/executing code for the Wii console. |
21+
| UNITY_SAMSUNGTV | #define directive for executing Samsung TV code. |
22+
23+
### 样例
24+
``` C#
25+
using UnityEngine;
26+
using System.Collections;
27+
28+
public class PlatformDefines : MonoBehaviour {
29+
30+
void Start () {
31+
#if UNITY_EDITOR
32+
Debug.Log("Unity Editor");
33+
#elif UNITY_IOS
34+
Debug.Log("Unity iPhone");
35+
#else
36+
Debug.Log("Any other platform");
37+
#endif
38+
}
39+
40+
}
41+
```
42+
43+
``` C#
44+
function Awake() {
45+
#if UNITY_EDITOR
46+
Debug.Log("Unity Editor");
47+
#endif
48+
49+
#if UNITY_IPHONE
50+
Debug.Log("Iphone");
51+
#endif
52+
53+
#if UNITY_STANDALONE_OSX
54+
Debug.Log("Stand Alone OSX");
55+
#endif
56+
57+
#if UNITY_STANDALONE_WIN
58+
Debug.Log("Stand Alone Windows");
59+
#endif
60+
}
61+
```
62+
* [Unity宏定义官方文档](https://docs.unity3d.com/Manual/PlatformDependentCompilation.html)
63+

0 commit comments

Comments
 (0)