---
title: "Unity宏定义问题"
author: "石心.Yong"
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/uwa-answer-unity-conditional-compilation-symbols/
type: note
content_role: source
source_type: "source"
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/2021-05-07 - Unity宏定义问题.md"
content_hash: 934026024962e9cd5baebd2145896928d765dbc601f12b229b284391780a68f2
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# Unity宏定义问题

> **note · 我的 UWA 问答**
> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。

## 问题

执行代码添加宏定义

```
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTarget, names);
```

然后执行代码打印宏定义

```
string defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
```

```
Debuger.Log("宏定义：" + defineSymbols);
```

上面输出的宏定义是自己要的。

但是通过#if判断宏定义 获取的还是之前的

# if TapTap

```
channelType = ChannelType.TapTap;
```

# elif GooglePlay

```
channelType = ChannelType.GooglePlay;
```

# elif AppStore

```
channelType = ChannelType.AppStore;
```

# endif

我这些都是在Editor下操作的， 执行过AssetDatabase.Refresh();也没有作用

- 提问者：路人甲
- 提问时间：2021-05-07 20:31:10

## 我的回答

在Editor下Refresh不行，Reimport才行。并且Editor下的宏定义设置，与当前的activeBuildTarget一致。

- 回答时间：2021-05-07 21:45:28
- 最后更新：2021-09-26 23:48:55
- 采纳状态：未采纳

## 来源与关系

- 上位集合：[我的 UWA 问答](https://www.pystone.net/notes/my-uwa-answers/)
- UWA 标签：引擎技术
- 原始问题：[Unity宏定义问题](https://answer.uwa4d.com/question/6094c28e6bb31032f9791518)
- 源页最后更新：2021-05-08 18:18:47
