PreprocessorDefine.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. };
  39. // only touch PlayerSettings if we actually modified it.
  40. // otherwise it shows up as changed in git each time.
  41. string newDefines = string.Join(";", defines);
  42. if (newDefines != currentDefines)
  43. {
  44. PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newDefines);
  45. }
  46. }
  47. }
  48. }