Skip to content

Commit

Permalink
fix: in 2020.2 or later, no need to recompile
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Dec 21, 2020
1 parent cc648de commit f815cf2
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions Plugins/CSharpCompilerSettings/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ internal static class Core
{
private static bool IsGlobal { get; }

public static void DirtyScriptsIfNeeded()
{
var assemblyName = GetAssemblyName(FindAsmdef());
if (!IsGlobal && string.IsNullOrEmpty(assemblyName)) return;

var filepath = "Temp/" + typeof(Core).Assembly.GetName().Name + ".loaded";
if (File.Exists(filepath)) return;
File.WriteAllText(filepath, "");

Utils.RequestCompilation(IsGlobal ? null : assemblyName);
}

public static string GetAssemblyName(string asmdefPath)
{
if (string.IsNullOrEmpty(asmdefPath)) return null;
Expand Down Expand Up @@ -268,6 +256,7 @@ public static void OnAssemblyCompilationStarted(string name)

static Core()
{
// For development assemblies: Do nothing.
var coreAssemblyName = typeof(Core).Assembly.GetName().Name;
if (coreAssemblyName == "CSharpCompilerSettings_") return;

Expand Down Expand Up @@ -315,21 +304,15 @@ static Core()
CompilationPipeline.assemblyCompilationStarted -= OnAssemblyCompilationStarted;
CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted;

// Install custom csc before compilation.
// Install custom compiler package before compilation.
var settings = GetSettings();
if (!settings.UseDefaultCompiler)
CompilerInfo.GetInstalledInfo(settings.CompilerPackage.PackageId);

// Install analyzer packages before compilation.
if (IsGlobal)
foreach (var package in settings.AnalyzerPackages.Where(x => x.IsValid))
AnalyzerInfo.GetInstalledInfo(package.PackageId);

// If Unity 2020.2 or newer, request re-compilation.
var version = Application.unityVersion.Split('.');
var major = int.Parse(version[0]);
var minor = int.Parse(version[1]);
if (2021 <= major || (major == 2020 && 2 <= minor))
DirtyScriptsIfNeeded();
}
}
}

0 comments on commit f815cf2

Please sign in to comment.