暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UnityInstallation.cs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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;
  7. using UnityEditor.Compilation;
  8. namespace Microsoft.Unity.VisualStudio.Editor
  9. {
  10. internal static class UnityInstallation
  11. {
  12. public static bool IsMainUnityEditorProcess
  13. {
  14. get
  15. {
  16. #if UNITY_2020_2_OR_NEWER
  17. if (UnityEditor.AssetDatabase.IsAssetImportWorkerProcess())
  18. return false;
  19. #elif UNITY_2019_3_OR_NEWER
  20. if (UnityEditor.Experimental.AssetDatabaseExperimental.IsAssetImportWorkerProcess())
  21. return false;
  22. #endif
  23. #if UNITY_2021_1_OR_NEWER
  24. if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Secondary)
  25. return false;
  26. #elif UNITY_2020_2_OR_NEWER
  27. if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Slave)
  28. return false;
  29. #elif UNITY_2020_1_OR_NEWER
  30. if (global::Unity.MPE.ProcessService.level == global::Unity.MPE.ProcessLevel.UMP_SLAVE)
  31. return false;
  32. #endif
  33. return true;
  34. }
  35. }
  36. private static readonly Lazy<bool> _lazyIsInSafeMode = new Lazy<bool>(() =>
  37. {
  38. // internal static extern bool isInSafeMode { get {} }
  39. var ieu = typeof(EditorUtility);
  40. var pinfo = ieu.GetProperty("isInSafeMode", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
  41. if (pinfo == null)
  42. return false;
  43. return Convert.ToBoolean(pinfo.GetValue(null));
  44. });
  45. public static bool IsInSafeMode => _lazyIsInSafeMode.Value;
  46. public static Version LatestLanguageVersionSupported(Assembly assembly)
  47. {
  48. #if UNITY_2020_2_OR_NEWER
  49. if (assembly?.compilerOptions != null && Version.TryParse(assembly.compilerOptions.LanguageVersion, out var result))
  50. return result;
  51. // if parsing fails, we know at least we have support for 8.0
  52. return new Version(8, 0);
  53. #else
  54. return new Version(7, 3);
  55. #endif
  56. }
  57. }
  58. }