Files
Test/Library/PackageCache/com.unity.ide.visualstudio@b5edea5f33f4/Editor/UnityInstallation.cs
T
2026-11-01 23:39:55 +02:00

51 lines
1.5 KiB
C#

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using UnityEditor;
using UnityEditor.Compilation;
namespace Microsoft.Unity.VisualStudio.Editor
{
internal static class UnityInstallation
{
public static bool IsMainUnityEditorProcess
{
get
{
if (AssetDatabase.IsAssetImportWorkerProcess())
return false;
if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Secondary)
return false;
return true;
}
}
private static readonly Lazy<bool> _lazyIsInSafeMode = new Lazy<bool>(() =>
{
// internal static extern bool isInSafeMode { get {} }
var ieu = typeof(EditorUtility);
var pinfo = ieu.GetProperty("isInSafeMode", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (pinfo == null)
return false;
return Convert.ToBoolean(pinfo.GetValue(null));
});
public static bool IsInSafeMode => _lazyIsInSafeMode.Value;
public static Version LatestLanguageVersionSupported(Assembly assembly)
{
if (assembly?.compilerOptions != null && Version.TryParse(assembly.compilerOptions.LanguageVersion, out var result))
return result;
// if parsing fails, we know at least we have support for 8.0
return new Version(8, 0);
}
}
}