using System.Collections.Generic; using UnityEditor; namespace Axibug.Editor { /// /// 脚本宏定义。 /// public static class ScriptingDefineSymbols { private static readonly BuildTargetGroup[] BuildTargetGroups = new BuildTargetGroup[] { BuildTargetGroup.Standalone, BuildTargetGroup.iOS, BuildTargetGroup.Android, BuildTargetGroup.WSA, BuildTargetGroup.WebGL }; /// /// 检查指定平台是否存在指定的脚本宏定义。 /// /// 要检查脚本宏定义的平台。 /// 要检查的脚本宏定义。 /// 指定平台是否存在指定的脚本宏定义。 public static bool HasScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) { if (string.IsNullOrEmpty(scriptingDefineSymbol)) { return false; } string[] scriptingDefineSymbols = GetScriptingDefineSymbols(buildTargetGroup); foreach (string i in scriptingDefineSymbols) { if (i == scriptingDefineSymbol) { return true; } } return false; } /// /// 为指定平台增加指定的脚本宏定义。 /// /// 要增加脚本宏定义的平台。 /// 要增加的脚本宏定义。 public static void AddScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) { if (string.IsNullOrEmpty(scriptingDefineSymbol)) { return; } if (HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol)) { return; } List scriptingDefineSymbols = new List(GetScriptingDefineSymbols(buildTargetGroup)) { scriptingDefineSymbol }; SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray()); } /// /// 为指定平台移除指定的脚本宏定义。 /// /// 要移除脚本宏定义的平台。 /// 要移除的脚本宏定义。 public static void RemoveScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) { if (string.IsNullOrEmpty(scriptingDefineSymbol)) { return; } if (!HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol)) { return; } List scriptingDefineSymbols = new List(GetScriptingDefineSymbols(buildTargetGroup)); while (scriptingDefineSymbols.Contains(scriptingDefineSymbol)) { scriptingDefineSymbols.Remove(scriptingDefineSymbol); } SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray()); } /// /// 为所有平台增加指定的脚本宏定义。 /// /// 要增加的脚本宏定义。 public static void AddScriptingDefineSymbol(string scriptingDefineSymbol) { if (string.IsNullOrEmpty(scriptingDefineSymbol)) { return; } foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups) { AddScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol); } } /// /// 为所有平台移除指定的脚本宏定义。 /// /// 要移除的脚本宏定义。 public static void RemoveScriptingDefineSymbol(string scriptingDefineSymbol) { if (string.IsNullOrEmpty(scriptingDefineSymbol)) { return; } foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups) { RemoveScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol); } } /// /// 获取指定平台的脚本宏定义。 /// /// 要获取脚本宏定义的平台。 /// 平台的脚本宏定义。 public static string[] GetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup) { return PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';'); } /// /// 设置指定平台的脚本宏定义。 /// /// 要设置脚本宏定义的平台。 /// 要设置的脚本宏定义。 public static void SetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup, string[] scriptingDefineSymbols) { PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Join(";", scriptingDefineSymbols)); } } }