// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Collections.Generic; using System.Linq; using UnityEditor; #if UNITY_2023_1_OR_NEWER using UnityEditor.Build; #endif namespace Microsoft.MixedReality.Toolkit.Utilities.Editor { /// /// A set of utilities to configure script compilation. /// public static class ScriptUtilities { /// /// Appends a set of symbolic constant definitions to Unity's Scripting Define Symbols for the /// specified build target group. /// /// The build target group for which the symbols are to be defined. /// Array of symbols to define. public static void AppendScriptingDefinitions( BuildTargetGroup targetGroup, params string[] symbols) { if (symbols == null || symbols.Length == 0) { return; } List toAdd = new List(symbols); #if UNITY_2023_1_OR_NEWER NamedBuildTarget target = NamedBuildTarget.FromBuildTargetGroup(targetGroup); List defines = new List(PlayerSettings.GetScriptingDefineSymbols(target).Split(';')); PlayerSettings.SetScriptingDefineSymbols(target, string.Join(";", defines.Union(toAdd).ToArray())); #else List defines = new List(PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup).Split(';')); PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", defines.Union(toAdd).ToArray())); #endif } /// /// Removes a set of symbolic constant definitions to Unity's Scripting Define Symbols from the /// specified build target group. /// /// The build target group for which the symbols are to be removed. /// Array of symbols to remove. public static void RemoveScriptingDefinitions( BuildTargetGroup targetGroup, params string[] symbols) { if (symbols == null || symbols.Length == 0) { return; } List toRemove = new List(symbols); #if UNITY_2023_1_OR_NEWER NamedBuildTarget target = NamedBuildTarget.FromBuildTargetGroup(targetGroup); List defines = new List(PlayerSettings.GetScriptingDefineSymbols(target).Split(';')); PlayerSettings.SetScriptingDefineSymbols(target, string.Join(";", defines.Except(toRemove).ToArray())); #else List defines = new List(PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup).Split(';')); PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", defines.Except(toRemove).ToArray())); #endif } } }