UnityInstallation.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. using System;
  6. using UnityEditor.Compilation;
  7. namespace Microsoft.Unity.VisualStudio.Editor
  8. {
  9. internal static class UnityInstallation
  10. {
  11. public static bool IsMainUnityEditorProcess
  12. {
  13. get
  14. {
  15. #if UNITY_2020_2_OR_NEWER
  16. if (UnityEditor.AssetDatabase.IsAssetImportWorkerProcess())
  17. return false;
  18. #elif UNITY_2019_3_OR_NEWER
  19. if (UnityEditor.Experimental.AssetDatabaseExperimental.IsAssetImportWorkerProcess())
  20. return false;
  21. #endif
  22. #if UNITY_2021_1_OR_NEWER
  23. if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Secondary)
  24. return false;
  25. #elif UNITY_2020_2_OR_NEWER
  26. if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Slave)
  27. return false;
  28. #elif UNITY_2020_1_OR_NEWER
  29. if (global::Unity.MPE.ProcessService.level == global::Unity.MPE.ProcessLevel.UMP_SLAVE)
  30. return false;
  31. #endif
  32. return true;
  33. }
  34. }
  35. public static Version LatestLanguageVersionSupported(Assembly assembly)
  36. {
  37. #if UNITY_2020_2_OR_NEWER
  38. if (assembly?.compilerOptions != null && Version.TryParse(assembly.compilerOptions.LanguageVersion, out var result))
  39. return result;
  40. // if parsing fails, we know at least we have support for 8.0
  41. return new Version(8, 0);
  42. #else
  43. return new Version(7, 3);
  44. #endif
  45. }
  46. }
  47. }