PreprocessorDefine.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. namespace Mirror
  4. {
  5. static class PreprocessorDefine
  6. {
  7. /// <summary>
  8. /// Add define symbols as soon as Unity gets done compiling.
  9. /// </summary>
  10. [InitializeOnLoadMethod]
  11. public static void AddDefineSymbols()
  12. {
  13. string currentDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  14. HashSet<string> defines = new HashSet<string>(currentDefines.Split(';'))
  15. {
  16. "MIRROR",
  17. "MIRROR_17_0_OR_NEWER",
  18. "MIRROR_18_0_OR_NEWER",
  19. "MIRROR_24_0_OR_NEWER",
  20. "MIRROR_26_0_OR_NEWER",
  21. "MIRROR_27_0_OR_NEWER",
  22. "MIRROR_28_0_OR_NEWER",
  23. "MIRROR_29_0_OR_NEWER",
  24. "MIRROR_30_0_OR_NEWER",
  25. "MIRROR_30_5_2_OR_NEWER",
  26. "MIRROR_32_1_2_OR_NEWER",
  27. "MIRROR_32_1_4_OR_NEWER",
  28. "MIRROR_35_0_OR_NEWER",
  29. "MIRROR_35_1_OR_NEWER",
  30. "MIRROR_37_0_OR_NEWER",
  31. "MIRROR_38_0_OR_NEWER",
  32. "MIRROR_39_0_OR_NEWER",
  33. "MIRROR_40_0_OR_NEWER",
  34. "MIRROR_41_0_OR_NEWER",
  35. "MIRROR_42_0_OR_NEWER",
  36. "MIRROR_43_0_OR_NEWER",
  37. "MIRROR_44_0_OR_NEWER",
  38. "MIRROR_46_0_OR_NEWER",
  39. "MIRROR_47_0_OR_NEWER"
  40. };
  41. // only touch PlayerSettings if we actually modified it.
  42. // otherwise it shows up as changed in git each time.
  43. string newDefines = string.Join(";", defines);
  44. if (newDefines != currentDefines)
  45. {
  46. PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newDefines);
  47. }
  48. }
  49. }
  50. }