In development, especially in Unity's cross-platform, we often roam across platforms such as Android, Apple, PC .... On this different platform, it is possible that we need to do different things. However, we can use Unity's own platform macro definition to make the platform inference. Unity helps us define, for example, the following platform preprocessing:
Name |
Descriptive narrative |
Unity_editor |
Define for calling Unity Editor scripts from your game code. |
Unity_standalone_osx |
Platform Define for Compiling/executing code specifically for Mac OS (this includes Universal, PPC and Intel architectures ). |
Unity_dashboard_widget |
Platform define when creating code for MAC OS dashboard widgets. |
Unity_standalone_win |
The use of this is want to Compile/execute code for Windows stand alone applications. |
Unity_standalone_linux |
The use of this is want to Compile/execute code for Linux stand alone applications. |
Unity_standalone |
Use the Compile/execute code for any standalone platform (MAC, Windows or Linux). |
Unity_webplayer |
Platform define for Web player content (this includes Windows and MAC Web Player executables). |
Unity_wii |
Platform Define for compiling/executing code for the WII console. |
Unity_iphone |
Platform Define for compiling/executing code for the IPhone Platform. |
Unity_android |
Platform define for the Android Platform. |
Unity_ps3 |
Platform define for running PlayStation 3 code. |
unity_xbox360 |
Platform define for executing Xbox code. |
Unity_nacl |
Platform define when compiling code for Google Native Client (this would be set additionally to Unity_webplayer). |
Unity_flash |
Platform define when compiling code for Adobe Flash. |
|
|
We are able to add inferences to our code in the future by being able to go easy on the basis of the macro definition. Let me give you a simple example, like this:
- Using Unityengine;
- Using System.Collections;
- Public class Recompile:monobehaviour
- {
- private String platform = string. Empty;
- // Use this for initialization
- void Start ()
- {
- Debugplatformmesaage ();
- }
- void Debugplatformmesaage ()
- {
- #if Unity_editor
- Platform = "Hi, hello everyone, I am in unity edit mode";
- #elif unity_xbox360
- platform="Hi, hello everyone, I am on the XBOX360 platform";
- #elif Unity_iphone
- platform="Hi, hello everyone, I am the iphone platform";
- #elif unity_android
- platform="Hi, hello everyone, I am Android platform";
- #elif UNITY_STANDALONE_OSX
- platform="Hi, hello everyone, I am OSX platform";
- #elif Unity_standalone_win
- platform="Hi, hello everyone, I am the Windows platform";
- #endif
- Debug.Log ("Current Platform:" + Platform);
- }
- }
If I were in the editor state, I would see the print out:
We are also able to customize the macro definition, defined in playersetting:
Like the place where I circled up, fill in a custom_itf this precompiled instruction. and add this sentence at the end of the Debugplatformmesaage function.
- Newly added content
- #if CUSTOM_ITF
- Custommsg = "I have defined the precompilation myself";
- #endif
- Debug.Log (CUSTOMMSG);
And then we take a look, and you can see the information we output in the console:
When we define our own macro definitions to be removed, the information we print will not come out.
In addition to these, unity also has the version number of the macro definition, the general development of the plug-in Daniel will use.
Unity_2_6 |
Platform define for the major version of Unity 2.6. |
Unity_2_6_1 |
Platform define for specific version 1 from the major release 2.6. |
Unity_3_0 |
Platform define for the major version of Unity 3.0. |
Unity_3_0_0 |
Platform define for the specific version 0 of Unity 3.0. |
Unity_3_1 |
Platform define for major version of Unity 3.1. |
Unity_3_2 |
Platform define for major version of Unity 3.2. |
Unity_3_3 |
Platform define for major version of Unity 3.3. |
Unity_3_4 |
Platform define for major version of Unity 3.4. |
Unity_3_5 |
Platform define for major version of Unity 3.5. |
Unity_4_0 |
Platform define for major version of Unity 4.0. |
Unity_4_0_1 |
Platform define for major version of Unity 4.0.1. |
Unity_4_1 |
Platform define for major version of Unity 4.1. |
Unity_4_2 |
Platform define for major version of Unity 4.2. |
|
Unity Multi-platform preprocessing