DefineSymbolsManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. /// <summary>
  4. /// Utility class that manages Define Symbols for a given set of build targets.
  5. /// </summary>
  6. public class DefineSymbolsManager {
  7. private Dictionary<BuildTargetGroup, DefineSymbols> defineSymbols = new Dictionary<BuildTargetGroup, DefineSymbols>();
  8. public DefineSymbolsManager(BuildTargetGroup[] groups)
  9. {
  10. foreach (var group in groups)
  11. {
  12. var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
  13. defineSymbols.Add(group, new DefineSymbols(symbols));
  14. }
  15. }
  16. public void UpdateFromBuildSettings()
  17. {
  18. var groups = defineSymbols.Keys;
  19. defineSymbols = new Dictionary<BuildTargetGroup, DefineSymbols>();
  20. foreach (var group in groups)
  21. {
  22. var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
  23. defineSymbols.Add(group, new DefineSymbols(symbols));
  24. }
  25. }
  26. public void ApplyToBuildSettings()
  27. {
  28. foreach (var e in defineSymbols)
  29. {
  30. PlayerSettings.SetScriptingDefineSymbolsForGroup(e.Key, e.Value.Get());
  31. }
  32. }
  33. public void Add(string symbol)
  34. {
  35. foreach (var item in defineSymbols)
  36. {
  37. item.Value.Add(symbol);
  38. }
  39. }
  40. public void Remove(string symbol)
  41. {
  42. foreach (var item in defineSymbols)
  43. {
  44. item.Value.Remove(symbol);
  45. }
  46. }
  47. public bool Has(string symbol)
  48. {
  49. var has = true;
  50. foreach (var item in defineSymbols)
  51. {
  52. has = has && item.Value.Has(symbol);
  53. }
  54. return has;
  55. }
  56. public override string ToString()
  57. {
  58. var str = "DefineSymbolsManager {\n";
  59. foreach (var item in defineSymbols)
  60. {
  61. str += item.Key + ": " + item.Value.Get() + "\n";
  62. }
  63. str += "}";
  64. return str;
  65. }
  66. }