Unity各平台宏定义

属性方法
UNITY_EDITOR #define directive for calling Unity Editor scripts from your game code.
UNITY_EDITOR_WIN #define directive for Editor code on Windows.
UNITY_EDITOR_OSX #define directive for Editor code on Mac OS X.
UNITY_STANDALONE #define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
UNITY_STANDALONE_WIN #define directive for compiling/executing code specifically for Windows standalone applications.
UNITY_STANDALONE_OSX #define directive for compiling/executing code specifically for Mac OS X (including Universal, PPC and Intel architectures).
UNITY_STANDALONE_LINUX #define directive for compiling/executing code specifically for Linux standalone applications.
UNITY_ANDROID #define directive for the Android platform.
UNITY_IOS #define directive for compiling/executing code for the iOS platform.
UNITY_IPHONE Deprecated. Use UNITY_IOS instead.
UNITY_WEBGL #define directive for WebGL.
UNITY_WP_8_1 #define directive for Windows Phone 8.1.
UNITY_PS4 #define directive for running PlayStation 4 code.
UNITY_XBOXONE #define directive for executing Xbox One code.
UNITY_WII #define directive for compiling/executing code for the Wii console.
UNITY_SAMSUNGTV #define directive for executing Samsung TV code.

样例:

复制代码
// C#
using UnityEngine;
using System.Collections;

public class PlatformDefines : MonoBehaviour {

  void Start () {
    #if UNITY_EDITOR
        Debug.Log("Unity Editor");
    #elif UNITY_IOS
        Debug.Log("Unity iPhone");
    #else
        Debug.Log("Any other platform");
    #endif
  }

}
复制代码

 

复制代码
// JS
function Awake() {
  #if UNITY_EDITOR
    Debug.Log("Unity Editor");
  #endif
    
  #if UNITY_IPHONE
    Debug.Log("Iphone");
  #endif

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

  #if UNITY_STANDALONE_WIN
    Debug.Log("Stand Alone Windows");
  #endif
}
复制代码

Unity宏定义官方文档

posted @   冰封百度  阅读(3315)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示