Unity 代码改宏定义

两个函数

PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); //所有宏定义 ; 分割
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, sz); //写入全部宏,相当于改配置

使用笔记

需要考虑一组宏定义的互斥问题,要保持不改动的宏不变,示例代码如下
public static void SetDebugerLevle(string logType)
{
    BuildTargetGroup targetGroup = BuildTargetGroup.Android;
    string ori = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
    string debugType = "Debuger_" + logType;

    List<string> defineSymbols = new List<string>(ori.Split(';'));
    for (int i = 0; i < defineSymbols.Count; ++i)
    {
        if (defineSymbols[i] == debugType)
        {
            Debug.LogFormat("========== debuglog {0}", logType);
            return;
        }

        if (defineSymbols[i].StartsWith("Debuger_"))
        {
            defineSymbols[i] = debugType;
            debugType = null;
            break;
        }
    }

    if (debugType != null)
    {
        defineSymbols.Add(debugType);
    }

    PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", defineSymbols.ToArray()));
    Debug.LogFormat("========== debuglog {0}", logType);
}
posted @ 2017-10-27 17:39  Hichy  阅读(2818)  评论(0编辑  收藏  举报