Unity Multi-platform preprocessing

Source: Internet
Author: User

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:

  1. Using Unityengine;
  2. Using System.Collections;
  3. Public class Recompile:monobehaviour
  4. {
  5. private String platform = string.  Empty;
  6. // Use this for initialization
  7. void Start ()
  8. {
  9. Debugplatformmesaage ();
  10. }
  11. void Debugplatformmesaage ()
  12. {
  13. #if Unity_editor
  14. Platform = "Hi, hello everyone, I am in unity edit mode";
  15. #elif unity_xbox360
  16. platform="Hi, hello everyone, I am on the XBOX360 platform";
  17. #elif Unity_iphone
  18. platform="Hi, hello everyone, I am the iphone platform";
  19. #elif unity_android
  20. platform="Hi, hello everyone, I am Android platform";
  21. #elif UNITY_STANDALONE_OSX
  22. platform="Hi, hello everyone, I am OSX platform";
  23. #elif Unity_standalone_win
  24. platform="Hi, hello everyone, I am the Windows platform";
  25. #endif
  26. Debug.Log ("Current Platform:" + Platform);
  27. }
  28. }

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.

    1. Newly added content
    2. #if CUSTOM_ITF
    3. Custommsg = "I have defined the precompilation myself";
    4. #endif
    5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.