Unity3d--Platform macro definition

Source: Internet
Author: User
Tags versions

Official Document URL: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

This article is translated from the official documentation

Property
: Function:
Unity_editor Unity Editor
Unity_editor_win Windows operating system.
Unity_editor_osx MacOS Operating System
Unity_standalone_osx Defined specifically for MacOS (including Universal, Ppc,intel architectures) platform
Unity_standalone_win Specifically for the Windows platform definition
Unity_standalone_linux Specifically for the Linux platform definition
Unity_standalone Standalone platform (Mac OS X, Windows or Linux).
Unity_wii WII Console Platform
Unity_ios iOS system Platform
Unity_iphone Iphone
Unity_android Android System Platform
Unity_ps4 PS4 platform
Unity_samsungtv Samsung TV Platform
Unity_xboxone Xbox One Platform
Unity_tizen Tizen Platform
Unity_tvos Apple TV Platform
Unity_wsa #define directive for Universal Windows Platform. Additionally, Netfx_core is defined when compiling C # files against. NET CORE and using. NET Scripting backend.
Unity_wsa_10_0 #define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C # files against. NET Core.
Unity_winrt Unity_wsa.
Unity_winrt_10_0 Unity_wsa_10_0
Unity_webgl #define directive for WebGL.
Unity_facebook Facebook Platform (WebGL or Windows standalone).
Unity_ads Call ad method, version 5.2 later
Unity_analytics Call the Unity Analytics service after version 5.2
Unity_assertions The process of controlling instructions
UNITY Version Determination method: Unity_x,unity_x_y,unity_x_y_z For example:

   
Unity_5 Unity5 version, including all 5.X.Y versions
Unity_5_0 Unity5.0 version, including all 5.0.x versions
Unity_5_0_1 Unity5.0.1 version
When packaging, select File > Build settings and then display the Platform selection screen.



code example C #:

C #
using Unityengine;
Using System.Collections;

public class Platformdefines:monobehaviour {
  void Start () {

    #if unity_editor
      Debug.Log ("UNITY EDITOR"); c7/> #endif
    
    #if unity_ios
      Debug.Log ("Iphone");
    #endif

    #if unity_standalone_osx
    Debug.Log ("Stand Alone OSX");
    #endif

    #if unity_standalone_win
      Debug.Log ("Stand Alone Windows");
    #endif

  }          
}



You can use # if #elif

#if unity_editor
    Debug.Log ("UNITY EDITOR");

#elif Unity_ios
    Debug.Log ("UNITY iPhone");

#else
    Debug.Log ("Any other platform");

#endif

You can customize the macro definition, open the other Settings window, select player Settings > Scripting Define Symbols

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.