Unity3D -- 平台宏定义

官方文档网址:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

本文章转译自官方文档

Property: Function:
UNITY_EDITOR Unity编辑器
UNITY_EDITOR_WIN Windows 操作系统.
UNITY_EDITOR_OSX macos操作系统
UNITY_STANDALONE_OSX 专门为macos(包括Universal, PPC,Intel architectures)平台的定义
UNITY_STANDALONE_WIN 专门为windows平台的定义
UNITY_STANDALONE_LINUX 专门为Linux平台的定义
UNITY_STANDALONE 独立平台 (Mac OS X, Windows or Linux).
UNITY_WII WII 游戏机平台
UNITY_IOS iOS系统平台
UNITY_IPHONE iPhone
UNITY_ANDROID android系统平台
UNITY_PS4 ps4平台
UNITY_SAMSUNGTV 三星TV平台
UNITY_XBOXONE Xbox One 平台
UNITY_TIZEN Tizen 平台
UNITY_TVOS Apple TV 平台
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平台(WebGL or Windows standalone).
UNITY_ADS 调用广告方法,版本 5.2 以后
UNITY_ANALYTICS 调用unity分析服务,版本5.2以后
UNITY_ASSERTIONS 控制指令的过程
Unity版本判定方式:UNITY_X,UNITY_X_Y,UNITY_X_Y_Z 例如:

   
UNITY_5 unity5版本, 包含所有的5.x.y版本
UNITY_5_0 Unity5.0版本,包含所有的5.0.x版本
UNITY_5_0_1 Unity5.0.1版本
打包的时候,选择 File >  Build Settings然后显示平台选择界面 .



代码实例C#


// C#
using UnityEngine;
using System.Collections;

public class PlatformDefines : MonoBehaviour {
  void Start () {

    #if UNITY_EDITOR
      Debug.Log("Unity Editor");
    #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

  }          
}



可以使用#if #elif

#if UNITY_EDITOR
    Debug.Log("Unity Editor");

#elif UNITY_IOS
    Debug.Log("Unity iPhone");

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

#endif

可以自定义宏定义,打开Other Settings窗口,选择Player Settings > Scripting Define Symbols

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值