{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/",
  "atlas": "https://www.pystone.net/?node=unity-csharp-preprocessor-directives#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives.md",
  "context": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:unity-csharp-preprocessor-directives",
  "slug": "unity-csharp-preprocessor-directives",
  "title": "Unity与C#预处理指令",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "Unity与C 预处理指令",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "c9dfffffbeeefc7da3ce873580adc77e5ba5c349bee9ea8215bdf705e7368d20",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "Unity与C#预处理指令",
      "anchor": "unity与c预处理指令",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#unity%E4%B8%8Ec%E9%A2%84%E5%A4%84%E7%90%86%E6%8C%87%E4%BB%A4"
    },
    {
      "depth": 2,
      "text": "Unity&C预处理指令",
      "anchor": "unityc预处理指令",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#unityc%E9%A2%84%E5%A4%84%E7%90%86%E6%8C%87%E4%BB%A4"
    },
    {
      "depth": 2,
      "text": "预处理指令（条件编译）",
      "anchor": "预处理指令条件编译",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#%E9%A2%84%E5%A4%84%E7%90%86%E6%8C%87%E4%BB%A4%E6%9D%A1%E4%BB%B6%E7%BC%96%E8%AF%91"
    },
    {
      "depth": 3,
      "text": "Conditional特性",
      "anchor": "conditional特性",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#conditional%E7%89%B9%E6%80%A7"
    },
    {
      "depth": 2,
      "text": "Unity自带的一些宏定义",
      "anchor": "unity自带的一些宏定义",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#unity%E8%87%AA%E5%B8%A6%E7%9A%84%E4%B8%80%E4%BA%9B%E5%AE%8F%E5%AE%9A%E4%B9%89"
    },
    {
      "depth": 2,
      "text": "自定义宏定义",
      "anchor": "自定义宏定义",
      "citation": "https://www.pystone.net/notes/unity-csharp-preprocessor-directives/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%8F%E5%AE%9A%E4%B9%89"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:game-graphics-and-runtime",
      "title": "游戏图形与运行时",
      "url": "https://www.pystone.net/notes/game-graphics-and-runtime/",
      "atlas": "https://www.pystone.net/?node=game-graphics-and-runtime#knowledge-atlas",
      "label": "游戏图形与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "Unity中的“Unity与C#预处理指令”导航项",
      "citation": "https://www.pystone.net/notes/game-graphics-and-runtime/#unity"
    }
  ],
  "contentMarkdown": "# Unity与C#预处理指令\n\n> 创建时间：2020/5/20 18:31\n\n## Unity&C预处理指令\n## 预处理指令（条件编译）\n\n预处理器指令指导编译器在实际编译开始之前对信息进行预处理。\n所有的预处理器指令都是以 # 开始。且在一行上，只有空白字符可以出现在预处理器指令之前。预处理器指令不是语句，所以它们不以分号（;）结束。\nC# 编译器没有一个单独的预处理器，但是，指令被处理时就像是有一个单独的预处理器一样。在 C# 中，预处理器指令用于在条件编译中起作用。与 C 和 C++ 不同的是，它们不是用来创建宏。一个预处理器指令必须是该行上的唯一指令。\n\n```csharp\nclass Program\n{\n    static void Main(string[] args)\n    {\n        dynamic dyn = 1;\n        object obj = 1;\n        dyn = dyn + 3;\n        //obj = obj + 3; 报错\n\n        // Rest the mouse pointer over dyn and obj to see their\n        // types at compile time.\n        System.Console.WriteLine(dyn.GetType());\n        System.Console.WriteLine(obj.GetType());\n    }\n}\n\n```\n\n### Conditional特性\n\n可以把输出日志的函数使用Conditional特性来标记上，只有在Unity编辑器中开启了指定的宏命令，这个输出日志的函数才能被编译，即可很方便地开关日志。\n`[Conditional(\"EnableLog\")]`\n需要在Unity编辑器中添加上EnableLog宏命令，该方法才能被编译。\n\n## Unity自带的一些宏定义\n\nUNITY_EDITOR Unity编辑器\nUNITY_EDITOR_WIN Windows 操作系统.\nUNITY_EDITOR_OSX macos操作系统\nUNITY_STANDALONE_OSX 专门为macos（包括Universal, PPC，Intel architectures）平台的定义\nUNITY_STANDALONE_WIN 专门为windows平台的定义\nUNITY_STANDALONE_LINUX 专门为Linux平台的定义\nUNITY_STANDALONE 独立平台 (Mac OS X, Windows or Linux).\nUNITY_WII WII 游戏机平台\nUNITY_IOS iOS系统平台\nUNITY_IPHONE iPhone\nUNITY_ANDROID android系统平台\nUNITY_PS4 ps4平台\nUNITY_SAMSUNGTV 三星TV平台\nUNITY_XBOXONE Xbox One 平台\nUNITY_TIZEN Tizen 平台\nUNITY_TVOS Apple TV 平台\nUNITY_WSA #define directive for Universal Windows Platform. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend.\nUNITY_WSA_10_0 #define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.\nUNITY_WINRT UNITY_WSA.\nUNITY_WINRT_10_0 UNITY_WSA_10_0\nUNITY_WEBGL #define directive for WebGL.\nUNITY_FACEBOOK faceBook平台(WebGL or Windows standalone).\nUNITY_ADS 调用广告方法，版本 5.2 以后\nUNITY_ANALYTICS 调用unity分析服务，版本5.2以后\nUNITY_ASSERTIONS 控制指令的过程\n\nUNITY_5 unity5版本, 包含所有的5.x.y版本\nUNITY_5_0 Unity5.0版本,包含所有的5.0.x版本\nUNITY_5_0_1 Unity5.0.1版本\n\n## 自定义宏定义\n\nFile - Build Settings - Player Settings - Other Settings\n多个用分号隔开\n"
}
