DefineSymbolsUtility.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEditor;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace NRKernal.Release
  5. {
  6. static class DefineSymbolsUtility
  7. {
  8. public static bool HasSymbol(string symbol)
  9. {
  10. string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  11. return (!string.IsNullOrEmpty(definesString) && definesString.Contains(symbol));
  12. }
  13. public static void RemoveSymbol(string symbol)
  14. {
  15. string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  16. List<string> allDefines = definesString.Split(';').ToList();
  17. allDefines.Remove(symbol);
  18. PlayerSettings.SetScriptingDefineSymbolsForGroup(
  19. EditorUserBuildSettings.selectedBuildTargetGroup,
  20. string.Join(";", allDefines.ToArray()));
  21. }
  22. public static void AddSymbol(string symbol)
  23. {
  24. string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  25. List<string> allDefines = definesString.Split(';').ToList();
  26. List<string> Symbols = new List<string>() { symbol };
  27. allDefines.AddRange(Symbols.Except(allDefines));
  28. PlayerSettings.SetScriptingDefineSymbolsForGroup(
  29. EditorUserBuildSettings.selectedBuildTargetGroup,
  30. string.Join(";", allDefines.ToArray()));
  31. }
  32. }
  33. }