TriLibDefineSymbolsHelper.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEditor;
  2. namespace TriLibCore.Editor
  3. {
  4. public static class TriLibDefineSymbolsHelper
  5. {
  6. public static bool IsSymbolDefined(string targetDefineSymbol)
  7. {
  8. var defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  9. var defineSymbolsArray = defineSymbols.Split(';');
  10. for (var i = 0; i < defineSymbolsArray.Length; i++)
  11. {
  12. var defineSymbol = defineSymbolsArray[i];
  13. var trimmedDefineSymbol = defineSymbol.Trim();
  14. if (trimmedDefineSymbol == targetDefineSymbol)
  15. {
  16. return true;
  17. }
  18. }
  19. return false;
  20. }
  21. public static void UpdateSymbol(string targetDefineSymbol, bool value)
  22. {
  23. var defineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
  24. var defineSymbolsArray = defineSymbols.Split(';');
  25. var newDefineSymbols = string.Empty;
  26. var isDefined = false;
  27. for (var i = 0; i < defineSymbolsArray.Length; i++)
  28. {
  29. var defineSymbol = defineSymbolsArray[i];
  30. var trimmedDefineSymbol = defineSymbol.Trim();
  31. if (trimmedDefineSymbol == targetDefineSymbol)
  32. {
  33. if (!value)
  34. {
  35. continue;
  36. }
  37. isDefined = true;
  38. }
  39. newDefineSymbols += string.Format("{0};", trimmedDefineSymbol);
  40. }
  41. if (value && !isDefined)
  42. {
  43. newDefineSymbols += string.Format("{0};", targetDefineSymbol);
  44. }
  45. PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, newDefineSymbols);
  46. }
  47. }
  48. }